source: orange-bioinformatics/server_update/updateNCBI_geneinfo.py @ 1721:921b3780c6cc

Revision 1721:921b3780c6cc, 2.1 KB checked in by markotoplak, 19 months ago (diff)

Moved common functionality of the server files update scripts to a separate file.

Line 
1##interval:7
2from common import *
3from Orange.bio import obiGene, obiTaxonomy
4from gzip import GzipFile
5
6tmpdir = os.path.join(environ.buffer_dir, "tmp_NCBIGene_info")
7try:
8    os.mkdir(tmpdir)
9except Exception, ex:
10    pass
11
12gene_info_filename = os.path.join(tmpdir, "gene_info")
13gene_history_filename = os.path.join(tmpdir, "gene_history")
14
15obiGene.NCBIGeneInfo.get_geneinfo_from_ncbi(gene_info_filename)
16obiGene.NCBIGeneInfo.get_gene_history_from_ncbi(gene_history_filename)
17
18info = open(gene_info_filename, "rb")
19hist = open(gene_history_filename, "rb")
20
21taxids = obiGene.NCBIGeneInfo.common_taxids()
22essential = obiGene.NCBIGeneInfo.essential_taxids()
23
24genes = dict([(taxid, []) for taxid in taxids])
25for gi in info:
26    if any(gi.startswith(id + "\t") for id in taxids):
27        genes[gi.split("\t", 1)[0]].append(gi.strip())
28
29history = dict([(taxid, []) for taxid in taxids])
30for hi in hist:
31    if any(hi.startswith(id + "\t") for id in taxids): 
32        history[hi.split("\t", 1)[0]].append(hi.strip())
33
34for taxid, genes in genes.items():
35    filename = os.path.join(tmpdir, "gene_info.%s.db" % taxid)
36    f = open(filename, "wb")
37    f.write("\n".join(genes))
38    f.flush()
39    f.close()
40    print "Uploading", filename
41    sf_server.upload("NCBI_geneinfo", "gene_info.%s.db" % taxid, filename,
42              title = "NCBI gene info for %s" % obiTaxonomy.name(taxid),
43              tags = ["NCBI", "gene info", "gene_names", obiTaxonomy.name(taxid)] + (["essential"] if taxid in essential else []))
44    sf_server.unprotect("NCBI_geneinfo", "gene_info.%s.db" % taxid)
45   
46    filename = os.path.join(tmpdir, "gene_history.%s.db" % taxid)
47    f = open(filename, "wb")
48    f.write("\n".join(history.get(taxid, "")))
49    f.flush()
50    f.close()
51    print "Uploading", filename
52    sf_server.upload("NCBI_geneinfo", "gene_history.%s.db" % taxid, filename,
53              title = "NCBI gene history for %s" % obiTaxonomy.name(taxid),
54              tags = ["NCBI", "gene info", "history", "gene_names", obiTaxonomy.name(taxid)] + (["essential"] if taxid in essential else []))
55    sf_server.unprotect("NCBI_geneinfo", "gene_history.%s.db" % taxid)
Note: See TracBrowser for help on using the repository browser.