scripts/export/rnac2json.py
def rnac_to_json_multi(seq_dir, fasta_dir, out_dir=None):
    """
    This is an implementation of the rnac_to_json function with the
    difference that input is split to smaller files prior to the json
    generation. It exports the sequences out of the Rfam's currenct version
    of fasta files.

    seq_dir:    The path to the directory containing multiple sequence
                files to be converted to json
    fasta_dir:  The path to the directory containing the fasta files of the
                current Rfam release
    out_dir:    The path to the output directory
    """

    if out_dir is None:
        out_dir = seq_dir

    seq_files = os.listdir(seq_dir)
    seq_files = filter(lambda x: string.find(x, ".txt") != -1, seq_files)

    # open a new log file and keep track of the sequences not found in the
    logging.basicConfig(filename=os.path.join(out_dir, "obsolete_seqs.log"),
                        filemode='w', level=logging.DEBUG)

    json_obj_list = []

    for seq_file in seq_files:

        fp = open(os.path.join(seq_dir, seq_file), 'r')
        seq_file_path = ''
        for entry in fp:
            entry = entry.strip().split('\t')

            if entry[ALIGNMENT] == 'seed' or entry[ALIGNMENT] == 'SEED':
                seq_file_path = os.path.join(fasta_dir, "Rfam.seed")
            else:
                seq_file_path = os.path.join(fasta_dir, entry[RFAM_ACC] + ".fa")

            sequence = ''
            seq_bits = None

            # check if the fasta file exists
            if os.path.exists(seq_file_path):
                seq_id = entry[SEQACC] + '/' + \
                         entry[SEQ_START] + '-' + entry[SEQ_END]

                cmd = "esl-sfetch %s %s" % (seq_file_path, seq_id)

                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 not found try fetching the sequence from ENA
            # if (sequence == ''):
            #    sequence = fetch_seq_from_ena(entry)

            # check if seq string still empty,
            if sequence != '' and seq_validator(sequence) is True:
                json_obj_list.append(build_json_dict(entry, sequence))
            else:
                # log obsolete sequence
                logging.debug("%s", "\t".join(entry))

            seq_id = None

        fp_out = open(
            os.path.join(out_dir, seq_file.partition(".")[0] + ".json"), 'w')

        json.dump(
            json_obj_list, fp_out, indent=2, separators=(',', ':'))

        json_obj_list = []

        fp_out.close()
        fp.close()

    This is an implementation of the rnac_to_json function with the
    difference that input is split to smaller files prior to the json
    generation. It exports the sequences out of the Rfam's currenct version
    of fasta files.

    seq_dir:    The path to the directory containing multiple sequence
                files to be converted to json
    fasta_dir:  The path to the directory containing the fasta files of the
                current Rfam release
    out_dir:    The path to the output directory
    
This is an implementation of the rnac_to_json function with the
difference that input is split to smaller files prior to the json
generation. It exports the sequences out of the Rfam's currenct version
of fasta files.

The path to the directory containing multiple sequence
files to be converted to json
fasta_dir:  The path to the directory containing the fasta files of the
current Rfam release
out_dir:    The path to the output directory
This is an implementation of the rnac_to_json function with the difference that input is split to smaller files prior to the json generation . It exports the sequences out of the Rfam ' s currenct version of fasta files . The path to the directory containing multiple sequence files to be converted to json fasta_dir : The path to the directory containing the fasta files of the current Rfam release out_dir : The path to the output directory
def rnac_to_json_multi(seq_dir, fasta_dir, out_dir=None):
    if out_dir is None:
        out_dir = seq_dir
    seq_files = os.listdir(seq_dir)
    seq_files = filter(lambda x: string.find(x, ".txt") != -1, seq_files)
    logging.basicConfig(filename=os.path.join(out_dir, "obsolete_seqs.log"),
                        filemode='w', level=logging.DEBUG)
    json_obj_list = []
    for seq_file in seq_files:
        fp = open(os.path.join(seq_dir, seq_file), 'r')
        seq_file_path = ''
        for entry in fp:
            entry = entry.strip().split('\t')
            if entry[ALIGNMENT] == 'seed' or entry[ALIGNMENT] == 'SEED':
                seq_file_path = os.path.join(fasta_dir, "Rfam.seed")
            else:
                seq_file_path = os.path.join(fasta_dir, entry[RFAM_ACC] + ".fa")
            sequence = ''
            seq_bits = None
            if os.path.exists(seq_file_path):
                seq_id = entry[SEQACC] + '/' + \
                         entry[SEQ_START] + '-' + entry[SEQ_END]
                cmd = "esl-sfetch %s %s" % (seq_file_path, seq_id)
                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:
                json_obj_list.append(build_json_dict(entry, sequence))
            else:
                logging.debug("%s", "\t".join(entry))
            seq_id = None
        fp_out = open(
            os.path.join(out_dir, seq_file.partition(".")[0] + ".json"), 'w')
        json.dump(
            json_obj_list, fp_out, indent=2, separators=(',', ':'))
        json_obj_list = []
        fp_out.close()
        fp.close()
def rnac_to_json_multi ( seq_dir , fasta_dir , out_dir = None ) : if out_dir is None : out_dir = seq_dir seq_files = os . listdir ( seq_dir ) seq_files = filter ( lambda x : string . find ( x , ".txt" ) != - 1 , seq_files ) logging . basicConfig ( filename = os . path . join ( out_dir , "obsolete_seqs.log" ) , filemode = 'w' , level = logging . DEBUG ) json_obj_list = [ ] for seq_file in seq_files : fp = open ( os . path . join ( seq_dir , seq_file ) , 'r' ) seq_file_path = '' for entry in fp : entry = entry . strip ( ) . split ( '\t' ) if entry [ ALIGNMENT ] == 'seed' or entry [ ALIGNMENT ] == 'SEED' : seq_file_path = os . path . join ( fasta_dir , "Rfam.seed" ) else : seq_file_path = os . path . join ( fasta_dir , entry [ RFAM_ACC ] + ".fa" ) sequence = '' seq_bits = None if os . path . exists ( seq_file_path ) : seq_id = entry [ SEQACC ] + '/' + entry [ SEQ_START ] + '-' + entry [ SEQ_END ] cmd = "esl-sfetch %s %s" % ( seq_file_path , seq_id ) 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 : json_obj_list . append ( build_json_dict ( entry , sequence ) ) else : logging . debug ( "%s" , "\t" . join ( entry ) ) seq_id = None fp_out = open ( os . path . join ( out_dir , seq_file . partition ( "." ) [ 0 ] + ".json" ) , 'w' ) json . dump ( json_obj_list , fp_out , indent = 2 , separators = ( ',' , ':' ) ) json_obj_list = [ ] fp_out . close ( ) fp . close ( )
This is an implementation of the rnac_to_json function with the
difference that input is split to smaller files prior to the json
generation.
This is an implementation of the rnac_to_json function with the difference that input is split to smaller files prior to the json generation .
"""
    This is an implementation of the rnac_to_json function with the
    difference that input is split to smaller files prior to the json
    generation. It exports the sequences out of the Rfam's currenct version
    of fasta files.

    seq_dir:    The path to the directory containing multiple sequence
                files to be converted to json
    fasta_dir:  The path to the directory containing the fasta files of the
                current Rfam release
    out_dir:    The path to the output directory
    """ # open a new log file and keep track of the sequences not found in the # check if the fasta file exists # get sequence # if sequence not found try fetching the sequence from ENA # if (sequence == ''): #    sequence = fetch_seq_from_ena(entry) # check if seq string still empty, # log obsolete sequence
seq_dir
fasta_dir
out_dir