def test_csv_neoantigens2model(self): neoantigens_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_data_model.txt" ) data = pd.read_csv(neoantigens_file, sep="\t") neoantigens = ModelConverter._neoantigens_csv2objects(data) self.assertEqual(5, len(neoantigens)) for n in neoantigens: self.assertTrue(isinstance(n, Neoantigen)) self.assertNotEmpty(n.mutation) self.assertNotEmpty(n.patient_identifier) self.assertNotEmpty(n.gene) self.assertTrue(isinstance(n.mutation, Mutation)) self.assertNotEmpty(n.mutation.mutated_xmer) self.assertNotEmpty(n.mutation.wild_type_xmer) self.assertIsNotNone(n.mutation.position) # test external annotations self._assert_external_annotations( expected_external_annotations=["external_annotation_1", "external_annotation_2"], neoantigen_annotations=n.external_annotations, non_nullable_annotations=["external_annotation_1", "external_annotation_2"] ) for a in n.external_annotations: if a.name == "external_annotation_1": self.assertEqual(a.value, "blah1") elif a.name == "external_annotation_2": self.assertEqual(a.value, "blah2")
def _get_test_data(self): input_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_model_file.txt") data = pd.read_csv(input_file, sep="\t") data = data.replace({np.nan: None}) neoantigens = ModelConverter._neoantigens_csv2objects(data) patients_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_patient_file.txt") patients = ModelConverter.parse_patients_file(patients_file, self.hla_database) patient_id = "Pt29" return neoantigens, patients, patient_id
def test_neofox_synthetic_data(self): """ this test just ensures that NeoFox does not crash with the synthetic data """ data = [ ("resources/synthetic_data/neoantigens_1patients_10neoantigens.2.txt", "resources/synthetic_data/patients_1patients_10neoantigens.2.txt" ), ("resources/synthetic_data/neoantigens_10patients_10neoantigens.0.txt", "resources/synthetic_data/patients_10patients_10neoantigens.0.txt" ), #("resources/synthetic_data/neoantigens_100patients_10neoantigens.2.txt", # "resources/synthetic_data/patients_100patients_10neoantigens.2.txt"), #("resources/synthetic_data/neoantigens_no_wt_1patients_10neoantigens.3.txt", # "resources/synthetic_data/patients_no_wt_1patients_10neoantigens.3.txt"), #("resources/synthetic_data/poltergeist_neoantigens.txt", # "resources/synthetic_data/poltergeist_patients.txt") ("resources/synthetic_data/neoantigens_no_wt_10patients_10neoantigens.4.txt", "resources/synthetic_data/patients_no_wt_10patients_10neoantigens.4.txt" ), #("resources/synthetic_data/neoantigens_100patients_10neoantigens.4.txt", # "resources/synthetic_data/patients_100patients_10neoantigens.4.txt"), ] for n, p, in data: input_file = pkg_resources.resource_filename( neofox.tests.__name__, n) data = pd.read_csv(input_file, sep="\t") data = data.replace({np.nan: None}) neoantigens = ModelConverter._neoantigens_csv2objects(data) patients_file = pkg_resources.resource_filename( neofox.tests.__name__, p) patients = ModelConverter.parse_patients_file( patients_file, self.hla_database) annotations = NeoFox( neoantigens=neoantigens, patients=patients, num_cpus=4, ).get_annotations() self.assertIsNotNone(annotations)
def test_model2csv2model(self): neoantigen = get_random_neoantigen() csv_data = ModelConverter._objects2dataframe([neoantigen]) neoantigen2 = ModelConverter._neoantigens_csv2objects(csv_data)[0] self.assertEqual(neoantigen, neoantigen2)