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

Revision 1721:921b3780c6cc, 1.5 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
2##!contact=ales.erjavec@fri.uni-lj.si
3
4from common import *
5from urllib import urlopen
6
7ontology = urlopen("ftp://nlmpubs.nlm.nih.gov/online/mesh/.asciimesh/d2012.bin")
8size = int(ontology.info().getheader("Content-Length"))
9rsize = 0
10results = list()
11for i in ontology:
12    rsize += len(i)
13    line = i.rstrip("\t\n")
14    if(line == "*NEWRECORD"):
15        if(len(results) > 0 and results[-1][1] == []): # we skip nodes with missing mesh id
16            results[-1] = ["",[],"No description."]
17        else:
18            results.append(["",[],"No description."])   
19    parts = line.split(" = ")
20    if(len(parts) == 2 and len(results)>0):
21        if(parts[0] == "MH"):
22            results[-1][0] = parts[1].strip("\t ") 
23
24        if(parts[0] == "MN"):
25            results[-1][1].append(parts[1].strip("\t "))
26        if(parts[0] == "MS"):
27            results[-1][2] = parts[1].strip("\t ")
28ontology.close()
29
30output = file('mesh-ontology.dat', 'w')
31
32for i in results:
33    print i[0] + "\t"
34    output.write(i[0] + "\t")
35    g=len(i[1])         
36    for k in i[1]:
37        g -= 1
38        if(g > 0):
39            output.write(k + ";")
40        else:
41            output.write(k + "\t" + i[2] + "\n")
42output.close()
43print "Ontology downloaded."
44
45sf_server.upload('MeSH', 'mesh-ontology.dat', 'mesh-ontology.dat', title="MeSH ontology", tags=['MeSH', 'ontology', 'orngMeSH'])
46#authenticated.upload('MeSH', 'cid-annotation.dat', 'cid-annotation.dat', title="Annotation for chemicals (CIDs)", tags =['CID','MeSH','orngMeSH','annotation'])
47
48sf_server.unprotect('MeSH', 'mesh-ontology.dat')
49os.remove('mesh-ontology.dat')
50print "Ontology uploaded to server."
Note: See TracBrowser for help on using the repository browser.