def test_neofox(self): """ This test is equivalent to the command line call: neofox --candidate-file /projects/SUMMIT/WP1.2/neofox/development/Pt29.sequences4testing.txt --patient-id Pt29 --patients-data ../resources/patient.pt29.csv NOTE: we will need to check the output when the calculation of resuls and printing to stdout have been decoupled """ output_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/output_{:%Y%m%d%H%M%S}_neoantigen_candidates_annotated.tsv" .format(datetime.now()), ) output_file_neoantigens = pkg_resources.resource_filename( neofox.tests.__name__, "resources/output_{:%Y%m%d%H%M%S}.neoantigens.tsv".format( datetime.now()), ) output_json_neoantigens = pkg_resources.resource_filename( neofox.tests.__name__, "resources/output_{:%Y%m%d%H%M%S}.neoantigen_candidates.json". format(datetime.now()), ) annotations = NeoFox( neoantigens=self.neoantigens, patient_id=self.patient_id, patients=self.patients, num_cpus=4, ).get_annotations() annotation_names = [ a.name for n in annotations for a in n.neofox_annotations.annotations ] # check it does contain any of the MixMHCpred annotations self.assertIn("MixMHC2pred_best_peptide", annotation_names) self.assertIn("MixMHC2pred_best_rank", annotation_names) self.assertIn("MixMHC2pred_best_allele", annotation_names) self.assertIn("MixMHCpred_best_peptide", annotation_names) self.assertIn("MixMHCpred_best_score", annotation_names) self.assertIn("MixMHCpred_best_rank", annotation_names) self.assertIn("MixMHCpred_best_allele", annotation_names) # checks it does have some of the NetMHCpan annotations self.assertIn("Best_affinity_MHCI_9mer_position_mutation", annotation_names) self.assertIn("Best_rank_MHCII_score", annotation_names) # writes output ModelConverter.annotations2table(neoantigens=annotations).to_csv( output_file, sep="\t", index=False) ModelConverter._objects2dataframe(annotations).to_csv( output_file_neoantigens, sep="\t", index=False) with open(output_json_neoantigens, "wb") as f: f.write(json.dumps(ModelConverter.objects2json(annotations))) # regression test self._regression_test_on_output_file(new_file=output_file)
def test_neomouse(self): output_file = pkg_resources.resource_filename( neofox.tests.__name__, "resources/output_mouse_{:%Y%m%d%H%M%S}_neoantigen_candidates_annotated.tsv" .format(datetime.now()), ) output_file_neoantigens = pkg_resources.resource_filename( neofox.tests.__name__, "resources/output_mouse_{:%Y%m%d%H%M%S}.neoantigens.tsv".format( datetime.now()), ) output_json_neoantigens = pkg_resources.resource_filename( neofox.tests.__name__, "resources/output_mouse_{:%Y%m%d%H%M%S}.neoantigen_candidates.json" .format(datetime.now()), ) annotations = NeoFox( neoantigens=self.neoantigens_mouse, patient_id=self.patient_id, patients=self.patients_mouse, num_cpus=4, reference_folder=self.references_mouse).get_annotations() annotation_names = [ a.name for n in annotations for a in n.neofox_annotations.annotations ] # checks it does have some of the NetMHCpan annotations self.assertIn("Best_affinity_MHCI_9mer_position_mutation", annotation_names) self.assertIn("Best_rank_MHCII_score", annotation_names) # writes output ModelConverter.annotations2table(neoantigens=annotations).to_csv( output_file, sep="\t", index=False) ModelConverter._objects2dataframe(annotations).to_csv( output_file_neoantigens, sep="\t", index=False) with open(output_json_neoantigens, "wb") as f: f.write(json.dumps(ModelConverter.objects2json(annotations))) # regression test self._regression_test_on_output_file( new_file=output_file, previous_filename="resources/output_previous_mouse.txt")
def _write_results(neoantigens, output_folder, output_prefix, with_json, with_table): # NOTE: this import here is a compromise solution so the help of the command line responds faster from neofox.model.conversion import ModelConverter # writes the output if with_table: ModelConverter.annotations2table(neoantigens).to_csv( os.path.join( output_folder, "{}_neoantigen_candidates_annotated.tsv".format(output_prefix), ), sep="\t", index=False, ) if with_json: output_features = os.path.join( output_folder, "{}_neoantigen_candidates_annotated.json".format(output_prefix)) with open(output_features, "wb") as f: f.write(json.dumps(ModelConverter.objects2json(neoantigens)))