source: orange-bioinformatics/server_update/updateMeSH.py @ 1719:6e8861564778

Revision 1719:6e8861564778, 1.8 KB checked in by markotoplak, 20 months ago (diff)

Fixed update scripts for MeSH, GO, HomoloGene, NCBI_geneinfo, OMIM, PPI. Moved wget to Orange.utils.

Line 
1##!interval=7
2##!contact=ales.erjavec@fri.uni-lj.si
3
4from urllib import urlopen
5import Orange.utils.serverfiles as orngServerFiles
6import os, sys
7
8from getopt import getopt
9
10opt = dict(getopt(sys.argv[1:], "u:p:", ["user=", "password="])[0])
11
12username = opt.get("-u", opt.get("--user", "username"))
13password = opt.get("-p", opt.get("--password", "password"))
14
15
16ontology = urlopen("ftp://nlmpubs.nlm.nih.gov/online/mesh/.asciimesh/d2012.bin")
17size = int(ontology.info().getheader("Content-Length"))
18rsize = 0
19results = list()
20for i in ontology:
21    rsize += len(i)
22    line = i.rstrip("\t\n")
23    if(line == "*NEWRECORD"):
24        if(len(results) > 0 and results[-1][1] == []): # we skip nodes with missing mesh id
25            results[-1] = ["",[],"No description."]
26        else:
27            results.append(["",[],"No description."])   
28    parts = line.split(" = ")
29    if(len(parts) == 2 and len(results)>0):
30        if(parts[0] == "MH"):
31            results[-1][0] = parts[1].strip("\t ") 
32
33        if(parts[0] == "MN"):
34            results[-1][1].append(parts[1].strip("\t "))
35        if(parts[0] == "MS"):
36            results[-1][2] = parts[1].strip("\t ")
37ontology.close()
38
39output = file('mesh-ontology.dat', 'w')
40
41for i in results:
42    print i[0] + "\t"
43    output.write(i[0] + "\t")
44    g=len(i[1])         
45    for k in i[1]:
46        g -= 1
47        if(g > 0):
48            output.write(k + ";")
49        else:
50            output.write(k + "\t" + i[2] + "\n")
51output.close()
52print "Ontology downloaded."
53
54
55
56
57ordinary = orngServerFiles.ServerFiles()
58authenticated = orngServerFiles.ServerFiles(username, password)
59
60authenticated.upload('MeSH', 'mesh-ontology.dat', 'mesh-ontology.dat', title="MeSH ontology", tags=['MeSH', 'ontology', 'orngMeSH'])
61#authenticated.upload('MeSH', 'cid-annotation.dat', 'cid-annotation.dat', title="Annotation for chemicals (CIDs)", tags =['CID','MeSH','orngMeSH','annotation'])
62
63authenticated.unprotect('MeSH', 'mesh-ontology.dat')
64os.remove('mesh-ontology.dat')
65print "Ontology uploaded to server."
Note: See TracBrowser for help on using the repository browser.