utils/infernal_utils.py
def infernal_output_parser(inf_output_file, ss_notation="wuss"):
    """
    Parses Infernal's detailed output file (-o) and returns a list of dictionaries
    for each hit found in the file

    inf_output_file: Infernal's output file (-o)
    dest_dir: The path to the output directory
    ss_notation: A string indicating the the notation in which to output the
    secondary structure string (wuss or dbn)

    return: A list of dictionaries
    """

    rna_type = ''
    ss_str_list = []

    scores = []

    fp_in = open(inf_output_file, 'r')

    line = fp_in.readline()
    rfam_acc = ''
    while line != '':

        # look for a new hit section and fetch rfam_acc
        if line.find("Accession:") != -1:
            rfam_acc = [x for x in line.strip().split(' ') if x != ''][1]

        # new hit
        if line[0:2] == ">>":
            line = line.strip()
            # get sequence accession
            seq_id = line[3:].strip()

            # get hit region
            index = 0
            while index < 3:
                line = fp_in.readline().strip()
                index += 1

            # bed file fields
            score_line = [x for x in line.strip().split(' ') if x != '']
            start = score_line[START]
            end = score_line[END]
            strand = score_line[11]
            e_value = score_line[2]
            bit_score = score_line[3]
            cm_start = score_line[6]
            cm_end = score_line[7]
            raw_trunc = score_line[14]
            truncated = ''

            if raw_trunc == 'no' or raw_trunc == '-':
                truncated = '0'
            elif raw_trunc.find('&') != -1:
                truncated = raw_trunc.replace('&', '').replace('\'', '')
            else:
                truncated = raw_trunc.replace('\'', '')

            rfamseq_acc = seq_id.split(' ')[0].split('|')[-1]

            # get secondary structure
            line = fp_in.readline()

            while line[0:2] != '>>' and line[0] != '#':

                if line.find("CS") != -1:
                    line = line.strip()
                    ss_line = [x for x in line.split(' ') if x != '' and x != 'CS']
                    ss_line = ss_line[0]
                    ss_str_list.append(ss_line)

                    if rna_type == '':  # 1st time we hit this
                        line = fp_in.readline().strip()  # read next line
                        rna_type = line.split(' ')[0].strip()

                line = fp_in.readline()  # read the rest

            sec_struct = ''.join(ss_str_list)

            if ss_notation.lower() == "dbn":
                sec_struct = convert_short_wuss_to_dbn(sec_struct)

            score_dict = {"rfam_acc": rfam_acc, "rfamseq_acc": rfamseq_acc, "start": start,
                          "end": end, "bit_score": bit_score, "e_value": e_value,
                          "strand": strand, "sec_struct": sec_struct, "rna_type": rna_type,
                          "truncated": truncated, "cm_start": cm_start, "cm_end": cm_end,
                          }

            scores.append(score_dict)

            ss_str_list = []
            rna_type = ''

        else:
            line = fp_in.readline()

    fp_in.close()

    return scores

    Parses Infernal's detailed output file (-o) and returns a list of dictionaries
    for each hit found in the file

    inf_output_file: Infernal's output file (-o)
    dest_dir: The path to the output directory
    ss_notation: A string indicating the the notation in which to output the
    secondary structure string (wuss or dbn)

    return: A list of dictionaries
    
Parses Infernal's detailed output file (-o) and returns a list of dictionaries
for each hit found in the file

Infernal's output file (-o)
dest_dir: The path to the output directory
ss_notation: A string indicating the the notation in which to output the
secondary structure string (wuss or dbn)

A list of dictionaries
Parses Infernal ' s detailed output file ( - o ) and returns a list of dictionaries for each hit found in the file Infernal ' s output file ( - o ) dest_dir : The path to the output directory ss_notation : A string indicating the the notation in which to output the secondary structure string ( wuss or dbn ) A list of dictionaries
def infernal_output_parser(inf_output_file, ss_notation="wuss"):
    rna_type = ''
    ss_str_list = []
    scores = []
    fp_in = open(inf_output_file, 'r')
    line = fp_in.readline()
    rfam_acc = ''
    while line != '':
        if line.find("Accession:") != -1:
            rfam_acc = [x for x in line.strip().split(' ') if x != ''][1]
        if line[0:2] == ">>":
            line = line.strip()
            seq_id = line[3:].strip()
            index = 0
            while index < 3:
                line = fp_in.readline().strip()
                index += 1
            score_line = [x for x in line.strip().split(' ') if x != '']
            start = score_line[START]
            end = score_line[END]
            strand = score_line[11]
            e_value = score_line[2]
            bit_score = score_line[3]
            cm_start = score_line[6]
            cm_end = score_line[7]
            raw_trunc = score_line[14]
            truncated = ''
            if raw_trunc == 'no' or raw_trunc == '-':
                truncated = '0'
            elif raw_trunc.find('&') != -1:
                truncated = raw_trunc.replace('&', '').replace('\'', '')
            else:
                truncated = raw_trunc.replace('\'', '')
            rfamseq_acc = seq_id.split(' ')[0].split('|')[-1]
            line = fp_in.readline()
            while line[0:2] != '>>' and line[0] != '#':
                if line.find("CS") != -1:
                    line = line.strip()
                    ss_line = [x for x in line.split(' ') if x != '' and x != 'CS']
                    ss_line = ss_line[0]
                    ss_str_list.append(ss_line)
                    if rna_type == '':  
                        line = fp_in.readline().strip()  
                        rna_type = line.split(' ')[0].strip()
                line = fp_in.readline()  
            sec_struct = ''.join(ss_str_list)
            if ss_notation.lower() == "dbn":
                sec_struct = convert_short_wuss_to_dbn(sec_struct)
            score_dict = {"rfam_acc": rfam_acc, "rfamseq_acc": rfamseq_acc, "start": start,
                          "end": end, "bit_score": bit_score, "e_value": e_value,
                          "strand": strand, "sec_struct": sec_struct, "rna_type": rna_type,
                          "truncated": truncated, "cm_start": cm_start, "cm_end": cm_end,
                          }
            scores.append(score_dict)
            ss_str_list = []
            rna_type = ''
        else:
            line = fp_in.readline()
    fp_in.close()
    return scores
def infernal_output_parser ( inf_output_file , ss_notation = "wuss" ) : rna_type = '' ss_str_list = [ ] scores = [ ] fp_in = open ( inf_output_file , 'r' ) line = fp_in . readline ( ) rfam_acc = '' while line != '' : if line . find ( "Accession:" ) != - 1 : rfam_acc = [ x for x in line . strip ( ) . split ( ' ' ) if x != '' ] [ 1 ] if line [ 0 : 2 ] == ">>" : line = line . strip ( ) seq_id = line [ 3 : ] . strip ( ) index = 0 while index < 3 : line = fp_in . readline ( ) . strip ( ) index += 1 score_line = [ x for x in line . strip ( ) . split ( ' ' ) if x != '' ] start = score_line [ START ] end = score_line [ END ] strand = score_line [ 11 ] e_value = score_line [ 2 ] bit_score = score_line [ 3 ] cm_start = score_line [ 6 ] cm_end = score_line [ 7 ] raw_trunc = score_line [ 14 ] truncated = '' if raw_trunc == 'no' or raw_trunc == '-' : truncated = '0' elif raw_trunc . find ( '&' ) != - 1 : truncated = raw_trunc . replace ( '&' , '' ) . replace ( '\'' , '' ) else : truncated = raw_trunc . replace ( '\'' , '' ) rfamseq_acc = seq_id . split ( ' ' ) [ 0 ] . split ( '|' ) [ - 1 ] line = fp_in . readline ( ) while line [ 0 : 2 ] != '>>' and line [ 0 ] != '#' : if line . find ( "CS" ) != - 1 : line = line . strip ( ) ss_line = [ x for x in line . split ( ' ' ) if x != '' and x != 'CS' ] ss_line = ss_line [ 0 ] ss_str_list . append ( ss_line ) if rna_type == '' : line = fp_in . readline ( ) . strip ( ) rna_type = line . split ( ' ' ) [ 0 ] . strip ( ) line = fp_in . readline ( ) sec_struct = '' . join ( ss_str_list ) if ss_notation . lower ( ) == "dbn" : sec_struct = convert_short_wuss_to_dbn ( sec_struct ) score_dict = { "rfam_acc" : rfam_acc , "rfamseq_acc" : rfamseq_acc , "start" : start , "end" : end , "bit_score" : bit_score , "e_value" : e_value , "strand" : strand , "sec_struct" : sec_struct , "rna_type" : rna_type , "truncated" : truncated , "cm_start" : cm_start , "cm_end" : cm_end , } scores . append ( score_dict ) ss_str_list = [ ] rna_type = '' else : line = fp_in . readline ( ) fp_in . close ( ) return scores
Parses Infernal's detailed output file (-o) and returns a list of dictionaries
for each hit found in the file
Parses Infernal ' s detailed output file ( - o ) and returns a list of dictionaries for each hit found in the file
"""
    Parses Infernal's detailed output file (-o) and returns a list of dictionaries
    for each hit found in the file

    inf_output_file: Infernal's output file (-o)
    dest_dir: The path to the output directory
    ss_notation: A string indicating the the notation in which to output the
    secondary structure string (wuss or dbn)

    return: A list of dictionaries
    """ # look for a new hit section and fetch rfam_acc # new hit # get sequence accession # get hit region # bed file fields # get secondary structure # 1st time we hit this # read next line # read the rest
inf_output_file
ss_notation