当前位置: 首页>>代码示例>>Python>>正文


Python Client.translateAll方法代码示例

本文整理汇总了Python中Client.Client.translateAll方法的典型用法代码示例。如果您正苦于以下问题:Python Client.translateAll方法的具体用法?Python Client.translateAll怎么用?Python Client.translateAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Client.Client的用法示例。


在下文中一共展示了Client.translateAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import translateAll [as 别名]
class ext:
    """
    These are some helper extensions pretty specific to 
    what I have been working on.
    May be useful to someone else? Maybe not.
    """
    def __init__(self, cache_dir='data', base_url="http://babel.gdxbase.org/cgi-bin/translate.cgi"):
        
        self.client = Client(base_url)
        self.cache_dir = cache_dir

    def mergeProbes(self, idLists):
        """
        Returns a list of 2-tuples (i,j) where i is the index in ids1 that matches ids2 
        """
        #figure out what type of data
        idtypes =[self.discoverID(idList, self._getProbeTypes())  for idList in idLists]
        for i, idtype in enumerate(idtypes):
            if idtype == None:
                raise pyBabelError("id " + str(i) + " undefined.")
        #get the type map table
        typeMap = self.getMap(idtypes)
        #build dicts from idname->indx
        indxMaps = [self._buildIndexMap(idList) for idList in idLists]
        #we only want unique mappings
        merged = {}
        for row in typeMap:
            entrez = row[-1]
            if entrez != None:
                good = True
                for i, column in enumerate(row[:-1]):
                    if column not in indxMaps[i]:
                        good = False
                if good:
                    merged[tuple(row[:-1])] = 1
        return merged.keys()

    def getControls(self, ids):
        """
        returns a list of indices that are controls
        #have no gene entrez_id
        """
        pass #no idea if this is working or not.
        idtype = self.discoverID(ids, self._getProbeTypes())
        if idtype == None:
            raise pyBabelError("ids undefined")

        map = self.getAllTable(idtype, idtype)
        #print self.prettyPrint(map)
        indxMap = self._buildIndexMap(ids)
        res = []
        for i, _ , entrez in map:
             if entrez == None and i in indxMap:
                res.append(i)
        return res
        
        
        

    def discoverID(self, ids, base_idTypes, numIDs=10):
        """
        Given a subset of base_idTypes check which 
        id type a set of ids come from
        """
        for idtype in base_idTypes:
            if len(self.client.translate(input_type=idtype, input_ids=ids[:numIDs],output_types=[idtype]) ) > 0:
                return idtype
        return None

    def getAllTable(self, idtypes):
    
        input_type = idtypes[0]
        output_type = idtypes[1:]
        output_type.append('gene_entrez') #for control filtering
        return self.client.translateAll(input_type=input_type, output_types=output_type)
            
    def _getProbeTypes(self):
        """
        returns a list of valid idtypes that have the word 'probe' in them
        """
        p = re.compile('probe')
        return [x for x in self.client.getIDTypes() if p.search(x)]

    def prettyPrint(self, table):
        """
        Little helper function that takes a table and returns a print friendly
        string.
        """ 
        return '\n'.join(['\t'.join([str(val) for val in row]) for row in table])
    def getMap(self, idtypes, usePickle=True):
        """
        """
        #look for pickle
        if usePickle:
            p = self._getPickle(idtypes)
        else:
            p = None

        if p == None:#not kosher
            map = self.getAllTable(idtypes)
#.........这里部分代码省略.........
开发者ID:phonybone,项目名称:Babel-Webservice,代码行数:103,代码来源:Extensions.py


注:本文中的Client.Client.translateAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。