source: orange-bioinformatics/server_update/updateNCBI_geneinfo.py @ 1717:b9f395780e75

Revision 1717:b9f395780e75, 2.4 KB checked in by markotoplak, 20 months ago (diff)

Copied server update scripts from Orange source.

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