From 5fde74adbdb7b0ec04b71a29fa30c1b7d8d6e935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Balajti?= Date: Tue, 31 Oct 2023 16:40:57 +0100 Subject: [PATCH] test: add org param tests --- Log.out | 39 ++++++++++++++++ tests/test_get_library_source.py | 79 ++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 Log.out diff --git a/Log.out b/Log.out new file mode 100644 index 00000000..2452d100 --- /dev/null +++ b/Log.out @@ -0,0 +1,39 @@ +STAR version=2.7.10b +STAR compilation time,server,dir=2022-11-01T09:53:26-04:00 :/home/dobin/data/STAR/STARcode/STAR.master/source +STAR git: On branch master ; commit c6f8efc2c7043ef83bf8b0d9bed36bbb6b9b1133 ; diff files: CHANGES.md +##### Command Line: +STAR --runMode genomeGenerate --genomeSAindexNbases 5 --genomeChrBinNbits 18 --runThreadN 1 --genomeDir /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/index --genomeFastaFiles /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/invalid +##### Initial USER parameters from Command Line: +###### All USER parameters from Command Line: +runMode genomeGenerate ~RE-DEFINED +genomeSAindexNbases 5 ~RE-DEFINED +genomeChrBinNbits 18 ~RE-DEFINED +runThreadN 1 ~RE-DEFINED +genomeDir /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/index ~RE-DEFINED +genomeFastaFiles /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/invalid ~RE-DEFINED +##### Finished reading parameters from all sources + +##### Final user re-defined parameters-----------------: +runMode genomeGenerate +runThreadN 1 +genomeDir /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/index +genomeFastaFiles /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/invalid +genomeSAindexNbases 5 +genomeChrBinNbits 18 + +------------------------------- +##### Final effective command line: +STAR --runMode genomeGenerate --runThreadN 1 --genomeDir /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/index --genomeFastaFiles /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/invalid --genomeSAindexNbases 5 --genomeChrBinNbits 18 +---------------------------------------- + +Number of fastq files for each mate = 1 +ParametersSolo: --soloCellFilterType CellRanger2.2 filtering parameters: 3000 0.99 10 +Finished loading and checking parameters +--genomeDir directory exists and will be overwritten: /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/index/ +!!!!! WARNING: Could not move Log.out file from ./Log.out into /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/index/Log.out. Will keep ./Log.out + +Oct 31 16:40:53 ... starting to generate Genome files + +EXITING because of INPUT ERROR: could not open genomeFastaFile: /scratch/pytest-of-balajt0000/pytest-29/test_create_star_index_star_pr0/invalid + +Oct 31 16:40:53 ...... FATAL ERROR, exiting diff --git a/tests/test_get_library_source.py b/tests/test_get_library_source.py index 5b27e8a6..e8e01498 100644 --- a/tests/test_get_library_source.py +++ b/tests/test_get_library_source.py @@ -264,6 +264,52 @@ def test_evaluate_min_freq_ratio(self, tmpdir): file_2=Source() ) + def test_evaluate_org_id_not_none(self): + """Test when self.org_id is not None.""" + CONFIG.args.org_id = 7227 # An example taxon ID + CONFIG.args.t_file_processed = FILE_TRANSCRIPTS + test_instance = GetLibSource(config=CONFIG) + result = test_instance.evaluate() + + assert result.file_1.taxon_id == 7227 + assert result.file_1.short_name == "dmelanogaster" + + def test_evaluate_org_id_none_with_path_2(self, tmpdir, monkeypatch): + """Test when self.org_id is None and self.paths[1] is not None.""" + CONFIG.args.org_id = None + CONFIG.args.path_1_processed = FILE_MATE_1 + CONFIG.args.path_2_processed = FILE_MATE_2 + CONFIG.args.t_file_processed = FILE_TRANSCRIPTS + CONFIG.args.tmp_dir = tmpdir + CONFIG.args.out_dir = tmpdir + test_instance = GetLibSource(config=CONFIG) + + # Mock the get_source method to return a specific result + monkeypatch.setattr( + 'htsinfer.get_library_source.GetLibSource.get_source', + lambda *args, **kwargs: SOURCE_HUMAN, + ) + + result = test_instance.evaluate() + + assert result.file_2.taxon_id == SOURCE_HUMAN.taxon_id + assert result.file_2.short_name == SOURCE_HUMAN.short_name + + def test_evaluate_org_id_not_none_with_path_2(self, tmpdir): + """Test when self.org_id is not None and self.paths[1] is not None.""" + CONFIG.args.org_id = 7227 + CONFIG.args.path_1_processed = FILE_MATE_1 + CONFIG.args.path_2_processed = FILE_MATE_2 + CONFIG.args.t_file_processed = FILE_TRANSCRIPTS + CONFIG.args.tmp_dir = tmpdir + CONFIG.args.out_dir = tmpdir + test_instance = GetLibSource(config=CONFIG) + + result = test_instance.evaluate() + + assert result.file_2.taxon_id == 7227 + assert result.file_2.short_name == "dmelanogaster" + def test_create_kallisto_index_problem(self, tmpdir): """Pass invalid file as transcripts.fasta file to simulate KallistoProblem.""" @@ -276,3 +322,36 @@ def test_create_kallisto_index_problem(self, tmpdir): test_instance = GetLibSource(config=CONFIG) with pytest.raises(KallistoProblem): test_instance.create_kallisto_index() + + def test_get_organism_name_found(self): + """Test the function when the taxon_id + is found in the organism dictionary.""" + CONFIG.args.t_file_processed = FILE_TRANSCRIPTS + test_instance = GetLibSource(config=CONFIG) + taxon_id = 7227 + result = test_instance.get_organism_name( + taxon_id, CONFIG.args.t_file_processed + ) + assert result == "dmelanogaster" + + def test_get_organism_name_not_found(self): + """Test the function when the taxon_id + is not found in the organism dictionary.""" + CONFIG.args.t_file_processed = FILE_TRANSCRIPTS + test_instance = GetLibSource(config=CONFIG) + taxon_id = 12345 # A tax ID that doesn't exist in transcripts + result = test_instance.get_organism_name( + taxon_id, CONFIG.args.t_file_processed + ) + assert result is None + + def test_get_organism_name_file_problem(self): + """Test the function when there's a + file problem while processing the FASTA file.""" + CONFIG.args.t_file_processed = FILE_DUMMY + test_instance = GetLibSource(config=CONFIG) + taxon_id = 7227 + with pytest.raises(FileProblem): + test_instance.get_organism_name( + taxon_id, CONFIG.args.t_file_processed + )