# 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]
# 
# def log_stderr(s, width=76, comment=True):
#     """
#     Wrapper for all stderr out. Allows future customization.
#     """
#     if LOG_SILENT:
#         return
#     if s and s[-1] != "\n":
#         s += "\n"
#     if not s.startswith("#"):
#         s = "# " + s
#     sys.stderr.write(s)


import os
from inmembrane.helpers import dict_get, chop_nterminal_peptide, log_stderr

    if has_barrel:
        category = 'OM(barrel)'

    # we only regard the barrel prediction as a true positive
    # if a signal peptide is also present
    #  is_barrel = False
    #  if has_signal_pept and has_barrel: # TODO and num_tms <= 1:
    #    category = 'OM(barrel)'
    #    is_barrel = True

    # set number of predicted OM barrel strands in details
    if has_barrel and \
            dict_get(protein, 'tmbeta_strands'):
        num_strands = len(protein['tmbeta_strands'])
        details += ['tmbeta_strands(%i)' % (num_strands)]

    if has_signal_pept and not is_lipop and \
            (dict_get(protein, 'signalp_cleave_position')):
        # we use the SignalP signal peptidase cleavage site for Tat signals
        chop_nterminal_peptide(protein, protein['signalp_cleave_position'])

    if is_tatfind:
        details += ["tatfind"]

    if is_signalp:
        details += ["signalp"]

    if is_lipop:
        details += ["lipop"]

# 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]
# 
# def log_stderr(s, width=76, comment=True):
#     """
#     Wrapper for all stderr out. Allows future customization.
#     """
#     if LOG_SILENT:
#         return
#     if s and s[-1] != "\n":
#         s += "\n"
#     if not s.startswith("#"):
#         s = "# " + s
#     sys.stderr.write(s)


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


    if has_barrel:
        category = 'OM(barrel)'

    # we only regard the barrel prediction as a true positive
    # if a signal peptide is also present
    #  is_barrel = False
    #  if has_signal_pept and has_barrel: # TODO and num_tms <= 1:
    #    category = 'OM(barrel)'
    #    is_barrel = True

    # set number of predicted OM barrel strands in details
    if has_barrel and \
            dict_get(protein, 'tmbeta_strands'):
        num_strands = len(protein['tmbeta_strands'])
        details += ['tmbeta_strands(%i)' % (num_strands)]

    if has_signal_pept and not is_lipop and \
            (dict_get(protein, 'signalp_cleave_position')):
        # we use the SignalP signal peptidase cleavage site for Tat signals
        chop_nterminal_peptide(protein, protein['signalp_cleave_position'])

    if is_tatfind:
        details += ["tatfind"]

    if is_signalp:
        details += ["signalp"]

    if is_lipop:
        details += ["lipop"]

        chop_nterminal_peptide(protein, protein['lipop_cleave_position'])