source: orange/install-scripts/orngServer/serverUpdateScripts/updateKEGG.py @ 10580:c4cbae8dcf8b

Revision 10580:c4cbae8dcf8b, 2.0 KB checked in by markotoplak, 2 years ago (diff)

Moved deprecation functions, progress bar support and environ into Orange.utils. Orange imports cleanly, although it is not tested yet.

Line 
1##!interval=7
2##!contact=ales.erjavec@fri.uni-lj.si
3
4import obiKEGG2, obiGene, obiTaxonomy, obiGeneSets
5import os, sys, tarfile, urllib2, shutil, cPickle
6from getopt import getopt
7
8from Orange.misc import serverfiles
9from Orange.utils import ConsoleProgressBar
10
11DOMAIN = "KEGG"
12
13opt = dict(getopt(sys.argv[1:], "u:p:", ["user=", "password="])[0])
14
15username = opt.get("-u", opt.get("--user", "username"))
16password = opt.get("-p", opt.get("--password", "password"))
17
18sf = serverfiles.ServerFiles(username, password)
19
20genome = obiKEGG2.KEGGGenome()
21common = genome.common_organisms()
22
23rev_taxmap = dict([(v, k) for k, v in genome.TAXID_MAP.items()])
24
25
26for org in common:
27   
28    #####################
29    # Create gene aliases
30    #####################
31   
32#    genes = obiKEGG2.KEGGGenes(org)
33#   
34#    pb = ConsoleProgressBar("Retriving KEGG ids for %r:" % org)
35#    genes.pre_cache(progress_callback=pb.set_state)
36#    aliases = []
37#    for key, entry in genes.iteritems():
38#        aliases.append(set([key]) | set(entry.alt_names))
39#    pb.finish()
40#   
41#    taxid = obiKEGG2.to_taxid(org)
42#    ids_filename = "kegg_gene_id_aliases_" + taxid + ".pickle"
43#    filename = serverfiles.localpath(DOMAIN, ids_filename)
44#   
45#    cPickle.dump(aliases, open(filename, "wb"))
46#   
47#    print "Uploading", ids_filename
48#    sf.upload(DOMAIN, ids_filename, filename,
49#              "KEGG Gene id aliases",
50#              tags=["KEGG", "genes", "aliases",
51#                    "#version:%s" % obiKEGG2.MatcherAliasesKEGG.VERSION
52#                    ],
53#              )
54#    sf.unprotect(DOMAIN, ids_filename)
55   
56    ##########################
57    # Create pathway gene sets
58    ##########################
59   
60    organism = obiKEGG2.KEGGOrganism(org)
61    ge = genome[org]
62   
63    taxid = rev_taxmap.get(ge.taxid, ge.taxid)
64    gene_sets = obiGeneSets.keggGeneSets(taxid)
65   
66    print "Uploading pathway gene sets for", taxid, "(%s)" % org
67    obiGeneSets.register_serverfiles(gene_sets, sf)
68   
Note: See TracBrowser for help on using the repository browser.