def test_range_operator_with_entry_return(self, mock_post): # Creates a mock HTTP response, as wrapped by `requests` canned_json_return_as_dict = { "result_set": [{ "identifier": "5JUP" }, { "identifier": "5JUS" }, { "identifier": "5JUO" }] } mock_response = mock.create_autospec(requests.Response, instance=True) mock_response.json.return_value = canned_json_return_as_dict mock_post.return_value = mock_response search_operator = text_operators.RangeOperator( from_value="2019-01-01T00:00:00Z", to_value="2019-06-30T00:00:00Z", include_lower=False, include_upper=True, attribute="rcsb_accession_info.initial_release_date") return_type = search_client.ReturnType.ENTRY results = search_client.perform_search(search_operator, return_type) expected_json_dict = { "query": { "type": "terminal", "service": "text", "parameters": { "operator": "range", "attribute": "rcsb_accession_info.initial_release_date", "value": { "from": "2019-01-01T00:00:00Z", "to": "2019-06-30T00:00:00Z", "include_lower": False, "include_upper": True } } }, "request_options": { "return_all_hits": True }, "return_type": "entry" } mock_post.assert_called_once_with( url=search_client.SEARCH_URL_ENDPOINT, data=json.dumps(expected_json_dict)) self.assertEqual(results, ["5JUP", "5JUS", "5JUO"])
def test_query_structure_resolution(self, mock_post): # Creates a mock HTTP response, as wrapped by `requests` canned_json_return_as_dict = { "result_set": [{ "identifier": "5JUP" }, { "identifier": "5JUS" }, { "identifier": "5JUO" }] } mock_response = mock.create_autospec(requests.Response, instance=True) mock_response.json.return_value = canned_json_return_as_dict mock_post.return_value = mock_response search_operator = text_operators.ComparisonOperator( value=4, attribute="rcsb_entry_info.resolution_combined", comparison_type=text_operators.ComparisonType.LESS) return_type = search_client.ReturnType.ENTRY results = search_client.perform_search(search_operator, return_type, return_raw_json_dict=True) expected_json_dict = { "query": { "type": "terminal", "service": "text", "parameters": { "operator": "less", "attribute": "rcsb_entry_info.resolution_combined", "value": 4 } }, "request_options": { "return_all_hits": True }, "return_type": "entry" } mock_post.assert_called_once_with( url=search_client.SEARCH_URL_ENDPOINT, data=json.dumps(expected_json_dict)) self.assertEqual(results, canned_json_return_as_dict)
def test_sequence_operator_search(self, mock_post): # Creates a mock HTTP response, as wrapped by `requests` canned_json_return_as_dict = { "result_set": [{ "identifier": "5JUP" }, { "identifier": "5JUS" }, { "identifier": "5JUO" }] } mock_response = mock.create_autospec(requests.Response, instance=True) mock_response.json.return_value = canned_json_return_as_dict mock_post.return_value = mock_response results = search_client.perform_search( search_operator=sequence_operators.SequenceOperator( sequence="ATGAGGTAA", sequence_type=sequence_operators.SequenceType.DNA, evalue_cutoff=100, identity_cutoff=0.90), return_type=search_client.ReturnType.ENTRY) expected_json_dict = { 'query': { 'type': 'terminal', 'service': 'sequence', 'parameters': { 'evalue_cutoff': 100, 'identity_cutoff': 0.90, 'target': 'pdb_dna_sequence', 'value': 'ATGAGGTAA' } }, 'request_options': { 'return_all_hits': True }, 'return_type': 'entry' } mock_post.assert_called_once_with( url=search_client.SEARCH_URL_ENDPOINT, data=json.dumps(expected_json_dict)) self.assertEqual(results, ["5JUP", "5JUS", "5JUO"])
def fetch(self): if self.dict_cond['type'] == ['protein']: search_operator = text_operators.ComparisonOperator( attribute="rcsb_entry_info.assembly_count", value=2, comparison_type=text_operators.ComparisonType.EQUAL) return_type = ReturnType.ENTRY self.allpdbs = perform_search(search_operator, return_type) else: self.allpdbs = self.get_all_pdb(self.start, self.size) print('PDBselect -> %d pdb retreived from the database' % len(self.allpdbs)) if 1: if self.nproc == 1: self.results['ids'] = self.process_pdb(self.allpdbs) else: print('PDBselect -> Processing the files on %d procs' % self.nproc) pool = multiprocessing.Pool(self.nproc) part_process = partial(self._select_pdb, dict_cond=self.dict_cond) if self.tqdm: self.results['ids'] = list( tqdm(pool.imap(part_process, self.allpdbs), total=len(self.allpdbs))) else: self.results['ids'] = pool.map(part_process, self.allpdbs) # remove the Nones self.results['ids'] = list(filter(None, self.results['ids'])) # save results print('PDBselect -> %04d complexes found' % (len(self.results['ids']))) print('PDBselect -> Saving results in :', self.outfile) self.save_hdf5()
def test_in_operator_with_non_polymer_return(self, mock_post): # Creates a mock HTTP response, as wrapped by `requests` canned_json_return_as_dict = { "result_set": [{ "identifier": "5JUP" }, { "identifier": "5JUS" }, { "identifier": "5JUO" }] } mock_response = mock.create_autospec(requests.Response, instance=True) mock_response.json.return_value = canned_json_return_as_dict mock_post.return_value = mock_response search_operator = text_operators.InOperator( values=["Mus musculus", "H**o sapiens"], attribute="rcsb_entity_source_organism.taxonomy_lineage.name") return_type = search_client.ReturnType.NON_POLYMER_ENTITY results = search_client.perform_search(search_operator, return_type) expected_json_dict = { 'query': { 'type': 'terminal', 'service': 'text', 'parameters': { 'attribute': 'rcsb_entity_source_organism.taxonomy_lineage.name', 'operator': 'in', 'value': ['Mus musculus', 'H**o sapiens'] } }, 'request_options': { 'return_all_hits': True }, 'return_type': 'non_polymer_entity' } mock_post.assert_called_once_with( url=search_client.SEARCH_URL_ENDPOINT, data=json.dumps(expected_json_dict)) self.assertEqual(results, ["5JUP", "5JUS", "5JUO"])
def test_comparison_operator_with_entry_return(self, mock_post): # Creates a mock HTTP response, as wrapped by `requests` canned_json_return_as_dict = { "result_set": [{ "identifier": "5JUP" }, { "identifier": "5JUS" }, { "identifier": "5JUO" }] } mock_response = mock.create_autospec(requests.Response, instance=True) mock_response.json.return_value = canned_json_return_as_dict mock_post.return_value = mock_response search_operator = text_operators.ComparisonOperator( value="2019-01-01T00:00:00Z", attribute="rcsb_accession_info.initial_release_date", comparison_type=text_operators.ComparisonType.GREATER) return_type = search_client.ReturnType.ENTRY results = search_client.perform_search(search_operator, return_type) expected_json_dict = { 'query': { 'type': 'terminal', 'service': 'text', 'parameters': { 'operator': 'greater', 'attribute': 'rcsb_accession_info.initial_release_date', 'value': '2019-01-01T00:00:00Z' } }, 'request_options': { 'return_all_hits': True }, 'return_type': 'entry' } mock_post.assert_called_once_with( url=search_client.SEARCH_URL_ENDPOINT, data=json.dumps(expected_json_dict)) self.assertEqual(results, ["5JUP", "5JUS", "5JUO"])
def test_exists_operator_with_entry_raw_json_response(self, mock_post): # Creates a mock HTTP response, as wrapped by `requests` canned_json_return_as_dict = { "result_set": [{ "identifier": "5JUP" }, { "identifier": "5JUS" }, { "identifier": "5JUO" }] } mock_response = mock.create_autospec(requests.Response, instance=True) mock_response.json.return_value = canned_json_return_as_dict mock_post.return_value = mock_response search_operator = text_operators.ExistsOperator( attribute="rcsb_accession_info.initial_release_date") return_type = search_client.ReturnType.ENTRY results = search_client.perform_search(search_operator, return_type, return_raw_json_dict=True) expected_json_dict = { "query": { "type": "terminal", "service": "text", "parameters": { "operator": "exists", "attribute": "rcsb_accession_info.initial_release_date", } }, "request_options": { "return_all_hits": True }, "return_type": "entry" } mock_post.assert_called_once_with( url=search_client.SEARCH_URL_ENDPOINT, data=json.dumps(expected_json_dict)) self.assertEqual(results, canned_json_return_as_dict)
def test_contains_words_operator_with_polymer_instance_return( self, mock_post): # Creates a mock HTTP response, as wrapped by `requests` canned_json_return_as_dict = { "result_set": [{ "identifier": "5JUP" }, { "identifier": "5JUS" }, { "identifier": "5JUO" }] } mock_response = mock.create_autospec(requests.Response, instance=True) mock_response.json.return_value = canned_json_return_as_dict mock_post.return_value = mock_response search_operator = text_operators.ContainsWordsOperator( value="actin-binding protein", attribute="struct.title") return_type = search_client.ReturnType.POLYMER_INSTANCE results = search_client.perform_search(search_operator, return_type) expected_json_dict = { 'query': { 'type': 'terminal', 'service': 'text', 'parameters': { 'attribute': 'struct.title', 'operator': 'contains_words', 'value': 'actin-binding protein' } }, 'request_options': { 'return_all_hits': True }, 'return_type': 'polymer_instance' } mock_post.assert_called_once_with( url=search_client.SEARCH_URL_ENDPOINT, data=json.dumps(expected_json_dict)) self.assertEqual(results, ["5JUP", "5JUS", "5JUO"])
def test_default_operator_with_entry_return_value(self, mock_post): # Creates a mock HTTP response, as wrapped by `requests` canned_json_return_as_dict = { "result_set": [{ "identifier": "5JUP" }, { "identifier": "5JUS" }, { "identifier": "5JUO" }] } mock_response = mock.create_autospec(requests.Response, instance=True) mock_response.json.return_value = canned_json_return_as_dict mock_post.return_value = mock_response search_operator = text_operators.DefaultOperator(value="ribosome") return_type = search_client.ReturnType.ENTRY results = search_client.perform_search(search_operator, return_type) expected_json_dict = { 'query': { 'type': 'terminal', 'service': 'text', 'parameters': { 'value': 'ribosome' } }, 'request_options': { 'return_all_hits': True }, 'return_type': 'entry' } mock_post.assert_called_once_with( url=search_client.SEARCH_URL_ENDPOINT, data=json.dumps(expected_json_dict)) self.assertEqual(results, ["5JUP", "5JUS", "5JUO"])