Changeset 257


Ignore:
Timestamp:
Nov 6, 2009, 7:32:44 AM (10 years ago)
Author:
pvkouteren
Message:
 
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • web/IbidasAtomicServicesTemp.py

    r242 r257  
    150150        return result
    151151   
     152    @soapmethod(Array(Integer), _returns=Array(String))
     153    def getAccessionNames(self, id_list):
     154        """ Get the accession names from an input list of IbidasIDs """
     155        result = []
     156        for identifier in id_list:
     157            i_id = self.cd.item[_.item_id == identifier].select(_.display_name)()
     158            result.append(i_id)
     159        return result
     160   
    152161    @soapmethod(Array(String), _returns=Array(Integer))
    153162    def getIbidasIDs(self, names):
     
    189198        return result
    190199   
    191     @soapmethod(Integer, _returns=Array(String))
     200    @soapmethod(String, _returns=Array(String))
    192201    def getMSigDBCategoryGenes(self, category_id):
    193202        """ Get all genes from a particular MSigDB category """
    194203        result = []
    195         g_res = self.cd.item_prop_term.join(self.cd.item, 'item_id', 'item_id').join(self.cd.term, 'term_id', 'term_id')[_.identifier.like("c"+str(category_id)+":%")].select('display_name')()
    196         return g_res
     204        g_res = self.cd.item_prop_term.join(self.cd.item, 'item_id', 'item_id').join(self.cd.term, 'term_id', 'term_id')[_.identifier == category_id].select('display_name')()
     205        res = set(list(g_res))
     206        print str(res)
     207        return res
    197208 
    198209    """
     
    217228        #print "set_id: " + str(set_id)
    218229        set_ids = self.cd.item_prop_term[_.source_id == set_id].select(_.item_id)().tolist()
    219         h = Hypergeometric(top_ids, back_ids, set_ids)
     230        h = Hypergeometric(top_ids, back_ids, set_ids, True)
    220231        return h.calculate()
    221232   
    222233    @soapmethod(Array(String), Array(String), String, Float, _returns=Array(Integer))
    223     def returnEnrichedGenesByDB(self, top, back, reference, threshold):
     234    def returnEnrichedGeneSetByDB(self, top, back, reference, threshold):
    224235        """ Returns a list of IbidasItem IDs if they are enriched """
    225236        if self.geneEnrichmentTestByDB(top, back, reference, threshold):
     
    227238        else:
    228239            return None
    229    
     240
     241    '''
    230242    @soapmethod(Array(Array(String)), Array(Array(String)), Array(String), Float, _returns=Array(Array(Array(Boolean))))
    231243    def geneEnrichmentTestsByDBs(self, tops, backs, references, threshold):
     
    241253            tbsrs.append(tbrs)
    242254        return tbsrs
    243    
     255    '''
     256   
    244257    """
    245258    By List
     
    262275        ref_ids = self._getItemIDs(reference)
    263276        print "ref_ids: " + str(ref_ids)
    264         h = Hypergeometric(top_ids, back_ids, ref_ids)
     277        h = Hypergeometric(top_ids, back_ids, ref_ids, True)
    265278        return h.calculate()
    266        
     279     
     280    '''   
    267281    @soapmethod(Array(Array(String)), Array(Array(String)), Array(Array(String)), Float, _returns=Array(Array(Array(Boolean))))
    268282    def geneEnrichmentTestsByLists(self, tops, backs, references, threshold):
     
    278292            tbsrs.append(tbrs)
    279293        return tbsrs
     294    '''
    280295             
    281296    @soapmethod(Array(String), Array(String), Array(String), Float, _returns=Array(Integer))
    282     def returnEnrichedGenesByList(self, top, back, reference, threshold):
     297    def returnEnrichedGeneSetByList(self, top, back, reference, threshold):
    283298        """ Returns a list of IbidasItem IDs if they are enriched """
    284299        if self.geneEnrichmentTestByList(top, back, reference, threshold):
    285300            return self.getIbidasIDs(top)
    286301        else:
    287             return None
    288        
    289        
     302            return None   
    290303       
    291304       
     
    392405            return list(set(res))
    393406   
     407    @soapmethod(Array(String), _returns=Array(String))
     408    def getTranscriptionFactorsOfGenes(self, genes):
     409        """ Return the transcription factors for a list of genes """
     410        result = []
     411        t_res = []
     412        for g in genes:
     413            g_res = self.getTranscriptionFactorsOfGene(g)
     414            for g_r in g_res:
     415                if not g_r in result:
     416                    result.append(g_r)
     417        return result
     418        '''
     419        for t in t_res:
     420            if not t in result:
     421                result.append(t)
     422        return result
     423        '''
     424   
    394425    @soapmethod(String, _returns=Array(String))
    395426    def getTranscriptionFactorsOfGene(self, gene):
     
    402433        # Get the gene identifiers
    403434        gene_ids = self.getTransfacGeneID(gene)
    404         print "gene_ids: " + str(gene_ids)
     435        #print "gene_ids: " + str(gene_ids)
    405436        # Get the bindingsites of this gene
    406437        bindingsite_ids = self._getGeneBindingsites(gene_ids)
    407         print "bindingsite_ids: " + str(bindingsite_ids)
     438        #print "bindingsite_ids: " + str(bindingsite_ids)
    408439        # Get TFs binding to this bindingsite
    409440        binding_tf_ids = self._getBindingTFs(bindingsite_ids)
    410         print "binding_tf_ids: " + str(binding_tf_ids)
     441        #print "binding_tf_ids: " + str(binding_tf_ids)
    411442        # Get genes these TFs encode for
    412443        res_gene_ids = self._getEncodingGenes(binding_tf_ids)
    413         print "res_gene_ids: " + str(res_gene_ids)
     444        #print "res_gene_ids: " + str(res_gene_ids)
    414445        # Get the gene accessions
    415446        res_gene_acc = self._getTransfacGeneAccessions(res_gene_ids)
     447        print "gene: " + str(gene)
    416448        print "res_gene_acc: " + str(res_gene_acc)
    417449        return res_gene_acc
    418450       
     451    @soapmethod(Array(Array(String)), _returns=Array(Array(String)))
     452    def getTransfacSequencesFromAccessionlists(self, acs_lists):
     453        """ Returns the sequences of transcription factors according to their accession """
     454        print "getTransfacSequencesFromAccessionlists"
     455        result = []
     456        for acs_list in acs_lists:
     457            print "Accession list:"
     458            print str(acs_list)
     459            print "----"
     460            res = self.getTransfacSequencesFromAccessions(acs_list)
     461            result.append(res)
     462        return result
     463       
     464    @soapmethod(Array(String), _returns=Array(String))
     465    def getTransfacSequencesFromAccessions(self, acs):
     466        """ Returns the sequences of transcription factors according to their accession """
     467        self._loadTransfac()
     468        tf = self.transfac['factor']
     469        f_ids = tf.accessions[_.accession.within(*acs)].select('ac_id')().tolist()
     470        if isinstance(f_ids, basestring):
     471            fids = [f_ids]
     472        else:
     473            fids = list(set(f_ids))
     474        res = tf.sequences[_.TF_id.within(*fids)].select('sequence')().tolist()
     475        if isinstance(res, basestring):
     476            return [res]
     477        else:
     478            return list(set(res))
     479       
     480       
     481    @soapmethod(Integer, _returns=Array(String))
     482    def getRandomItems(self, amount):
     483        """ Return a random itemset of the input size """
     484        import random
     485        returnlist = []
     486        while len(returnlist) < amount:
     487            i_id = random.randint(1,len(self.cd.item))
     488            item_name = self.cd.item[_.item_id == i_id].select('display_name')()
     489            if not '~withdrawn' in item_name:
     490                returnlist.append(item_name)
     491        return returnlist
     492           
Note: See TracChangeset for help on using the changeset viewer.