scripts/export/rfam_xml_dumper.py
def main(entry_type, rfam_acc, outdir, hfields=False):
    """
    This function puts everything together

    entry_type: One of the three entry types in Rfam (Motif, Clan, Family)
    rfam_acc: An Rfam associated accession (RF*,CL*,RM*). If rfam_acc is set
              to None, then all data related to the entry type will be
              exported
    hfields: A flag (True/False) indicating whether to add hierarchical
             fields on not. True by default
    outdir: Destination directory
    """

    rfam_accs = None
    entry = ""

    name_object = {}
    name_dict = {}

    try:
        # this will create the output directory if it doesn't exist
        if not os.path.exists(outdir):
            try:
                os.mkdir(outdir)
            except:
                print "Error creating output directory at: ", outdir

        # export all entries
        if rfam_acc is None:
            # Motif accessions
            if entry_type == rs.MOTIF:
                rfam_accs = fetch_value_list(None, rs.MOTIF_ACC)

            # Clan accessions
            elif entry_type == rs.CLAN:
                rfam_accs = fetch_value_list(None, rs.CLAN_ACC)

            # Genome accessions
            elif entry_type == rs.GENOME:
                rfam_accs = fetch_value_list(None, rs.GENOME_ACC)

            # Genome accessions required for exporting full region
            elif entry_type == rs.MATCH:
                rfam_accs = fetch_value_list(None, rs.GENOME_ACC)

            # Family accessions
            elif entry_type == rs.FAMILY:
                if hfields:
                    # load ncbi taxonomy browser here
                    name_dict, name_dict_reverse = read_ncbi_names_dmp(
                        rfc.TAX_NAMES_DUMP)
                    name_object = read_ncbi_taxonomy_nodes(
                        name_dict, rfc.TAX_NODES_DUMP)

                rfam_accs = fetch_value_list(None, rs.FAM_ACC)

                for entry in rfam_accs:
                    print(entry)
                    t0 = timeit.default_timer()
                    xml4db_dumper(name_dict, name_object, entry_type, entry, hfields, outdir)
                    print "%s execution time: %.1fs" % (entry, timeit.default_timer() - t0)

                return

            # Don't build hierarchical references for Clans and Motifs
            for entry in rfam_accs:
                print entry
                t0 = timeit.default_timer()
                xml4db_dumper(None, None, entry_type, entry, False, outdir)
                print "%s execution time: %.1fs" % (entry, timeit.default_timer() - t0)

        # export single entry
        else:
            # need to check the validity of an rfam_acc (rfam, motif, clan)
            if entry_type == rs.MOTIF or entry_type == rs.CLAN or entry_type == rs.GENOME:
                xml4db_dumper(None, None, entry_type, rfam_acc, False, outdir)

            # export single family entry
            else:
                if hfields:
                    # load ncbi taxonomy browser here
                    name_dict, name_dict_reverse = read_ncbi_names_dmp(
                        rfc.TAX_NAMES_DUMP)
                    name_object = read_ncbi_taxonomy_nodes(
                        name_dict, rfc.TAX_NODES_DUMP)

                xml4db_dumper(
                    name_dict, name_object, entry_type, rfam_acc, hfields, outdir)

    except:
        traceback.print_exc()
        # need to correct this one
        if rfam_acc is None:
            gen_fams = Set([x.partition('.')[0] for x in os.listdir(outdir)])
            loaded_fams = Set(rfam_accs)
            # get remaining families
            rem_fams = loaded_fams - gen_fams

            # open a log file
            logging.basicConfig(
                filename=os.path.join("missing_accs" + ".log"), filemode='w', level=logging.DEBUG)

            # write accessions to log file
            for rfam_acc in rem_fams:
                logging.debug(rfam_acc)
        else:
            print "Error exporting %s." % rfam_acc

    This function puts everything together

    entry_type: One of the three entry types in Rfam (Motif, Clan, Family)
    rfam_acc: An Rfam associated accession (RF*,CL*,RM*). If rfam_acc is set
              to None, then all data related to the entry type will be
              exported
    hfields: A flag (True/False) indicating whether to add hierarchical
             fields on not. True by default
    outdir: Destination directory
    
This function puts everything together
entry_type: One of the three entry types in Rfam (Motif, Clan, Family)
rfam_acc: An Rfam associated accession (RF*,CL*,RM*). If rfam_acc is set
to None, then all data related to the entry type will be
exported
hfields: A flag (True/False) indicating whether to add hierarchical
fields on not. True by default
outdir: Destination directory
This function puts everything together entry_type : One of the three entry types in Rfam ( Motif Clan Family ) rfam_acc : An Rfam associated accession ( RF * CL * RM * ) . If rfam_acc is set to None then all data related to the entry type will be exported hfields : A flag ( True / False ) indicating whether to add hierarchical fields on not . True by default outdir : Destination directory
def main(entry_type, rfam_acc, outdir, hfields=False):
    rfam_accs = None
    entry = ""
    name_object = {}
    name_dict = {}
    try:
        if not os.path.exists(outdir):
            try:
                os.mkdir(outdir)
            except:
                print "Error creating output directory at: ", outdir
        if rfam_acc is None:
            if entry_type == rs.MOTIF:
                rfam_accs = fetch_value_list(None, rs.MOTIF_ACC)
            elif entry_type == rs.CLAN:
                rfam_accs = fetch_value_list(None, rs.CLAN_ACC)
            elif entry_type == rs.GENOME:
                rfam_accs = fetch_value_list(None, rs.GENOME_ACC)
             required for exporting full region
            elif entry_type == rs.MATCH:
                rfam_accs = fetch_value_list(None, rs.GENOME_ACC)
            elif entry_type == rs.FAMILY:
                if hfields:
                    name_dict, name_dict_reverse = read_ncbi_names_dmp(
                        rfc.TAX_NAMES_DUMP)
                    name_object = read_ncbi_taxonomy_nodes(
                        name_dict, rfc.TAX_NODES_DUMP)
                rfam_accs = fetch_value_list(None, rs.FAM_ACC)
                for entry in rfam_accs:
                    print(entry)
                    t0 = timeit.default_timer()
                    xml4db_dumper(name_dict, name_object, entry_type, entry, hfields, outdir)
                    print "%s execution time: %.1fs" % (entry, timeit.default_timer() - t0)
                return
            for entry in rfam_accs:
                print entry
                t0 = timeit.default_timer()
                xml4db_dumper(None, None, entry_type, entry, False, outdir)
                print "%s execution time: %.1fs" % (entry, timeit.default_timer() - t0)
        else:
            if entry_type == rs.MOTIF or entry_type == rs.CLAN or entry_type == rs.GENOME:
                xml4db_dumper(None, None, entry_type, rfam_acc, False, outdir)
            else:
                if hfields:
                    name_dict, name_dict_reverse = read_ncbi_names_dmp(
                        rfc.TAX_NAMES_DUMP)
                    name_object = read_ncbi_taxonomy_nodes(
                        name_dict, rfc.TAX_NODES_DUMP)
                xml4db_dumper(
                    name_dict, name_object, entry_type, rfam_acc, hfields, outdir)
    except:
        traceback.print_exc()
        if rfam_acc is None:
            gen_fams = Set([x.partition('.')[0] for x in os.listdir(outdir)])
            loaded_fams = Set(rfam_accs)
            rem_fams = loaded_fams - gen_fams
            logging.basicConfig(
                filename=os.path.join("missing_accs" + ".log"), filemode='w', level=logging.DEBUG)
            for rfam_acc in rem_fams:
                logging.debug(rfam_acc)
        else:
            print "Error exporting %s." % rfam_acc
def main ( entry_type , rfam_acc , outdir , hfields = False ) : rfam_accs = None entry = "" name_object = { } name_dict = { } try : if not os . path . exists ( outdir ) : try : os . mkdir ( outdir ) except : print "Error creating output directory at: " , outdir if rfam_acc is None : if entry_type == rs . MOTIF : rfam_accs = fetch_value_list ( None , rs . MOTIF_ACC ) elif entry_type == rs . CLAN : rfam_accs = fetch_value_list ( None , rs . CLAN_ACC ) elif entry_type == rs . GENOME : rfam_accs = fetch_value_list ( None , rs . GENOME_ACC ) elif entry_type == rs . MATCH : rfam_accs = fetch_value_list ( None , rs . GENOME_ACC ) elif entry_type == rs . FAMILY : if hfields : name_dict , name_dict_reverse = read_ncbi_names_dmp ( rfc . TAX_NAMES_DUMP ) name_object = read_ncbi_taxonomy_nodes ( name_dict , rfc . TAX_NODES_DUMP ) rfam_accs = fetch_value_list ( None , rs . FAM_ACC ) for entry in rfam_accs : print ( entry ) t0 = timeit . default_timer ( ) xml4db_dumper ( name_dict , name_object , entry_type , entry , hfields , outdir ) print "%s execution time: %.1fs" % ( entry , timeit . default_timer ( ) - t0 ) return for entry in rfam_accs : print entry t0 = timeit . default_timer ( ) xml4db_dumper ( None , None , entry_type , entry , False , outdir ) print "%s execution time: %.1fs" % ( entry , timeit . default_timer ( ) - t0 ) else : if entry_type == rs . MOTIF or entry_type == rs . CLAN or entry_type == rs . GENOME : xml4db_dumper ( None , None , entry_type , rfam_acc , False , outdir ) else : if hfields : name_dict , name_dict_reverse = read_ncbi_names_dmp ( rfc . TAX_NAMES_DUMP ) name_object = read_ncbi_taxonomy_nodes ( name_dict , rfc . TAX_NODES_DUMP ) xml4db_dumper ( name_dict , name_object , entry_type , rfam_acc , hfields , outdir ) except : traceback . print_exc ( ) if rfam_acc is None : gen_fams = Set ( [ x . partition ( '.' ) [ 0 ] for x in os . listdir ( outdir ) ] ) loaded_fams = Set ( rfam_accs ) rem_fams = loaded_fams - gen_fams logging . basicConfig ( filename = os . path . join ( "missing_accs" + ".log" ) , filemode = 'w' , level = logging . DEBUG ) for rfam_acc in rem_fams : logging . debug ( rfam_acc ) else : print "Error exporting %s." % rfam_acc
This function puts everything together
entry_type: One of the three entry types in Rfam (Motif, Clan, Family)
rfam_acc: An Rfam associated accession (RF*,CL*,RM*).
This function puts everything together entry_type : One of the three entry types in Rfam ( Motif Clan Family ) rfam_acc : An Rfam associated accession ( RF * CL * RM * ) .
"""
    This function puts everything together

    entry_type: One of the three entry types in Rfam (Motif, Clan, Family)
    rfam_acc: An Rfam associated accession (RF*,CL*,RM*). If rfam_acc is set
              to None, then all data related to the entry type will be
              exported
    hfields: A flag (True/False) indicating whether to add hierarchical
             fields on not. True by default
    outdir: Destination directory
    """ # this will create the output directory if it doesn't exist # export all entries # Motif accessions # Clan accessions # Genome accessions # Genome accessions required for exporting full region # Family accessions # load ncbi taxonomy browser here # Don't build hierarchical references for Clans and Motifs # export single entry # need to check the validity of an rfam_acc (rfam, motif, clan) # export single family entry # load ncbi taxonomy browser here # need to correct this one # get remaining families # open a log file # write accessions to log file
entry_type
rfam_acc
outdir
hfields