utils/infernal_utils.py
def tblout_to_full_region(tblout_file, dest_dir=None):
    """
    Parses Infernal's tblout file and generates a .txt file that is compatible with full_region
    table.

    tblout_file: A valid Infernal's output file in .tblout format
    dest_dir: The path to the output directory

    return: True if successful, False otherwise
    """

    tblout_fp = open(tblout_file, 'r')
    filename = os.path.split(tblout_file)[1].partition('.')[0]

    if dest_dir is None:
        dest_dir = os.path.split(tblout_file)[0]
        #filename = os.path.split(tblout_file)[1].partition('.')[0]

    full_region_fp = open(os.path.join(dest_dir, filename+'.txt'), 'w')

    # set to 1 on update and correct with clan competition
    is_significant = 1

    # set all to full until we update seed sequences
    seq_type = "full"

    line = tblout_fp.readline().strip()

    while line != '':
        # skip comment lines
        if str(line[0]) != '#':
            line = line.split(' ')
            line_cont = [x for x in line if x != '']
            if len(line_cont) > 1:
                seq_acc = ''
                if line[0].find('|') != -1:
                        seq_acc = line_cont[0].split('|')  # could also be position 0 for cmsearch
                        seq_acc = seq_acc[-1]  # get last field
                else:
                        seq_acc = line[0].strip()

                rfam_acc = line_cont[3]  # 1 or 3 for cmscan
                cm_start = line_cont[5]
                cm_end = line_cont[6]
                seq_start = line_cont[7]
                seq_end = line_cont[8]

                trunc = line_cont[10].replace('\'', '')
                if trunc == "no" or trunc == '-':
                        trunc = str(0)

                elif trunc.find('&') != -1:
                        trunc = trunc.replace('&', '')

                bit_score = line_cont[14]
                evalue = line_cont[15]

                full_region_fp.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (rfam_acc,
                                                                                   seq_acc,
                                                                                   seq_start,
                                                                                   seq_end,
                                                                                   bit_score,
                                                                                   evalue,
                                                                                   cm_start,
                                                                                   cm_end,
                                                                                   trunc,
                                                                                   seq_type,
                                                                                   str(is_significant)))
            line = tblout_fp.readline().strip()

        else:
            line = tblout_fp.readline().strip()

    tblout_fp.close()
    full_region_fp.close()

    Parses Infernal's tblout file and generates a .txt file that is compatible with full_region
    table.

    tblout_file: A valid Infernal's output file in .tblout format
    dest_dir: The path to the output directory

    return: True if successful, False otherwise
    
Parses Infernal's tblout file and generates a .txt file that is compatible with full_region
table.

A valid Infernal's output file in .tblout format
dest_dir: The path to the output directory

True if successful, False otherwise
Parses Infernal ' s tblout file and generates a . txt file that is compatible with full_region table . A valid Infernal ' s output file in . tblout format dest_dir : The path to the output directory True if successful False otherwise
def tblout_to_full_region(tblout_file, dest_dir=None):
    tblout_fp = open(tblout_file, 'r')
    filename = os.path.split(tblout_file)[1].partition('.')[0]
    if dest_dir is None:
        dest_dir = os.path.split(tblout_file)[0]
    full_region_fp = open(os.path.join(dest_dir, filename+'.txt'), 'w')
    is_significant = 1
    seq_type = "full"
    line = tblout_fp.readline().strip()
    while line != '':
        if str(line[0]) != '#':
            line = line.split(' ')
            line_cont = [x for x in line if x != '']
            if len(line_cont) > 1:
                seq_acc = ''
                if line[0].find('|') != -1:
                        seq_acc = line_cont[0].split('|')  
                        seq_acc = seq_acc[-1]  
                else:
                        seq_acc = line[0].strip()
                rfam_acc = line_cont[3]  
                cm_start = line_cont[5]
                cm_end = line_cont[6]
                seq_start = line_cont[7]
                seq_end = line_cont[8]
                trunc = line_cont[10].replace('\'', '')
                if trunc == "no" or trunc == '-':
                        trunc = str(0)
                elif trunc.find('&') != -1:
                        trunc = trunc.replace('&', '')
                bit_score = line_cont[14]
                evalue = line_cont[15]
                full_region_fp.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (rfam_acc,
                                                                                   seq_acc,
                                                                                   seq_start,
                                                                                   seq_end,
                                                                                   bit_score,
                                                                                   evalue,
                                                                                   cm_start,
                                                                                   cm_end,
                                                                                   trunc,
                                                                                   seq_type,
                                                                                   str(is_significant)))
            line = tblout_fp.readline().strip()
        else:
            line = tblout_fp.readline().strip()
    tblout_fp.close()
    full_region_fp.close()
def tblout_to_full_region ( tblout_file , dest_dir = None ) : tblout_fp = open ( tblout_file , 'r' ) filename = os . path . split ( tblout_file ) [ 1 ] . partition ( '.' ) [ 0 ] if dest_dir is None : dest_dir = os . path . split ( tblout_file ) [ 0 ] full_region_fp = open ( os . path . join ( dest_dir , filename + '.txt' ) , 'w' ) is_significant = 1 seq_type = "full" line = tblout_fp . readline ( ) . strip ( ) while line != '' : if str ( line [ 0 ] ) != '#' : line = line . split ( ' ' ) line_cont = [ x for x in line if x != '' ] if len ( line_cont ) > 1 : seq_acc = '' if line [ 0 ] . find ( '|' ) != - 1 : seq_acc = line_cont [ 0 ] . split ( '|' ) seq_acc = seq_acc [ - 1 ] else : seq_acc = line [ 0 ] . strip ( ) rfam_acc = line_cont [ 3 ] cm_start = line_cont [ 5 ] cm_end = line_cont [ 6 ] seq_start = line_cont [ 7 ] seq_end = line_cont [ 8 ] trunc = line_cont [ 10 ] . replace ( '\'' , '' ) if trunc == "no" or trunc == '-' : trunc = str ( 0 ) elif trunc . find ( '&' ) != - 1 : trunc = trunc . replace ( '&' , '' ) bit_score = line_cont [ 14 ] evalue = line_cont [ 15 ] full_region_fp . write ( "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( rfam_acc , seq_acc , seq_start , seq_end , bit_score , evalue , cm_start , cm_end , trunc , seq_type , str ( is_significant ) ) ) line = tblout_fp . readline ( ) . strip ( ) else : line = tblout_fp . readline ( ) . strip ( ) tblout_fp . close ( ) full_region_fp . close ( )
Parses Infernal's tblout file and generates a .txt file that is compatible with full_region
table.
Parses Infernal ' s tblout file and generates a . txt file that is compatible with full_region table .
"""
    Parses Infernal's tblout file and generates a .txt file that is compatible with full_region
    table.

    tblout_file: A valid Infernal's output file in .tblout format
    dest_dir: The path to the output directory

    return: True if successful, False otherwise
    """ #filename = os.path.split(tblout_file)[1].partition('.')[0] # set to 1 on update and correct with clan competition # set all to full until we update seed sequences # skip comment lines # could also be position 0 for cmsearch # get last field # 1 or 3 for cmscan
tblout_file
dest_dir