# 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


def get_annotations(params):
    """
    Creates a list of annotation functions required
    by this gram_pos protocol. The main program
    will run the annotation functions of this list,
    mapping the correct functions to the strings.

    As well, the function does some bookeeping on
    params to make sure the 'hmm_profiles_dir' is
    pointing in the right place.
    """
    annotations = []

    params['signalp4_organism'] = 'gram+'

    if not params['signalp4_bin'] or params[
        'signalp4_bin'] == 'signalp_scrape_web':
        annotations += ['signalp_scrape_web']
    else:
        annotations += ['signalp4']

    if not params['lipop1_bin'] or params['lipop1_bin'] == 'lipop_scrape_web':
        annotations += ['lipop_scrape_web']
    else:
        annotations += ['lipop1']

    annotations += ['hmmsearch3']


# 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



def get_annotations(params):
    """
    Creates a list of annotation functions required
    by this gram_pos protocol. The main program
    will run the annotation functions of this list,
    mapping the correct functions to the strings.

    As well, the function does some bookeeping on
    params to make sure the 'hmm_profiles_dir' is
    pointing in the right place.
    """
    annotations = []

    params['signalp4_organism'] = 'gram+'

    if not params['signalp4_bin'] or params[
        'signalp4_bin'] == 'signalp_scrape_web':
        annotations += ['signalp_scrape_web']
    else:
        annotations += ['signalp4']

    if not params['lipop1_bin'] or params['lipop1_bin'] == 'lipop_scrape_web':
        annotations += ['lipop_scrape_web']
    else:
        annotations += ['lipop1']

    annotations += ['hmmsearch3']


    if dict_get(params, 'helix_programs'):