Skip to content

Commit

Permalink
feat: add org_id param #108
Browse files Browse the repository at this point in the history
  • Loading branch information
balajtimate committed Nov 10, 2023
1 parent fa1f3fc commit fbd91b0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 4 deletions.
11 changes: 7 additions & 4 deletions htsinfer/get_library_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ def evaluate(self) -> ResultsSource:
# Check if library_source is provided, otherwise infer it
if self.org_id is not None:
source.file_1.taxon_id = self.org_id
org_name = self.get_organism_name(self.org_id, self.transcripts_file)

org_name = self.get_organism_name(
self.org_id,
self.transcripts_file
)

if org_name is not None:
source.file_1.short_name = org_name

Expand All @@ -89,8 +92,8 @@ def evaluate(self) -> ResultsSource:

else:
LOGGER.warning(
f"Taxon ID '{self.org_id}' not found in organism dictionary, "
"inferring source organism..."
f"Taxon ID '{self.org_id}' not found in "
"organism dictionary, inferring source organism..."
)
index = self.create_kallisto_index()
library_source = self.get_source(
Expand Down
90 changes: 90 additions & 0 deletions tests/test_get_library_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,93 @@ def test_get_organism_name_file_problem(self):
test_instance.get_organism_name(
taxon_id, CONFIG.args.t_file_processed
)

def test_evaluate_org_id_is_none(self, monkeypatch, tmpdir):
"""Test when self.org_id is 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 create_kallisto_index method to return a specific result
monkeypatch.setattr(
'htsinfer.get_library_source.GetLibSource.create_kallisto_index',
lambda *args, **kwargs: tmpdir / "kallisto.idx",
)

# Mock the get_source method to return a specific result
monkeypatch.setattr(
'htsinfer.get_library_source.GetLibSource.get_source',
lambda *args, **kwargs: SOURCE_FRUIT_FLY,
)

result = test_instance.evaluate()

assert result.file_1.taxon_id == SOURCE_FRUIT_FLY.taxon_id
assert result.file_1.short_name == SOURCE_FRUIT_FLY.short_name

assert result.file_2.taxon_id == SOURCE_FRUIT_FLY.taxon_id
assert result.file_2.short_name == SOURCE_FRUIT_FLY.short_name

def test_evaluate_org_id_not_none_no_org_name(self, monkeypatch, tmpdir):
"""Test when self.org_id is not None but org_name is not found."""
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)

# Mock the get_organism_name method to return None
monkeypatch.setattr(
'htsinfer.get_library_source.GetLibSource.get_organism_name',
lambda *args, **kwargs: None,
)

# Mock the create_kallisto_index method to return a specific result
monkeypatch.setattr(
'htsinfer.get_library_source.GetLibSource.create_kallisto_index',
lambda *args, **kwargs: tmpdir / "kallisto.idx",
)

# Mock the get_source method to return a specific result
monkeypatch.setattr(
'htsinfer.get_library_source.GetLibSource.get_source',
lambda *args, **kwargs: SOURCE_FRUIT_FLY,
)

result = test_instance.evaluate()

assert result.file_1.taxon_id == SOURCE_FRUIT_FLY.taxon_id
assert result.file_1.short_name == SOURCE_FRUIT_FLY.short_name

assert result.file_2.taxon_id == SOURCE_FRUIT_FLY.taxon_id
assert result.file_2.short_name == SOURCE_FRUIT_FLY.short_name

def test_evaluate_org_id_not_none_name_found(self, monkeypatch, tmpdir):
"""Test when self.org_id is not None and org_name is found."""
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)

# Mock the get_organism_name method to return a specific result
monkeypatch.setattr(
'htsinfer.get_library_source.GetLibSource.get_organism_name',
lambda *args, **kwargs: "dmelanogaster",
)

result = test_instance.evaluate()

assert result.file_1.taxon_id == 7227
assert result.file_1.short_name == "dmelanogaster"

assert result.file_2.taxon_id == 7227
assert result.file_2.short_name == "dmelanogaster"

0 comments on commit fbd91b0

Please sign in to comment.