# Path: inmembrane/helpers.py
# def dict_get(this_dict, prop):
#     """
#     Useful helper function to get values from dicts. Takes in
#     the possibility that the key may not exist, and in that
#     case returns False. Makes it easier to write code to avoid
#     handling the case of missing keys.
#     """
#     if prop not in this_dict:
#         return False
#     return this_dict[prop]
# 
# def chop_nterminal_peptide(protein, i_cut):
#     """
#     Finds all transmembrane fields in protein ("*_loops" and "*_helices")
#     and deletes an N-terminal section of the protein indicated by i_cut.
# 
#     Assuming the topology of inner and outer loops remain the same, this
#     may delete a certain number of elements at the N-terminus. Allows a
#     simple way of removing lipo-protein and secretion-protein signals from
#     the evaluation of the outer_loops of the protein.
#     """
#     protein['sequence_length'] -= i_cut
#     for prop in protein:
#         if '_loops' in prop or '_helices' in prop:
#             sses = protein[prop]
#             for i in range(len(sses)):
#                 j, k = sses[i]
#                 sses[i] = (j - i_cut, k - i_cut)
#     for prop in protein:
#         if '_loops' in prop or '_helices' in prop:
#             sses = protein[prop]
#             for i in reversed(range(len(sses))):
#                 j, k = sses[i]
#                 # tests if this loop or TM-helix has been cut out
#                 if j <= 0 and k <= 0:
#                     del sses[i]
#                 # otherewise, neg value means loop or TM-helix is at the new N-terminal
#                 elif j <= 0 and k > 0:
#                     sses[i] = (1, k)
#                     # if a TM-helix gets cut in half and becomes a new N-terminal,
#                     # convert the remaining residues to a loop and remove the helix
#                     if '_helices' in prop:
#                         program = prop.split('_')[0]
#                         for x in protein:
#                             if x == '%s_loops' % program:
#                                 new_N_loop = protein[x][0]
#                                 new_N_loop[0] = 1
#                         del sses[i]


import os
from inmembrane.helpers import dict_get, chop_nterminal_peptide
            return max(extents)
        else:
            return 0

    terminal_exposed_loop_min = \
        params['terminal_exposed_loop_min']

    is_hmm_profile_match = dict_get(protein, 'hmmsearch')
    is_lipop = dict_get(protein, 'is_lipop')
    if is_lipop:
        i_lipop_cut = protein['lipop_cleave_position']
    is_signalp = dict_get(protein, 'is_signalp')
    if is_signalp:
        i_signalp_cut = protein['signalp_cleave_position']

    details = []
    if is_hmm_profile_match:
        details += ["hmm(%s)" % "|".join(protein['hmmsearch'])]
    if is_lipop:
        details += ["lipop"]
    if is_signalp:
        details += ["signalp"]
    for program in params['helix_programs']:
        if has_tm_helix(protein):
            n = len(protein['%s_helices' % program])
            details += [program + "(%d)" % n]

    if is_lipop:
        chop_nterminal_peptide(protein, i_lipop_cut)
    elif is_signalp:

# Path: inmembrane/helpers.py
# def dict_get(this_dict, prop):
#     """
#     Useful helper function to get values from dicts. Takes in
#     the possibility that the key may not exist, and in that
#     case returns False. Makes it easier to write code to avoid
#     handling the case of missing keys.
#     """
#     if prop not in this_dict:
#         return False
#     return this_dict[prop]
# 
# def chop_nterminal_peptide(protein, i_cut):
#     """
#     Finds all transmembrane fields in protein ("*_loops" and "*_helices")
#     and deletes an N-terminal section of the protein indicated by i_cut.
# 
#     Assuming the topology of inner and outer loops remain the same, this
#     may delete a certain number of elements at the N-terminus. Allows a
#     simple way of removing lipo-protein and secretion-protein signals from
#     the evaluation of the outer_loops of the protein.
#     """
#     protein['sequence_length'] -= i_cut
#     for prop in protein:
#         if '_loops' in prop or '_helices' in prop:
#             sses = protein[prop]
#             for i in range(len(sses)):
#                 j, k = sses[i]
#                 sses[i] = (j - i_cut, k - i_cut)
#     for prop in protein:
#         if '_loops' in prop or '_helices' in prop:
#             sses = protein[prop]
#             for i in reversed(range(len(sses))):
#                 j, k = sses[i]
#                 # tests if this loop or TM-helix has been cut out
#                 if j <= 0 and k <= 0:
#                     del sses[i]
#                 # otherewise, neg value means loop or TM-helix is at the new N-terminal
#                 elif j <= 0 and k > 0:
#                     sses[i] = (1, k)
#                     # if a TM-helix gets cut in half and becomes a new N-terminal,
#                     # convert the remaining residues to a loop and remove the helix
#                     if '_helices' in prop:
#                         program = prop.split('_')[0]
#                         for x in protein:
#                             if x == '%s_loops' % program:
#                                 new_N_loop = protein[x][0]
#                                 new_N_loop[0] = 1
#                         del sses[i]


# Path: inmembrane/protocols/gram_pos.py
import os
from inmembrane.helpers import dict_get, chop_nterminal_peptide

            return max(extents)
        else:
            return 0

    terminal_exposed_loop_min = \
        params['terminal_exposed_loop_min']

    is_hmm_profile_match = dict_get(protein, 'hmmsearch')
    is_lipop = dict_get(protein, 'is_lipop')
    if is_lipop:
        i_lipop_cut = protein['lipop_cleave_position']
    is_signalp = dict_get(protein, 'is_signalp')
    if is_signalp:
        i_signalp_cut = protein['signalp_cleave_position']

    details = []
    if is_hmm_profile_match:
        details += ["hmm(%s)" % "|".join(protein['hmmsearch'])]
    if is_lipop:
        details += ["lipop"]
    if is_signalp:
        details += ["signalp"]
    for program in params['helix_programs']:
        if has_tm_helix(protein):
            n = len(protein['%s_helices' % program])
            details += [program + "(%d)" % n]

    if is_lipop:
        chop_nterminal_peptide(protein, i_lipop_cut)
    elif is_signalp:

        chop_nterminal_peptide(protein, i_signalp_cut)