Commits

Flashpoint  committed 764dc2b

First attempt at configuring Orange server update

  • Participants
  • Parent commits 5cc362d

Comments (0)

Files changed (4)

File _bioinformatics/geneset.py

         if genes == None:
             genes = []
 
-        self.hierarchy = hierarchy
+        self.hierarchy = hierarchy     
         self.genes = set(genes)
         self.name = name
         self.id = id

File _bioinformatics/obiDictyMutants.py

 import os
 import urllib2
 import shutil
-import cPickle as pickle
+import pickle
 
 from collections import defaultdict
 
 from Orange.orng import orngServerFiles
 
+from Orange.utils.serverfiles import localpath_download
+
+domain = "dictybase"
+pickle_file = "mutants.pkl"
+tags = ["Dictyostelium discoideum", "mutant", "dictyBase", "phenotype"]
+
 class DictyMutant(object):
 
     def __init__(self, mutant_line):
  
 class DictyMutants(object):
     VERSION=1
-    DEFAULT_DATABASE_PATH = orngServerFiles.localpath("DictyMutants") #use a default folder for storing the genesets
-
+    DEFAULT_DATABASE_PATH = orngServerFiles.localpath("DictyMutants") #use a default local folder for storing the genesets
+    
     def __init__(self, local_database_path=None):
         self.local_database_path = local_database_path if local_database_path is not None else self.DEFAULT_DATABASE_PATH
-        self.local_pickle_path = os.path.join(self.local_database_path, "Mutants.pkl")
-
+        
         if not os.path.exists(self.local_database_path):
             os.mkdir(self.local_database_path)
             
-        if not os.path.exists(self.local_pickle_path):
-            self.prepare_mutants()
-        else:
-            self._mutants = pickle.load(open(self.local_pickle_path, "rb"))
- 
+        self._mutants = pickle.load(open(localpath_download(domain, pickle_file), "rb"))
+              
     def update_file(self, name):
         url = "http://dictybase.org/db/cgi-bin/dictyBase/download/download.pl?area=mutant_phenotypes&ID="
         filename = os.path.join(self.local_database_path, name)
         data_header = data.readline()
         data = data.read()
         return data.splitlines()
-       
-    def prepare_mutants(self):   
+                 
+    def download_mutants(self):   
         all_mutants = self.load_mutants(self.update_file("all-mutants.txt"))
         null_mutants = self.load_mutants(self.update_file("null-mutants.txt"))
         overexp_mutants = self.load_mutants(self.update_file("overexpression-mutants.txt"))
             if mutant.name in the_develops: mutant.develop = True
             if mutant.name in the_others: mutant.other = True
        
-        self._mutants = {x: x for x in _mutants}
-        pickle.dump(self._mutants, open(self.local_pickle_path, "wb"), -1)
+        final_mutants = {x: x for x in _mutants}
+        return final_mutants
+
+    def pickle_data(self):
+        return pickle.dumps(self.download_mutants(), -1)
 
     @classmethod
     def get_instance(cls):
                 dpm[phenotype].add(mutant)
         return dpm
 
-
 def mutants():
     """ Return all mutant objects
     """
     """
     return DictyMutants.get_instance().phenotype_mutants()
 
+def download_mutants():
+    return DictyMutants.get_instance().pickle_data()
+
 if  __name__  == "__main__":
     print(phenotype_mutants())    

File _bioinformatics/obiGeneSets.py

     """
     from . import obiDictyMutants
     link_fmt = "http://dictybase.org/db/cgi-bin/dictyBase/SC/scsearch.pl?searchdb=strains&search_term=%s&column=all&B1=Submit" 
-    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
-                        link=(link_fmt % mutant.name if mutant.name else None)) \
-                        for mutant in obiDictyMutants.mutants()]
-    genesets.extend([GeneSet(id=mutant.name, name=mutant.descriptor, genes=obiDictyMutants.mutant_phenotypes(mutant), hierarchy=("Dictybase", "phenotype_mutants"), organism="352472",
-                        link=(link_fmt % mutant.name if mutant.name else None)) \
-                        for mutant in obiDictyMutants.mutants()])
+    #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
+    #                    link=(link_fmt % mutant.name if mutant.name else None)) \
+    #                    for mutant in obiDictyMutants.mutants()]
+ 
+    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
+                        link="") \
+                        for phenotype, mutants in obiDictyMutants.phenotype_mutants().items()]
 
     return GeneSets(genesets)
 

File server_update/updateDictyBase.py

 from gzip import GzipFile
 import tempfile
 from Orange.bio.obiDicty import DictyBase
+import Orange.bio.obiDictyMutants as DictyMutants
 
 tmpdir = tempfile.mkdtemp("dictybase")
-
 base = DictyBase.pickle_data()
 filename = os.path.join(tmpdir, "tf")
 
 sf_server.unprotect(dom, fn)
 
 shutil.rmtree(tmpdir)
+
+
+"""
+Orange server upload for DictyMutants 
+"""
+
+tmpdir_mutants = tempfile.mkdtemp("dictymutants")
+base_mutants = DictyMutants.download_mutants()
+file_mutants = os.path.join(tmpdir_mutants, "tempMut")
+
+fm = open(file_mutants, "wb")
+fm.write(base_mutants)
+fm.close()
+
+fm_dom = DictyMutants.domain
+fm_name = DictyMutants.pickle_file
+
+print file_mutants
+
+sf_server.upload(fm_dom, fm_name, file_mutants, title="dictyBase mutant collection",
+    tags=DictyMutants.tags)
+sf_server.unprotect(fm_dom, fm_name)
+
+shutil.rmtree(tmpdir_mutants)
+
+"""
+Orange server upload for Dicty mutant gene sets
+"""
+from Orange.bio.obiGeneSets import dictyMutantSets, update_server_list
+import cPickle as pickle
+
+mutant_sets = dictyMutantSets()
+
+tmpdir_sets = tempfile.mkdtemp("dictygenesets")
+file_mutants = os.path.join(tmpdir_sets, "tempSets")
+
+with open(file_mutants, "wb") as f:
+    pickle.dump(mutant_sets, f, -1)
+
+fm_dom = "gene_sets"
+fm_name = "DictyMutant phenotypes"
+set_tags = ["Mutant", "phenotype", "dicty"]
+
+print file_mutants
+
+sf_server.upload(fm_dom, fm_name, file_mutants, title="Dictyostelium discoideum mutant phenotypes",
+    tags=set_tags)
+sf_server.unprotect(fm_dom, fm_name)
+update_server_list(sf_server)
+
+shutil.rmtree(tmpdir_sets)
+