def download(self, genes, fields, scope=None, species=None): ''' Retrives the data depending on self.constraints and self.view ''' constraints = self.constraints views = self.views glist = np.array(genes) if len(glist) > 1000: a = len(glist) / 1000 segs = np.array_split(glist, a) else: segs = [glist] # store the data in here z = [] # API uses letters to distinguish between constraints alpha = list(string.ascii_uppercase) for seg in segs: # Connect to the API service = SS(self.datasource) query = service.new_query("Gene") query.add_view(",".join(views)) # Some databases require a host name if self.hostid != "": query.add_constraint("Gene", "LOOKUP", ",".join(seg), self.hostid, code="A") else: query.add_constraint("Gene", "LOOKUP", ",".join(seg), code="A") # Apply the constraints if len(constraints) != 0: i = 1 for constraint in constraints: letter = alpha[i] if len(constraint.split("=")) == 2: L = constraint.split("=") query.add_constraint(L[0], "=", L[1], code=letter) elif re.search("IS NOT NULL", constraint): p1 = constraint.replace(" IS NOT NULL", "") query.add_constraint(p1, "IS NOT NULL", code=letter) i = i + 1 # Parse the output into a list of tuples j = 0 for row in query.rows(): t = [row['symbol']] for v in views: t.append(row[v]) z.append(tuple(t)) j += 1 self.dataset = z
def test(self): ''' Tests the HumanMine API Look up symbol for APOBEC3G, should return APOBEC3G. ''' service = SS('http://www.humanmine.org/humanmine/service') query = service.new_query("Gene") query.add_view("symbol") query.add_constraint("Gene", "LOOKUP", "APOBEC3G", code="A") for row in query.rows(): symbol = row['symbol'] if symbol == "APOBEC3G": return 1 else: return 0