Changeset 1781:764dc2b10839 in orange-bioinformatics


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

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • _bioinformatics/geneset.py

    r1712 r1781  
    1717            genes = [] 
    1818 
    19         self.hierarchy = hierarchy 
     19        self.hierarchy = hierarchy      
    2020        self.genes = set(genes) 
    2121        self.name = name 
  • _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())     
  • _bioinformatics/obiGeneSets.py

    r1780 r1781  
    6767    from . import obiDictyMutants 
    6868    link_fmt = "http://dictybase.org/db/cgi-bin/dictyBase/SC/scsearch.pl?searchdb=strains&search_term=%s&column=all&B1=Submit"  
    69     genesets = [GeneSet(id=mutant.name, name=mutant.descriptor, genes=obiDictyMutants.mutant_genes(mutant), hierarchy=("Dictybase", ), organism="352472", # 352472 gathered from obiGO.py code_map -> Dicty identifier 
    70                         link=(link_fmt % mutant.name if mutant.name else None)) \ 
    71                         for mutant in obiDictyMutants.mutants()] 
    72     genesets.extend([GeneSet(id=mutant.name, name=mutant.descriptor, genes=obiDictyMutants.mutant_phenotypes(mutant), hierarchy=("Dictybase", "phenotype_mutants"), organism="352472", 
    73                         link=(link_fmt % mutant.name if mutant.name else None)) \ 
    74                         for mutant in obiDictyMutants.mutants()]) 
     69    #genesets = [GeneSet(id=mutant.name, name=mutant.descriptor, genes=obiDictyMutants.mutant_genes(mutant), hierarchy=("Dictybase", ), organism="352472", # 352472 gathered from obiGO.py code_map -> Dicty identifier 
     70    #                    link=(link_fmt % mutant.name if mutant.name else None)) \ 
     71    #                    for mutant in obiDictyMutants.mutants()] 
     72  
     73    genesets = [GeneSet(id=phenotype, name=phenotype, genes=[obiDictyMutants.mutant_genes(mutant)[0] for mutant in mutants], hierarchy=("Dictybase", ), organism="352472", # 352472 gathered from obiGO.py code_map -> Dicty identifier 
     74                        link="") \ 
     75                        for phenotype, mutants in obiDictyMutants.phenotype_mutants().items()] 
    7576 
    7677    return GeneSets(genesets) 
  • server_update/updateDictyBase.py

    r1721 r1781  
    66import tempfile 
    77from Orange.bio.obiDicty import DictyBase 
     8import Orange.bio.obiDictyMutants as DictyMutants 
    89 
    910tmpdir = tempfile.mkdtemp("dictybase") 
    10  
    1111base = DictyBase.pickle_data() 
    1212filename = os.path.join(tmpdir, "tf") 
     
    3131 
    3232shutil.rmtree(tmpdir) 
     33 
     34 
     35""" 
     36Orange server upload for DictyMutants  
     37""" 
     38 
     39tmpdir_mutants = tempfile.mkdtemp("dictymutants") 
     40base_mutants = DictyMutants.download_mutants() 
     41file_mutants = os.path.join(tmpdir_mutants, "tempMut") 
     42 
     43fm = open(file_mutants, "wb") 
     44fm.write(base_mutants) 
     45fm.close() 
     46 
     47fm_dom = DictyMutants.domain 
     48fm_name = DictyMutants.pickle_file 
     49 
     50print file_mutants 
     51 
     52sf_server.upload(fm_dom, fm_name, file_mutants, title="dictyBase mutant collection", 
     53    tags=DictyMutants.tags) 
     54sf_server.unprotect(fm_dom, fm_name) 
     55 
     56shutil.rmtree(tmpdir_mutants) 
     57 
     58""" 
     59Orange server upload for Dicty mutant gene sets 
     60""" 
     61from Orange.bio.obiGeneSets import dictyMutantSets, update_server_list 
     62import cPickle as pickle 
     63 
     64mutant_sets = dictyMutantSets() 
     65 
     66tmpdir_sets = tempfile.mkdtemp("dictygenesets") 
     67file_mutants = os.path.join(tmpdir_sets, "tempSets") 
     68 
     69with open(file_mutants, "wb") as f: 
     70    pickle.dump(mutant_sets, f, -1) 
     71 
     72fm_dom = "gene_sets" 
     73fm_name = "DictyMutant phenotypes" 
     74set_tags = ["Mutant", "phenotype", "dicty"] 
     75 
     76print file_mutants 
     77 
     78sf_server.upload(fm_dom, fm_name, file_mutants, title="Dictyostelium discoideum mutant phenotypes", 
     79    tags=set_tags) 
     80sf_server.unprotect(fm_dom, fm_name) 
     81update_server_list(sf_server) 
     82 
     83shutil.rmtree(tmpdir_sets) 
     84 
Note: See TracChangeset for help on using the changeset viewer.