def _get_storage(self): """ Returns the current connection to the reactome storage :return: A ReactomeStorage object """ if not self._storage: try: self._storage = reactome_storage.ReactomeStorage() except Exception as e: LOGGER.error("Failed to connect to storage service: " + str(e)) raise Exception("Failed to connect to storage service", e) return self._storage
def test_fetch_sc_expression_atlas(self): dataset_id = "E-MTAB-7078" k = "3" resource_id = "ebi_sc_gxa" loading_id = "loading_sc_gxa_1" # set the data directory os.environ["EXAMPLE_DIRECTORY"] = os.path.join( os.path.dirname(__file__), "testfiles") fetcher = reactome_analysis_dataset_fetcher.ReactomeAnalysisDatasetFetcher( ) # post one analysis request mq = reactome_mq.ReactomeMQ(queue_name=reactome_mq.DATASET_QUEUE) storage = reactome_storage.ReactomeStorage() mq.post_analysis(models.dataset_request.DatasetRequest( loading_id=loading_id, resource_id=resource_id, parameters=[ models.dataset_request.DatasetRequestParameter( name="dataset_id", value=dataset_id), models.dataset_request.DatasetRequestParameter(name="k", value=k) ]).to_json(), method="test") # process the message fetcher.process_single_message() # make sure the status is complete status = storage.get_status(analysis_identifier=loading_id, data_type="dataset") self.assertIsNotNone(status) status_obj = json.loads(status) self.assertEqual("complete", status_obj["status"]) dataset_id = status_obj["dataset_id"] # get the summary summary_string = storage.get_request_data_summary(dataset_id) self.assertIsNotNone(summary_string) # get the data data_string = storage.get_request_data(dataset_id) self.assertIsNotNone(data_string)
def test_fetch_proteomics(self): os.environ["EXAMPLE_DIRECTORY"] = os.path.join( os.path.dirname(__file__), "../example_datasets") fetcher = reactome_analysis_dataset_fetcher.ReactomeAnalysisDatasetFetcher( ) # post one analysis request mq = reactome_mq.ReactomeMQ(queue_name=reactome_mq.DATASET_QUEUE) storage = reactome_storage.ReactomeStorage() mq.post_analysis(models.dataset_request.DatasetRequest( loading_id="loading_2", resource_id="example_datasets", parameters=[ models.dataset_request.DatasetRequestParameter( name="dataset_id", value="EXAMPLE_MEL_PROT") ]).to_json(), method="test") # process the message fetcher.process_single_message() # make sure the status is complete status = storage.get_status(analysis_identifier="loading_2", data_type="dataset") self.assertIsNotNone(status) status_obj = json.loads(status) self.assertEqual("complete", status_obj["status"]) # get the summary summary_string = storage.get_request_data_summary("EXAMPLE_MEL_PROT") self.assertIsNotNone(summary_string) # get the data data_string = storage.get_request_data("EXAMPLE_MEL_PROT") self.assertIsNotNone(data_string)
def test_additional_parameter_analysis(self): """ Tests an analysis request that contains multiple blocking factors """ request_json = """ { "analysisId": "test_01", "datasets": [ { "data": "\\tSample 1\\tSample2\\tSample 3\\nCD19\\t10\\t2\\t20\\nCD20\\t10\\t20\\t2\\nMITF\\t40\\t20\\t10\\n", "design": { "analysisGroup": [ "Treatment", "Control", "Treatment" ], "comparison": { "group1": "Control", "group2": "Treatment" }, "samples": [ "Sample 1", "Sample 2", "Sample 3" ] }, "name": "First experiment", "type": "rnaseq_counts" } ], "methodName": "camera", "parametes": [ { "name": "permutations", "value": "10" }, { "name": "permutations", "value": "10" } ] } """ # make sure the JSON is valid obj = json.loads(request_json) self.assertIsNotNone(obj) # submit the request mq = reactome_mq.ReactomeMQ() mq.post_analysis(request_json, "camera") # download the gene sets if not os.path.isfile("/tmp/reactome_homo_sapiens.pkl"): geneset = self._get_gene_set() geneset.save("/tmp/reactome_homo_sapiens.pkl") # enable debug mode os.environ["REACTOME_WORKER_DEBUG"] = "True" # start to listen to analyses worker = reactome_analysis_worker.ReactomeAnalysisWorker() worker.process_single_message() # fetch the result storage = reactome_storage.ReactomeStorage() result_text = storage.get_result("test_01") self.assertIsNotNone(result_text, "Result was not saved in redis") json_obj = json.loads(result_text) result = AnalysisResult.from_dict(json_obj) self.assertIsNotNone(result) self.assertIsNotNone(result.mappings) self.assertIsNotNone(result.results) self.assertEqual("68", result.release) self.assertEqual(1, len(result.results)) self.assertIsNotNone(result.results[0].pathways) self.assertIsNotNone(result.results[0].fold_changes) pathway_lines = result.results[0].pathways.split("\n") self.assertEqual(23, len(pathway_lines)) gene_lines = result.results[0].fold_changes.split("\n") self.assertEqual(4, len(gene_lines))
def test_incorrect_genes(self): json_request = """ { "analysisId": "test_02", "datasets": [ { "data": "\\tSample 1\\tSample2\\tSample3\\nCD19\\t10\\t20\\t5\\nCD20\\t10\\t49\\t2\\nMITF\\t56\\t14\\t24\\n", "design": { "analysisGroup": [ "Treatment", "Control", "Treatment" ], "comparison": { "group1": "Control", "group2": "Treatment" }, "samples": [ "Sample 1", "Sample 2", "Sample 3" ] }, "name": "First experiment", "type": "rnaseq_counts" }, { "data": "\\tSample 1\\tSample2\\tGene 1\\t10\\t20\\n", "design": { "analysisGroup": [ "Treatment", "Control", "Treatment" ], "comparison": { "group1": "Control", "group2": "Treatment" }, "samples": [ "Sample 1", "Sample 2", "Sample 3" ] }, "name": "First experiment", "type": "rnaseq_counts" } ], "methodName": "Camera", "parameters": [ { "name": "permutations", "value": "10" }, { "name": "permutations", "value": "10" } ] } """ # make sure the JSON is valid obj = json.loads(json_request) self.assertIsNotNone(obj) # submit the request mq = reactome_mq.ReactomeMQ() mq.post_analysis(json_request, "camera") # download the gene sets if not os.path.isfile("/tmp/reactome_homo_sapiens.pkl"): geneset = self._get_gene_set() geneset.save("/tmp/reactome_homo_sapiens.pkl") # enable debug mode os.environ["REACTOME_WORKER_DEBUG"] = "True" # start to listen to analyses worker = reactome_analysis_worker.ReactomeAnalysisWorker() worker.process_single_message() # fetch the result storage = reactome_storage.ReactomeStorage() status = storage.get_status("test_02") status_obj = json.loads(status) self.assertEqual("failed", status_obj["status"]) result_text = storage.get_result("test_02") self.assertIsNone(result_text)