def toProtocolElement(self): dataset = protocol.Dataset() dataset.id = self.getId() dataset.name = pb.string(self.getLocalId()) dataset.description = pb.string(self.getDescription()) self.serializeAttributes(dataset) return dataset
def search_datasets(request): """ Mock Function """ dataset_list = [] for i in xrange(10): dataset = protocol.Dataset() dataset.id = str(i) dataset.name = "Hi there" dataset_list.append(dataset) return (dataset_list, "0:0")
def testRoundTripDatasetProtobufString(self): id_ = "id" name = "name" description = "description" dataset = protocol.Dataset() dataset.id = id_ dataset.name = name dataset.description = description pbStr = protocol.toProtobufString(dataset) newDataset = protocol.fromProtobufString(pbStr, Dataset) self.assertEquals(newDataset.id, id_) self.assertEquals(newDataset.name, name) self.assertEquals(newDataset.description, description)
def testRoundTripDataset(self): id_ = "id" name = "name" description = "description" dataset = protocol.Dataset() dataset.id = id_ dataset.name = name dataset.description = description jsonStr = protocol.toJson(dataset) newDataset = protocol.fromJson(jsonStr, Dataset) self.assertEquals(dataset.id, id_) self.assertEquals(dataset.name, name) self.assertEquals(dataset.description, description) datasetDict = protocol.toJsonDict(newDataset) self.assertEquals(datasetDict['id'], id_) self.assertEquals(datasetDict['name'], name) self.assertEquals(datasetDict['description'], description)
def search_datasets(request): # TODO safely cast page token page_size = 100 # Default page size if request.page_size != 0: page_size = request.page_size page_token = 0 if request.page_token != '': page_token = int(request.page_token) offset = page_token * request.page_size esearch_params = { 'db': 'bioproject', 'term': 'all[filter]', 'retmax': page_size, 'retstart': offset } esearch_response = requests.get( "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi", esearch_params) # get IDs ids = [] root = ET.fromstring(esearch_response.text) for id_ in root.findall("./IdList/Id"): ids.append(id_.text) # get summaries esummary_params = {'db': 'bioproject', 'id': ','.join(ids)} esummary_response = requests.get( "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi", params=esummary_params) root = ET.fromstring(esummary_response.text.encode('utf-8')) dataset_list = [] for ds in root.findall("./DocumentSummarySet/DocumentSummary"): dataset = protocol.Dataset() # uid = ds.find('Project_Id').text dataset.id = ds.find('Project_Acc').text # id dataset.name = ds.find('Project_Title').text # name dataset.description = ds.find('Project_Description').text dataset_list.append(dataset) return dataset_list