scripts/support/fasta2rfamseq.py
def extract_metadata_from_fasta(fasta_file, taxid, source, filename=None, to_file=True):
    """
    Parses a fasta file and generates rfamseq like matadata using esl-seqstat

    fasta_file: A valid fasta file
    taxid: A file with upid and taxid mappings.
    database:

    returns: void
    """

    mol_type = "genomic DNA"
    previous_acc = ''
    seq_acc_taxids = {}
    # default flag
    is_taxid_str = True

    # check if taxid is file 
    if os.path.isfile(taxid):
        is_taxid_str = False

        fp = open(taxid, 'r')
        
        for line in fp:
            line = line.strip().split('\t')
            seq_acc_taxids[line[0]] = line[1]
        fp.close()  

    # create an output file pointed
    output_fp = None

    if to_file is True:
        if filename is None:
            filename = os.path.basename(fasta_file).partition('.')[0]
        destination = os.path.split(fasta_file)[0]
        output_fp = open(os.path.join(destination, filename+".rfamseq"), 'w')

    args = [gf.ESL_SEQSTAT, "-a", "--dna", fasta_file]
    # open a process pipe and run esl-seqstat. Stores the result in process
    process = subprocess.Popen(args, stdout=subprocess.PIPE)
    
    # fetch esl-seqstat results
    result = process.communicate()

    # read in and clean-up sequence stats
    seq_stats = [x[2:] for x in result[0].strip().split('\n') if x[0] == '=']

    # process every sequence header to generate a rfamseq entry
    for sequence in seq_stats:
        seq_elements = [x.strip() for x in sequence.split(' ') if x != '']

        rfamseq_acc = seq_elements[0].split('|')[-1]
        accession = rfamseq_acc.partition('.')[0]
        version = rfamseq_acc.partition('.')[2]
        length = seq_elements[1]
        description = " ".join(seq_elements[2:])

        if not is_taxid_str:
            taxid = seq_acc_taxids[rfamseq_acc]

        rfamseq_entry = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (rfamseq_acc, accession,
                                                      "00000"+str(version), taxid,
                                                      mol_type, length,
                                                      description, previous_acc,
                                                      source)
        if to_file is True:
            output_fp.write(rfamseq_entry+'\n')
        else:
            print (rfamseq_entry)

    if to_file is True:
        output_fp.close()

    Parses a fasta file and generates rfamseq like matadata using esl-seqstat

    fasta_file: A valid fasta file
    taxid: A file with upid and taxid mappings.
    database:

    returns: void
    
Parses a fasta file and generates rfamseq like matadata using esl-seqstat
fasta_file: A valid fasta file
taxid: A file with upid and taxid mappings.
database.

void
Parses a fasta file and generates rfamseq like matadata using esl - seqstat fasta_file : A valid fasta file taxid : A file with upid and taxid mappings . database . void
def extract_metadata_from_fasta(fasta_file, taxid, source, filename=None, to_file=True):
    mol_type = "genomic DNA"
    previous_acc = ''
    seq_acc_taxids = {}
    is_taxid_str = True
    if os.path.isfile(taxid):
        is_taxid_str = False
        fp = open(taxid, 'r')
        for line in fp:
            line = line.strip().split('\t')
            seq_acc_taxids[line[0]] = line[1]
        fp.close()  
    output_fp = None
    if to_file is True:
        if filename is None:
            filename = os.path.basename(fasta_file).partition('.')[0]
        destination = os.path.split(fasta_file)[0]
        output_fp = open(os.path.join(destination, filename+".rfamseq"), 'w')
    args = [gf.ESL_SEQSTAT, "-a", "--dna", fasta_file]
    process = subprocess.Popen(args, stdout=subprocess.PIPE)
    result = process.communicate()
    seq_stats = [x[2:] for x in result[0].strip().split('\n') if x[0] == '=']
    for sequence in seq_stats:
        seq_elements = [x.strip() for x in sequence.split(' ') if x != '']
        rfamseq_acc = seq_elements[0].split('|')[-1]
        accession = rfamseq_acc.partition('.')[0]
        version = rfamseq_acc.partition('.')[2]
        length = seq_elements[1]
        description = " ".join(seq_elements[2:])
        if not is_taxid_str:
            taxid = seq_acc_taxids[rfamseq_acc]
        rfamseq_entry = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (rfamseq_acc, accession,
                                                      "00000"+str(version), taxid,
                                                      mol_type, length,
                                                      description, previous_acc,
                                                      source)
        if to_file is True:
            output_fp.write(rfamseq_entry+'\n')
        else:
            print (rfamseq_entry)
    if to_file is True:
        output_fp.close()
def extract_metadata_from_fasta ( fasta_file , taxid , source , filename = None , to_file = True ) : mol_type = "genomic DNA" previous_acc = '' seq_acc_taxids = { } is_taxid_str = True if os . path . isfile ( taxid ) : is_taxid_str = False fp = open ( taxid , 'r' ) for line in fp : line = line . strip ( ) . split ( '\t' ) seq_acc_taxids [ line [ 0 ] ] = line [ 1 ] fp . close ( ) output_fp = None if to_file is True : if filename is None : filename = os . path . basename ( fasta_file ) . partition ( '.' ) [ 0 ] destination = os . path . split ( fasta_file ) [ 0 ] output_fp = open ( os . path . join ( destination , filename + ".rfamseq" ) , 'w' ) args = [ gf . ESL_SEQSTAT , "-a" , "--dna" , fasta_file ] process = subprocess . Popen ( args , stdout = subprocess . PIPE ) result = process . communicate ( ) seq_stats = [ x [ 2 : ] for x in result [ 0 ] . strip ( ) . split ( '\n' ) if x [ 0 ] == '=' ] for sequence in seq_stats : seq_elements = [ x . strip ( ) for x in sequence . split ( ' ' ) if x != '' ] rfamseq_acc = seq_elements [ 0 ] . split ( '|' ) [ - 1 ] accession = rfamseq_acc . partition ( '.' ) [ 0 ] version = rfamseq_acc . partition ( '.' ) [ 2 ] length = seq_elements [ 1 ] description = " " . join ( seq_elements [ 2 : ] ) if not is_taxid_str : taxid = seq_acc_taxids [ rfamseq_acc ] rfamseq_entry = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % ( rfamseq_acc , accession , "00000" + str ( version ) , taxid , mol_type , length , description , previous_acc , source ) if to_file is True : output_fp . write ( rfamseq_entry + '\n' ) else : print ( rfamseq_entry ) if to_file is True : output_fp . close ( )
Parses a fasta file and generates rfamseq like matadata using esl-seqstat
fasta_file: A valid fasta file
taxid: A file with upid and taxid mappings.
Parses a fasta file and generates rfamseq like matadata using esl - seqstat fasta_file : A valid fasta file taxid : A file with upid and taxid mappings .
"""
    Parses a fasta file and generates rfamseq like matadata using esl-seqstat

    fasta_file: A valid fasta file
    taxid: A file with upid and taxid mappings.
    database:

    returns: void
    """ # default flag # check if taxid is file  # create an output file pointed # open a process pipe and run esl-seqstat. Stores the result in process # fetch esl-seqstat results # read in and clean-up sequence stats # process every sequence header to generate a rfamseq entry
fasta_file
taxid
source
filename
to_file