source: orange/install-scripts/orngServer/serverUpdateScripts/updateKEGG.py @ 9634:af72f198600b

Revision 9634:af72f198600b, 1.9 KB checked in by ales_erjavec, 2 years ago (diff)

Update script using new kegg module.

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