Changeset 1796:a8618bd60eb7 in orange-bioinformatics for _bioinformatics/obiOMIM.py


Ignore:
Timestamp:
05/21/13 09:30:58 (11 months ago)
Author:
Flashpoint <vid.flashpoint@…>
Branch:
default
Parents:
1795:663192bd4469 (diff), 1784:6a26e5172130 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged obiOMIM.py latest commit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • _bioinformatics/obiOMIM.py

    r1784 r1796  
    33import shutil 
    44import re 
    5 import Orange 
    65 
    76from collections import defaultdict 
     7 
     8from Orange.orng import orngServerFiles 
    89 
    910class disease(object): 
     
    1516        string = morbidmap_line.split("|", 1)[0] 
    1617        match = self.regex.match(string) 
    17 #        print string 
    18 #        print match.groups() 
     18        print string 
     19        print match.groups() 
    1920        self.name, self.id, self.mapping = [s.strip() if s else s for s in match.groups()[:3]] 
    2021        if match.group("m2"): 
     
    2324class OMIM(object): 
    2425    VERSION = 1 
    25     DEFAULT_DATABASE_PATH = Orange.utils.serverfiles.localpath("OMIM") 
     26    DEFAULT_DATABASE_PATH = orngServerFiles.localpath("OMIM") 
    2627    def __init__(self, local_database_path=None): 
    2728        self.local_database_path = local_database_path if local_database_path is not None else self.DEFAULT_DATABASE_PATH 
    2829         
    29         if self.local_database_path == self.DEFAULT_DATABASE_PATH: 
    30             filename = Orange.utils.serverfiles.localpath_download("OMIM", "morbidmap") 
    31         else: 
    32             filename = os.path.join(self.local_database_path, "morbidmap") 
    33  
     30        if not os.path.exists(self.local_database_path): 
     31            os.makedirs(self.local_database_path) 
     32             
     33        filename = os.path.join(self.local_database_path, "morbidmap") 
     34        print filename 
     35        if not os.path.exists(filename): 
     36            stream = urllib2.urlopen("ftp://ftp.ncbi.nih.gov/repository/OMIM/ARCHIVE/morbidmap") 
     37            with open(filename, "wb") as file: 
     38                shutil.copyfileobj(stream, file, length=10) 
     39             
     40             
    3441        self.load(filename) 
    3542     
    3643    @classmethod 
    3744    def download_from_NCBI(cls, file=None): 
    38         if isinstance(file, basestring): 
     45        data = urllib2.urlopen("ftp://ftp.ncbi.nih.gov/repository/OMIM/ARCHIVE/morbidmap").read() 
     46        if file is None: 
     47            if not os.path.exists(cls.DEFAULT_DATABASE_PATH): 
     48                os.mkdir(cls.DEFAULT_DATABASE_PATH) 
     49            file = open(os.path.join(cls.DEFAULT_DATABASE_PATH, "morbidmap"), "wb") 
     50        elif isinstance(file, basestring): 
    3951            file = open(file, "wb") 
    40         stream = urllib2.urlopen("ftp://ftp.ncbi.nih.gov/repository/OMIM/ARCHIVE/morbidmap") 
    41         shutil.copyfileobj(stream, file, length=10) 
     52        file.write(data) 
    4253        file.close() 
    4354         
     
    91102    """ 
    92103    return OMIM.get_instance().gene_diseases() 
     104 
     105if __name__ == "__main__": 
     106    print genes() 
Note: See TracChangeset for help on using the changeset viewer.