def test_patients_csv_file2model_without_mhc2(self): patients_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/balachandran_supplementary_table1_patients.tsv" ) patients = ModelConverter.parse_patients_file(patients_file, self.hla_database) self.assertIsNotNone(patients) self.assertIsInstance(patients, list) self.assertTrue(len(patients) == 58)
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 _read_data( candidate_file, json_file, patients_data, patient_id, mhc_database: MhcDatabase) -> Tuple[List[Neoantigen], List[Patient]]: # parse patient data patients = ModelConverter.parse_patients_file(patients_data, mhc_database) # parse the neoantigen candidate data if candidate_file is not None: neoantigens = ModelConverter.parse_candidate_file( candidate_file, patient_id) else: neoantigens = ModelConverter.parse_neoantigens_json_file(json_file) return neoantigens, patients
def setUp(self): self.references, self.configuration = integration_test_tools.load_references( ) self.references_mouse, self.configuration_mouse = integration_test_tools.load_references( organism=ORGANISM_MUS_MUSCULUS) # self.fastafile = integration_test_tools.create_temp_aminoacid_fasta_file() # self.runner = Runner() self.patient_id = "Pt29" input_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_candidate_file.txt") patients_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_patient_file.txt") patients_file_mouse = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_patient_file_mouse.txt") self.hla_database = self.references.get_mhc_database() self.h2_database = self.references_mouse.get_mhc_database() self.patients = ModelConverter.parse_patients_file( patients_file, self.hla_database) self.patients_mouse = ModelConverter.parse_patients_file( patients_file_mouse, self.h2_database) self.neoantigens = ModelConverter.parse_candidate_file(input_file) self.neoantigens_mouse = ModelConverter.parse_candidate_file( input_file)
def test_patients_csv_file2model_without_mhc1(self): patients_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/patient.Pt29.without_mhc1.csv" ) patients = ModelConverter.parse_patients_file(patients_file, self.hla_database) self.assertIsNotNone(patients) self.assertIsInstance(patients, list) self.assertTrue(len(patients) == 1) self.assertIsInstance(patients[0], Patient) self.assertEqual(patients[0].identifier, "Pt29") for m in patients[0].mhc1: self.assertEqual(m.zygosity, Zygosity.LOSS) self.assertEqual(3, len(patients[0].mhc2)) self.assertEqual( 9, len([a for m in patients[0].mhc2 for g in m.genes for a in g.alleles]) ) self.assertEqual(patients[0].is_rna_available, True)
def test_patients_csv_file2model_mouse(self): patients_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/alleles.Pt29_mouse.csv" ) patients = ModelConverter.parse_patients_file(patients_file, self.h2_database) self.assertIsNotNone(patients) self.assertIsInstance(patients, list) self.assertTrue(len(patients) == 1) self.assertIsInstance(patients[0], Patient) self.assertEqual(patients[0].identifier, "Pt29") self.assertEqual(3, len(patients[0].mhc1)) self.assertEqual(6, len([a for m in patients[0].mhc1 for a in m.alleles])) self.assertEqual(2, len(patients[0].mhc2)) self.assertEqual( 3, len([a for m in patients[0].mhc2 for g in m.genes for a in g.alleles]) ) self.assertEqual(patients[0].is_rna_available, False)
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_no_expression_imputation(self): input_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_candidate_file.txt" ) patients_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_patient_file.txt" ) patients = ModelConverter.parse_patients_file(patients_file, self.hla_database) neoantigens = ModelConverter.parse_candidate_file(input_file) neofox_runner = NeoFox( neoantigens=neoantigens, patients=patients, reference_folder=FakeReferenceFolder(), configuration=FakeDependenciesConfiguration(), ) for neoantigen in neoantigens: for neoantigen_imputed in neofox_runner.neoantigens: if neoantigen.mutation.mutated_xmer == neoantigen_imputed.mutation.mutated_xmer: self.assertEqual( neoantigen.rna_expression, neoantigen_imputed.rna_expression )
def test_with_expression_imputation(self): input_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_candidate_file_Pty.txt" ) neoantigens= ModelConverter.parse_candidate_file(input_file) import copy original_neoantigens = copy.deepcopy(neoantigens) patients_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_patient_file.txt" ) patients = ModelConverter.parse_patients_file(patients_file, self.hla_database) neofox_runner = NeoFox( neoantigens=neoantigens, patients=patients, reference_folder=FakeReferenceFolder(), configuration=FakeDependenciesConfiguration(), ) for neoantigen in original_neoantigens: for neoantigen_imputed in neofox_runner.neoantigens: self.assertFalse( neoantigen.rna_expression == neoantigen_imputed.rna_expression )
def test_patients_csv_file2model3(self): patients_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/test_patient_info.txt" ) patients = ModelConverter.parse_patients_file(patients_file, self.hla_database) self.assertIsNotNone(patients) self.assertIsInstance(patients, list) self.assertTrue(len(patients) == 1) self.assertIsInstance(patients[0], Patient) self.assertEqual(patients[0].identifier, "Ptx") self.assertEqual(3, len(patients[0].mhc1)) self.assertEqual(6, len([a for m in patients[0].mhc1 for a in m.alleles])) self.assertEqual(3, len(patients[0].mhc2)) self.assertEqual( 10, len([a for m in patients[0].mhc2 for g in m.genes for a in g.alleles]) ) self.assertTrue( "HLA-A*03:01" in [a.name for m in patients[0].mhc1 for a in m.alleles] ) self.assertTrue( "HLA-DQA1*04:01" in [a.name for m in patients[0].mhc2 for g in m.genes for a in g.alleles] ) self.assertTrue(patients[0].is_rna_available)