scripts/export/fasta_file_generator.py
def generate_fasta_single(seq_file, rfam_acc, out_dir):
    """
    Uses esl-sfetch to generate family specific fasta files out of seq_file
    which is provided as source. Works on single family based on rfam_acc.
    Files are generated in a compressed .fa.gz format

    seq_file:   This is the the path to rfamseq input file in fasta format,
                for generating the fasta files

    rfam_acc:   The rfam_acc of a specific family

    out_dir:    This is the destination directory where the files will be
                generated
    """

    sequence = ''
    fp_out = None
    seq_bits = None

    # logging sequences not exported
    # rename this to family log
    log_file = os.path.join(out_dir, rfam_acc + ".log")
    logging.basicConfig(
        filename=log_file, filemode='w', level=logging.INFO)

    # connect to db
    cnx = RfamDB.connect()

    # get a new buffered cursor
    cursor = cnx.cursor(raw=True)

    # fetch sequence accessions for specific family - significant only!!
    query = ("SELECT fr.rfam_acc, fr.rfamseq_acc, fr.seq_start, fr.seq_end, rf.description\n"
             "FROM full_region fr, rfamseq rf\n"
             "WHERE fr.rfamseq_acc=rf.rfamseq_acc\n"
             "AND fr.is_significant=1\n"
             "AND fr.rfam_acc=\'%s\'") % (rfam_acc)

    # execute the query
    cursor.execute(query)

    # open a new fasta output file
    fp_out = gzip.open(
        os.path.join(out_dir, str(rfam_acc) + ".fa.gz"), 'w')

    for region in cursor:

        cmd = "esl-sfetch -c %s/%s %s %s" % (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)

        # print sequence

        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 sequences that have not been exported
            logging.info(str(region[SEQ_ACC]))

    # close last file
    fp_out.close()

    # disconnect from DB
    cursor.close()
    RfamDB.disconnect(cnx)

    Uses esl-sfetch to generate family specific fasta files out of seq_file
    which is provided as source. Works on single family based on rfam_acc.
    Files are generated in a compressed .fa.gz format

    seq_file:   This is the the path to rfamseq input file in fasta format,
                for generating the fasta files

    rfam_acc:   The rfam_acc of a specific family

    out_dir:    This is the destination directory where the files will be
                generated
    
Uses esl-sfetch to generate family specific fasta files out of seq_file
which is provided as source. Works on single family based on rfam_acc.
Files are generated in a compressed .fa.gz format

This is the the path to rfamseq input file in fasta format,
for generating the fasta files

The rfam_acc of a specific family

This is the destination directory where the files will be
generated
Uses esl - sfetch to generate family specific fasta files out of seq_file which is provided as source . Works on single family based on rfam_acc . Files are generated in a compressed . fa . gz format This is the the path to rfamseq input file in fasta format for generating the fasta files The rfam_acc of a specific family This is the destination directory where the files will be generated
def generate_fasta_single(seq_file, rfam_acc, out_dir):
    sequence = ''
    fp_out = None
    seq_bits = None
    log_file = os.path.join(out_dir, rfam_acc + ".log")
    logging.basicConfig(
        filename=log_file, filemode='w', level=logging.INFO)
    cnx = RfamDB.connect()
    cursor = cnx.cursor(raw=True)
    query = ("SELECT fr.rfam_acc, fr.rfamseq_acc, fr.seq_start, fr.seq_end, rf.description\n"
             "FROM full_region fr, rfamseq rf\n"
             "WHERE fr.rfamseq_acc=rf.rfamseq_acc\n"
             "AND fr.is_significant=1\n"
             "AND fr.rfam_acc=\'%s\'") % (rfam_acc)
    cursor.execute(query)
    fp_out = gzip.open(
        os.path.join(out_dir, str(rfam_acc) + ".fa.gz"), 'w')
    for region in cursor:
        cmd = "esl-sfetch -c %s/%s %s %s" % (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(str(region[SEQ_ACC]))
    fp_out.close()
    cursor.close()
    RfamDB.disconnect(cnx)
def generate_fasta_single ( seq_file , rfam_acc , out_dir ) : sequence = '' fp_out = None seq_bits = None log_file = os . path . join ( out_dir , rfam_acc + ".log" ) logging . basicConfig ( filename = log_file , filemode = 'w' , level = logging . INFO ) cnx = RfamDB . connect ( ) cursor = cnx . cursor ( raw = True ) query = ( "SELECT fr.rfam_acc, fr.rfamseq_acc, fr.seq_start, fr.seq_end, rf.description\n" "FROM full_region fr, rfamseq rf\n" "WHERE fr.rfamseq_acc=rf.rfamseq_acc\n" "AND fr.is_significant=1\n" "AND fr.rfam_acc=\'%s\'" ) % ( rfam_acc ) cursor . execute ( query ) fp_out = gzip . open ( os . path . join ( out_dir , str ( rfam_acc ) + ".fa.gz" ) , 'w' ) for region in cursor : cmd = "esl-sfetch -c %s/%s %s %s" % ( 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 ( str ( region [ SEQ_ACC ] ) ) fp_out . close ( ) cursor . close ( ) RfamDB . disconnect ( cnx )
Uses esl-sfetch to generate family specific fasta files out of seq_file
which is provided as source.
Uses esl - sfetch to generate family specific fasta files out of seq_file which is provided as source .
"""
    Uses esl-sfetch to generate family specific fasta files out of seq_file
    which is provided as source. Works on single family based on rfam_acc.
    Files are generated in a compressed .fa.gz format

    seq_file:   This is the the path to rfamseq input file in fasta format,
                for generating the fasta files

    rfam_acc:   The rfam_acc of a specific family

    out_dir:    This is the destination directory where the files will be
                generated
    """ # logging sequences not exported # rename this to family log # connect to db # get a new buffered cursor # fetch sequence accessions for specific family - significant only!! # execute the query # open a new fasta output file # get sequence # print sequence # write header # write sequence # logging sequences that have not been exported # close last file # disconnect from DB
seq_file
rfam_acc
out_dir