scripts/export/fasta_export.py
def export_sequences(seq_db, sql, filename=None, out_dir=None):
    """
    Exporting sequences from rfam_live and generating a fasta file
    by fetching the corresponding regions from seq_db provided as param

    seq_db:     A fasta sequence database to extract sequence regions from.
                Default seq_db is rfamseq11.fa
    sql:        The query to execute (string or valid .sql file)
    filename:   Ouput filename
    out_dir:    A path to the output directory
    """

    log_file = os.path.join(out_dir, "missing_seqs.log")
    logging.basicConfig(
        filename=log_file, filemode='w', level=logging.INFO)

    cnx = RfamDB.connect()
    cursor = cnx.cursor(raw=True)

    query = ''

    if os.path.isfile(sql):
        fp = open(sql, 'r')
        query = ' '.join(fp.readlines())

    else:
        query = sql

    cursor.execute(query)

    # open an output file
    fp_out = None

    if filename is not None:
        fp_out = gzip.open(
            os.path.join(out_dir, filename + ".fa.gz"), 'w')
    else:
        fp_out = gzip.open(os.path.join(out_dir, OUT_FILE_NAME), 'w')

    for region in cursor:
        cmd = "%s -c %s/%s %s %s" % (ESL_PATH,
                                     str(region[START]), str(region[END]),
                                     seq_file, str(region[SEQ_ACC]))

        proc = subprocess.Popen(
            cmd, shell=True, stdout=subprocess.PIPE)

        seq = proc.communicate()[0]

        # get sequence
        sequence = ''
        seq_bits = seq.split('\n')[1:]
        sequence = sequence.join(seq_bits)

        if (sequence != '' and seq_validator(sequence) is True):
            # write header
            fp_out.write(">%s/%s-%s %s\n" % (str(region[SEQ_ACC]),
                                             str(region[START]),
                                             str(region[END]),
                                             str(region[DESC])))

            # write sequence
            fp_out.write(sequence + '\n')

        else:
            logging.info(sequence)

    fp_out.close()

    cursor.close()
    RfamDB.disconnect(cnx)

    Exporting sequences from rfam_live and generating a fasta file
    by fetching the corresponding regions from seq_db provided as param

    seq_db:     A fasta sequence database to extract sequence regions from.
                Default seq_db is rfamseq11.fa
    sql:        The query to execute (string or valid .sql file)
    filename:   Ouput filename
    out_dir:    A path to the output directory
    
Exporting sequences from rfam_live and generating a fasta file
by fetching the corresponding regions from seq_db provided as param

A fasta sequence database to extract sequence regions from.
Default seq_db is rfamseq11.fa
sql:        The query to execute (string or valid .sql file)
filename:   Ouput filename
out_dir:    A path to the output directory
Exporting sequences from rfam_live and generating a fasta file by fetching the corresponding regions from seq_db provided as param A fasta sequence database to extract sequence regions from . Default seq_db is rfamseq11 . fa sql : The query to execute ( string or valid . sql file ) filename : Ouput filename out_dir : A path to the output directory
def export_sequences(seq_db, sql, filename=None, out_dir=None):
    log_file = os.path.join(out_dir, "missing_seqs.log")
    logging.basicConfig(
        filename=log_file, filemode='w', level=logging.INFO)
    cnx = RfamDB.connect()
    cursor = cnx.cursor(raw=True)
    query = ''
    if os.path.isfile(sql):
        fp = open(sql, 'r')
        query = ' '.join(fp.readlines())
    else:
        query = sql
    cursor.execute(query)
    fp_out = None
    if filename is not None:
        fp_out = gzip.open(
            os.path.join(out_dir, filename + ".fa.gz"), 'w')
    else:
        fp_out = gzip.open(os.path.join(out_dir, OUT_FILE_NAME), 'w')
    for region in cursor:
        cmd = "%s -c %s/%s %s %s" % (ESL_PATH,
                                     str(region[START]), str(region[END]),
                                     seq_file, str(region[SEQ_ACC]))
        proc = subprocess.Popen(
            cmd, shell=True, stdout=subprocess.PIPE)
        seq = proc.communicate()[0]
        sequence = ''
        seq_bits = seq.split('\n')[1:]
        sequence = sequence.join(seq_bits)
        if (sequence != '' and seq_validator(sequence) is True):
            fp_out.write(">%s/%s-%s %s\n" % (str(region[SEQ_ACC]),
                                             str(region[START]),
                                             str(region[END]),
                                             str(region[DESC])))
            fp_out.write(sequence + '\n')
        else:
            logging.info(sequence)
    fp_out.close()
    cursor.close()
    RfamDB.disconnect(cnx)
def export_sequences ( seq_db , sql , filename = None , out_dir = None ) : log_file = os . path . join ( out_dir , "missing_seqs.log" ) logging . basicConfig ( filename = log_file , filemode = 'w' , level = logging . INFO ) cnx = RfamDB . connect ( ) cursor = cnx . cursor ( raw = True ) query = '' if os . path . isfile ( sql ) : fp = open ( sql , 'r' ) query = ' ' . join ( fp . readlines ( ) ) else : query = sql cursor . execute ( query ) fp_out = None if filename is not None : fp_out = gzip . open ( os . path . join ( out_dir , filename + ".fa.gz" ) , 'w' ) else : fp_out = gzip . open ( os . path . join ( out_dir , OUT_FILE_NAME ) , 'w' ) for region in cursor : cmd = "%s -c %s/%s %s %s" % ( ESL_PATH , str ( region [ START ] ) , str ( region [ END ] ) , seq_file , str ( region [ SEQ_ACC ] ) ) proc = subprocess . Popen ( cmd , shell = True , stdout = subprocess . PIPE ) seq = proc . communicate ( ) [ 0 ] sequence = '' seq_bits = seq . split ( '\n' ) [ 1 : ] sequence = sequence . join ( seq_bits ) if ( sequence != '' and seq_validator ( sequence ) is True ) : fp_out . write ( ">%s/%s-%s %s\n" % ( str ( region [ SEQ_ACC ] ) , str ( region [ START ] ) , str ( region [ END ] ) , str ( region [ DESC ] ) ) ) fp_out . write ( sequence + '\n' ) else : logging . info ( sequence ) fp_out . close ( ) cursor . close ( ) RfamDB . disconnect ( cnx )
Exporting sequences from rfam_live and generating a fasta file
by fetching the corresponding regions from seq_db provided as param
Exporting sequences from rfam_live and generating a fasta file by fetching the corresponding regions from seq_db provided as param
"""
    Exporting sequences from rfam_live and generating a fasta file
    by fetching the corresponding regions from seq_db provided as param

    seq_db:     A fasta sequence database to extract sequence regions from.
                Default seq_db is rfamseq11.fa
    sql:        The query to execute (string or valid .sql file)
    filename:   Ouput filename
    out_dir:    A path to the output directory
    """ # open an output file # get sequence # write header # write sequence
seq_db
sql
filename
out_dir