scripts/export/fasta_file_generator.py
def generate_fasta(seq_file, out_dir):
    """
    Uses esl-sfetch to generate family specific fasta files out of seq_file
    which is provided as source (e.g. rfamseq11.fa). It will generate fasta
    files for all families by default

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

    out_dir:    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, "missing_seqs.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 clan specific family full_region data and sequence description

    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"
             "ORDER BY fr.rfam_acc")

    # execute the query
    cursor.execute(query)

    for region in cursor:

        # new family
        if str(region[RFAM_ACC]) != rfam_acc:
            # check if there's no open file
            if fp_out is not None:
                fp_out.close()

            # open new fasta file
            fp_out = gzip.open(
                os.path.join(out_dir, str(region[RFAM_ACC]) + ".fa.gz"), 'w')

        rfam_acc = region[RFAM_ACC]

        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(sequence)

    # 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 (e.g. rfamseq11.fa). It will generate fasta
    files for all families by default

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

    out_dir:    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 . It will generate fasta
files for all families by default

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

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 . It will generate fasta files for all families by default The path to rfamseq input file in fasta format for generating the fasta files Destination directory where the files will be generated
def generate_fasta(seq_file, out_dir):
    sequence = ''
    fp_out = None
    seq_bits = 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 = ("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"
             "ORDER BY fr.rfam_acc")
    cursor.execute(query)
    for region in cursor:
        if str(region[RFAM_ACC]) != rfam_acc:
            if fp_out is not None:
                fp_out.close()
            fp_out = gzip.open(
                os.path.join(out_dir, str(region[RFAM_ACC]) + ".fa.gz"), 'w')
        rfam_acc = region[RFAM_ACC]
        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(sequence)
    fp_out.close()
    cursor.close()
    RfamDB.disconnect(cnx)
def generate_fasta ( seq_file , out_dir ) : sequence = '' fp_out = None seq_bits = 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 = ( "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" "ORDER BY fr.rfam_acc" ) cursor . execute ( query ) for region in cursor : if str ( region [ RFAM_ACC ] ) != rfam_acc : if fp_out is not None : fp_out . close ( ) fp_out = gzip . open ( os . path . join ( out_dir , str ( region [ RFAM_ACC ] ) + ".fa.gz" ) , 'w' ) rfam_acc = region [ RFAM_ACC ] 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 ( sequence ) 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 (e.g.
Uses esl - sfetch to generate family specific fasta files out of seq_file which is provided as source ( e . g .
"""
    Uses esl-sfetch to generate family specific fasta files out of seq_file
    which is provided as source (e.g. rfamseq11.fa). It will generate fasta
    files for all families by default

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

    out_dir:    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 clan specific family full_region data and sequence description # execute the query # new family # check if there's no open file # open new fasta file # get sequence # print sequence # write header # write sequence # logging sequences that have not been exported # close last file # disconnect from DB
seq_file
out_dir