def read_ncbi_phylogeny_mysql(con,downloadD): taxon_pyv=downloadD+'/nodes_hash.pyv' if os.path.isfile(taxon_pyv): fp=open(taxon_pyv,'r') h_tax_node2par = pickle.load(fp) else: #h_tax_node2par = taxon_rel_in_hash(nodes_fn) h_tax_node2par = dbUtils.taxon_rel_in_hash_mysql(con) fp=open(taxon_pyv,'w') pickle.dump(h_tax_node2par,fp) fp.close() return h_tax_node2par
def append_ti_into_fasta_app(ncbiNt, taxon_ids, subTaxF, MySqlConf, enable_descF, enable_onlineF, outPrefix, outDir): invalSelFlag = False # Not generating invalid fasta file by default GET_ALL_TAX = -2 NAs = 'X' (hostname, port, user, passwd, defaultDb) = range(5) useHash = False workD = outDir + os.sep + 'ncbiDB' if not os.path.exists(workD): os.makedirs(workD) valSel = outDir + os.sep + outPrefix + '_ti.fa' invalSel = outDir + os.sep + outPrefix + '_ti_inval.fa' if MySqlConf[ passwd] == NAs: #then, we use download gi2tax instead of using mysql query useHash = True gi2taxDump = getGi2TaxDump_online(workD) nodes_fn = getNodesDump_online(workD) if not useHash: con = dbUtils.init_mysql_innocentive( MySqlConf, 0) #DON'T REMOVE LAST 0 or CHANGE TO 1 if taxon_ids[0] == GET_ALL_TAX: subTaxons = [GET_ALL_TAX] else: #select all taxons under the given taxonomy lists subTaxons = taxon_ids if subTaxF: #build dic of ti nodes in phylogeny if useHash: h_tax_node2par = taxon_rel_in_hash(nodes_fn) else: h_tax_node2par = dbUtils.taxon_rel_in_hash_mysql(con, workD) subTaxons = get_allsub_taxons_phylo(h_tax_node2par, taxon_ids) #append taxonomy id to fasta header if useHash: append_ti_into_fasta_hash(ncbiNt, gi2taxDump, subTaxons, enable_descF, enable_onlineF, valSel, invalSel, invalSelFlag) else: append_ti_into_fasta_mysql(con, ncbiNt, subTaxons, enable_descF, enable_onlineF, valSel, invalSel, invalSelFlag) dbUtils.mysql_close(con) return (valSel, invalSel)
def append_ti_into_fasta_app(ncbiNt, taxon_ids, exclude_taxon_ids, subTaxF, MySqlConf, enable_descF, enable_onlineF, outPrefix, outDir): invalSelFlag = False # Not generating invalid fasta file by default GET_ALL_TAX=-2 NAs='X' (hostname,port,user,passwd,defaultDb)=range(5) useHash=False workD = outDir + os.sep + 'ncbiDB' if not os.path.exists(workD): os.makedirs(workD) valSel = outDir + os.sep + outPrefix+'_ti.fa' invalSel = outDir + os.sep + outPrefix+'_ti_inval.fa' if MySqlConf[passwd]==NAs: #then, we use download gi2tax instead of using mysql query useHash=True gi2taxDump=getGi2TaxDump_online(workD) nodes_fn=getNodesDump_online(workD) if not useHash: con = dbUtils.init_mysql_innocentive(MySqlConf,0) #DON'T REMOVE LAST 0 or CHANGE TO 1 if taxon_ids[0]==GET_ALL_TAX: subTaxons=[GET_ALL_TAX] else: #select all taxons under the given taxonomy lists subTaxons=taxon_ids if subTaxF: #build dic of ti nodes in phylogeny if useHash: h_tax_node2par = taxon_rel_in_hash(nodes_fn) else: h_tax_node2par = dbUtils.taxon_rel_in_hash_mysql(con, workD) subTaxons=get_allsub_taxons_phylo(h_tax_node2par,taxon_ids, exclude_taxon_ids) #append taxonomy id to fasta header if useHash: append_ti_into_fasta_hash(ncbiNt, gi2taxDump, subTaxons, enable_descF, enable_onlineF, valSel, invalSel, invalSelFlag) else: append_ti_into_fasta_mysql(con, ncbiNt, subTaxons, enable_descF, enable_onlineF, valSel, invalSel, invalSelFlag) dbUtils.mysql_close(con) return (valSel,invalSel)