scripts/support/populate_region_md5s.py
def generate_md5s_and_populate_table(seq_file, type = "seed", dest_dir = None):
    """
    Fetches seed of full regions from the database and populates/updates the
    appropriate table with the md5s of the corresponding ncRNA sequences.

    seq_file: This can be the Rfam.seed file (seed) or an Rfamseq file (full)
    type: one of seed/full

    return: void
    """

    if dest_dir is None:
        dest_dir = os.path.split(seq_file)[0]


    region_rows = None

    if type == "seed":
        region_rows = sr.fetch_seed_regions()
    elif type == "full":
        region_rows = db.fetch_metagenomic_regions()

    sql_data_list = []

    fp_err = None

    for seq_region in region_rows:
        seq_acc = seq_region[1]
        seq_start = seq_region[2]
        seq_end = seq_region[3]
        rfam_acc = seq_region[0]

        # extract sequence from sequence file
        sequence = fetch_sequence(seq_file, seq_acc, seq_start, seq_end, type)
        
	# Replace Ts with Us as done by RNAcentral
        # Note: there shouldn't be any in the seed alignments
        sequence = sequence.replace('T', 'U')

        if sequence != '' and len(sequence) > 2:
            # convert sequence to md5
            m = hashlib.md5()
            m.update(sequence)
            seq_md5 = m.hexdigest()
            # update tuple
            extended_tuple = (seq_md5, rfam_acc, seq_acc, seq_start, seq_end)
            # add to new list
            sql_data_list.append(extended_tuple)
            extended_tuple = None

        else:
            # check if first error
            if fp_err is None:
                fp_err = open(os.path.join(dest_dir, "md5.err"), 'w')

            fp_err.write("Error extracting sequence %s at %s-%s of %s\n" % (seq_acc,
                                                                            seq_start,
                                                                            seq_end,
                                                                            rfam_acc))

    # update/populate table
    if type == "seed":
        sr.update_seed_region_md5s(sql_data_list)
    else:
        db.update_metagenomic_region_md5s(sql_data_list)

    # close error file if opened
    if fp_err is not None:
        fp_err.close()

    Fetches seed of full regions from the database and populates/updates the
    appropriate table with the md5s of the corresponding ncRNA sequences.

    seq_file: This can be the Rfam.seed file (seed) or an Rfamseq file (full)
    type: one of seed/full

    return: void
    
Fetches seed of full regions from the database and populates/updates the
appropriate table with the md5s of the corresponding ncRNA sequences.

This can be the Rfam.seed file  or an Rfamseq file (full)
type: one of seed/full

void
Fetches seed of full regions from the database and populates / updates the appropriate table with the md5s of the corresponding ncRNA sequences . This can be the Rfam . seed file or an Rfamseq file ( full ) type : one of seed / full void
def generate_md5s_and_populate_table(seq_file, type = "seed", dest_dir = None):
    if dest_dir is None:
        dest_dir = os.path.split(seq_file)[0]
    region_rows = None
    if type == "seed":
        region_rows = sr.fetch_seed_regions()
    elif type == "full":
        region_rows = db.fetch_metagenomic_regions()
    sql_data_list = []
    fp_err = None
    for seq_region in region_rows:
        seq_acc = seq_region[1]
        seq_start = seq_region[2]
        seq_end = seq_region[3]
        rfam_acc = seq_region[0]
        sequence = fetch_sequence(seq_file, seq_acc, seq_start, seq_end, type)
        sequence = sequence.replace('T', 'U')
        if sequence != '' and len(sequence) > 2:
            m = hashlib.md5()
            m.update(sequence)
            seq_md5 = m.hexdigest()
            extended_tuple = (seq_md5, rfam_acc, seq_acc, seq_start, seq_end)
            sql_data_list.append(extended_tuple)
            extended_tuple = None
        else:
            if fp_err is None:
                fp_err = open(os.path.join(dest_dir, "md5.err"), 'w')
            fp_err.write("Error extracting sequence %s at %s-%s of %s\n" % (seq_acc,
                                                                            seq_start,
                                                                            seq_end,
                                                                            rfam_acc))
    if type == "seed":
        sr.update_seed_region_md5s(sql_data_list)
    else:
        db.update_metagenomic_region_md5s(sql_data_list)
    if fp_err is not None:
        fp_err.close()
def generate_md5s_and_populate_table ( seq_file , type = "seed" , dest_dir = None ) : if dest_dir is None : dest_dir = os . path . split ( seq_file ) [ 0 ] region_rows = None if type == "seed" : region_rows = sr . fetch_seed_regions ( ) elif type == "full" : region_rows = db . fetch_metagenomic_regions ( ) sql_data_list = [ ] fp_err = None for seq_region in region_rows : seq_acc = seq_region [ 1 ] seq_start = seq_region [ 2 ] seq_end = seq_region [ 3 ] rfam_acc = seq_region [ 0 ] sequence = fetch_sequence ( seq_file , seq_acc , seq_start , seq_end , type ) sequence = sequence . replace ( 'T' , 'U' ) if sequence != '' and len ( sequence ) > 2 : m = hashlib . md5 ( ) m . update ( sequence ) seq_md5 = m . hexdigest ( ) extended_tuple = ( seq_md5 , rfam_acc , seq_acc , seq_start , seq_end ) sql_data_list . append ( extended_tuple ) extended_tuple = None else : if fp_err is None : fp_err = open ( os . path . join ( dest_dir , "md5.err" ) , 'w' ) fp_err . write ( "Error extracting sequence %s at %s-%s of %s\n" % ( seq_acc , seq_start , seq_end , rfam_acc ) ) if type == "seed" : sr . update_seed_region_md5s ( sql_data_list ) else : db . update_metagenomic_region_md5s ( sql_data_list ) if fp_err is not None : fp_err . close ( )
Fetches seed of full regions from the database and populates/updates the
appropriate table with the md5s of the corresponding ncRNA sequences.
Fetches seed of full regions from the database and populates / updates the appropriate table with the md5s of the corresponding ncRNA sequences .
"""
    Fetches seed of full regions from the database and populates/updates the
    appropriate table with the md5s of the corresponding ncRNA sequences.

    seq_file: This can be the Rfam.seed file (seed) or an Rfamseq file (full)
    type: one of seed/full

    return: void
    """ # extract sequence from sequence file # Replace Ts with Us as done by RNAcentral # Note: there shouldn't be any in the seed alignments # convert sequence to md5 # update tuple # add to new list # check if first error # update/populate table # close error file if opened
seq_file
type
dest_dir