# 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
        del outer_loops[0]
        lengths.append(loop_len(nterminal_loop))

    # if the C-terminal loop sticks outside
    if outer_loops:
        if outer_loops[-1][-1] == sequence_length:
            cterminal_loop = outer_loops[-1]
            del outer_loops[-1]
            lengths.append(loop_len(cterminal_loop))

    # test remaining outer loops for length
    for loop in outer_loops:
        lengths.append(loop_len(loop) / 2)

    return max(lengths)


def post_process_protein(params, protein):
    """
    This is the main analysis of the protein, where theprotein
    dictionary should contain all the necessary information
    from the annotations. Thus post_process_protein contain
    can determine the final analysis.
    """

    def sequence_length(protein):
        return protein['sequence_length']

    def has_tm_helix(protein):
        for program in params['helix_programs']:

# 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

        del outer_loops[0]
        lengths.append(loop_len(nterminal_loop))

    # if the C-terminal loop sticks outside
    if outer_loops:
        if outer_loops[-1][-1] == sequence_length:
            cterminal_loop = outer_loops[-1]
            del outer_loops[-1]
            lengths.append(loop_len(cterminal_loop))

    # test remaining outer loops for length
    for loop in outer_loops:
        lengths.append(loop_len(loop) / 2)

    return max(lengths)


def post_process_protein(params, protein):
    """
    This is the main analysis of the protein, where theprotein
    dictionary should contain all the necessary information
    from the annotations. Thus post_process_protein contain
    can determine the final analysis.
    """

    def sequence_length(protein):
        return protein['sequence_length']

    def has_tm_helix(protein):
        for program in params['helix_programs']:

            if dict_get(protein, '%s_helices' % program):