Changeset 1781:764dc2b10839 in orange-bioinformatics for _bioinformatics/obiDictyMutants.py


Ignore:
Timestamp:
05/10/13 15:19:06 (12 months ago)
Author:
Flashpoint <vid.flashpoint@…>
Branch:
default
Message:

First attempt at configuring Orange server update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • _bioinformatics/obiDictyMutants.py

    r1780 r1781  
    22import urllib2 
    33import shutil 
    4 import cPickle as pickle 
     4import pickle 
    55 
    66from collections import defaultdict 
    77 
    88from Orange.orng import orngServerFiles 
     9 
     10from Orange.utils.serverfiles import localpath_download 
     11 
     12domain = "dictybase" 
     13pickle_file = "mutants.pkl" 
     14tags = ["Dictyostelium discoideum", "mutant", "dictyBase", "phenotype"] 
    915 
    1016class DictyMutant(object): 
     
    2430class DictyMutants(object): 
    2531    VERSION=1 
    26     DEFAULT_DATABASE_PATH = orngServerFiles.localpath("DictyMutants") #use a default folder for storing the genesets 
    27  
     32    DEFAULT_DATABASE_PATH = orngServerFiles.localpath("DictyMutants") #use a default local folder for storing the genesets 
     33     
    2834    def __init__(self, local_database_path=None): 
    2935        self.local_database_path = local_database_path if local_database_path is not None else self.DEFAULT_DATABASE_PATH 
    30         self.local_pickle_path = os.path.join(self.local_database_path, "Mutants.pkl") 
    31  
     36         
    3237        if not os.path.exists(self.local_database_path): 
    3338            os.mkdir(self.local_database_path) 
    3439             
    35         if not os.path.exists(self.local_pickle_path): 
    36             self.prepare_mutants() 
    37         else: 
    38             self._mutants = pickle.load(open(self.local_pickle_path, "rb")) 
    39   
     40        self._mutants = pickle.load(open(localpath_download(domain, pickle_file), "rb")) 
     41               
    4042    def update_file(self, name): 
    4143        url = "http://dictybase.org/db/cgi-bin/dictyBase/download/download.pl?area=mutant_phenotypes&ID=" 
     
    5557        data = data.read() 
    5658        return data.splitlines() 
    57         
    58     def prepare_mutants(self):    
     59                  
     60    def download_mutants(self):    
    5961        all_mutants = self.load_mutants(self.update_file("all-mutants.txt")) 
    6062        null_mutants = self.load_mutants(self.update_file("null-mutants.txt")) 
     
    7981            if mutant.name in the_others: mutant.other = True 
    8082        
    81         self._mutants = {x: x for x in _mutants} 
    82         pickle.dump(self._mutants, open(self.local_pickle_path, "wb"), -1) 
     83        final_mutants = {x: x for x in _mutants} 
     84        return final_mutants 
     85 
     86    def pickle_data(self): 
     87        return pickle.dumps(self.download_mutants(), -1) 
    8388 
    8489    @classmethod 
     
    117122        return dpm 
    118123 
    119  
    120124def mutants(): 
    121125    """ Return all mutant objects 
     
    148152    return DictyMutants.get_instance().phenotype_mutants() 
    149153 
     154def download_mutants(): 
     155    return DictyMutants.get_instance().pickle_data() 
     156 
    150157if  __name__  == "__main__": 
    151158    print(phenotype_mutants())     
Note: See TracChangeset for help on using the changeset viewer.