utils/infernal_utils.py
def infernal_to_rfam(inf_tblout_file, dest_dir, file_format='tsv'):
    """
    Parses Infernal's output file and exports results in Rfam's genome full region format
    (tsv option is used by default)

    inf_tblout_file: Infernal's output file in tabular format
    format: This is an option whether to output results in  tabular format or create a json file
    """

    in_file = open(inf_tblout_file, 'r')
    filename = os.path.basename(inf_tblout_file).partition('.')[0]

    out_file = None
    if file_format == "tsv":
        out_file = open(os.path.join(dest_dir, filename + ".tsv"), 'w')
    else:
        out_file = open(os.path.join(dest_dir, filename + ".json"), 'w')

    upid = filename
    is_significant = 1  # always the same before clan competition
    #seq_type = "null"
    seq_type = "full" # set all to full until we update seed sequences

    line = in_file.readline().strip()

    while line != '':
        if line[0] != '#':
            line = line.split(' ')
            line_cont = [x for x in line if x != '']

            genseq_acc = line_cont[2].split('|') # could also be position 0 for cmsearch
            genseq_acc = genseq_acc[len(genseq_acc) - 1]  # get last field
            rfam_acc = line_cont[1] # 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]

            out_file.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (rfam_acc, genseq_acc,
                                                                                 upid, seq_start,
                                                                                 seq_end, bit_score,
                                                                                 evalue, cm_start,
                                                                                 cm_end, trunc,
                                                                                 seq_type, is_significant))
            line = in_file.readline().strip()

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

    in_file.close()
    out_file.close()

    Parses Infernal's output file and exports results in Rfam's genome full region format
    (tsv option is used by default)

    inf_tblout_file: Infernal's output file in tabular format
    format: This is an option whether to output results in  tabular format or create a json file
    
Parses Infernal's output file and exports results in Rfam's genome full region format
(tsv option is used by default)

Infernal's output file in tabular format
format: This is an option whether to output results in  tabular format or create a json file
Parses Infernal ' s output file and exports results in Rfam ' s genome full region format ( tsv option is used by default ) Infernal ' s output file in tabular format format : This is an option whether to output results in tabular format or create a json file
def infernal_to_rfam(inf_tblout_file, dest_dir, file_format='tsv'):
    in_file = open(inf_tblout_file, 'r')
    filename = os.path.basename(inf_tblout_file).partition('.')[0]
    out_file = None
    if file_format == "tsv":
        out_file = open(os.path.join(dest_dir, filename + ".tsv"), 'w')
    else:
        out_file = open(os.path.join(dest_dir, filename + ".json"), 'w')
    upid = filename
    is_significant = 1  
    seq_type = "full" 
    line = in_file.readline().strip()
    while line != '':
        if line[0] != '#':
            line = line.split(' ')
            line_cont = [x for x in line if x != '']
            genseq_acc = line_cont[2].split('|') 
            genseq_acc = genseq_acc[len(genseq_acc) - 1]  
            rfam_acc = line_cont[1] 
            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]
            out_file.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (rfam_acc, genseq_acc,
                                                                                 upid, seq_start,
                                                                                 seq_end, bit_score,
                                                                                 evalue, cm_start,
                                                                                 cm_end, trunc,
                                                                                 seq_type, is_significant))
            line = in_file.readline().strip()
        else:
            line = in_file.readline().strip()
    in_file.close()
    out_file.close()
def infernal_to_rfam ( inf_tblout_file , dest_dir , file_format = 'tsv' ) : in_file = open ( inf_tblout_file , 'r' ) filename = os . path . basename ( inf_tblout_file ) . partition ( '.' ) [ 0 ] out_file = None if file_format == "tsv" : out_file = open ( os . path . join ( dest_dir , filename + ".tsv" ) , 'w' ) else : out_file = open ( os . path . join ( dest_dir , filename + ".json" ) , 'w' ) upid = filename is_significant = 1 seq_type = "full" line = in_file . readline ( ) . strip ( ) while line != '' : if line [ 0 ] != '#' : line = line . split ( ' ' ) line_cont = [ x for x in line if x != '' ] genseq_acc = line_cont [ 2 ] . split ( '|' ) genseq_acc = genseq_acc [ len ( genseq_acc ) - 1 ] rfam_acc = line_cont [ 1 ] 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 ] out_file . write ( "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( rfam_acc , genseq_acc , upid , seq_start , seq_end , bit_score , evalue , cm_start , cm_end , trunc , seq_type , is_significant ) ) line = in_file . readline ( ) . strip ( ) else : line = in_file . readline ( ) . strip ( ) in_file . close ( ) out_file . close ( )
Parses Infernal's output file and exports results in Rfam's genome full region format
(tsv option is used by default)
Parses Infernal ' s output file and exports results in Rfam ' s genome full region format ( tsv option is used by default )
"""
    Parses Infernal's output file and exports results in Rfam's genome full region format
    (tsv option is used by default)

    inf_tblout_file: Infernal's output file in tabular format
    format: This is an option whether to output results in  tabular format or create a json file
    """ # always the same before clan competition #seq_type = "null" # set all to full until we update seed sequences # could also be position 0 for cmsearch # get last field # 1 or 3 for cmscan
inf_tblout_file
dest_dir
file_format