Skip to content

Commit

Permalink
added get_sample_names() method that's replicate compliant (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cowart authored Jun 19, 2024
1 parent d7d5e7e commit 734ebd1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
29 changes: 29 additions & 0 deletions sequence_processing_pipeline/Pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,35 @@ def _get_sample_names_from_sample_sheet(self, project_name):

return results

def get_orig_names_from_sheet(self, project_name):
if project_name is None:
results = [x.orig_name for x in self.sample_sheet.samples]
# eliminate inavoidable duplicates and sort.
return sorted(set(results))
else:
# Since the project-name is stored in an internal variable
# in a third-party library, convert the data structure to
# JSON using the exposed method and obtain from the result.
jsn = json_loads(self.sample_sheet.to_json())

results = []

for sample in jsn['Data']:
# handle case where project_name includes an appended qiita-id.
if sample['Sample_Project'] == project_name:
results.append(sample['orig_name'])
continue

# handle case where project_name does not include a qiita-id.
# exact matching is required for cases where one project name
# in a sheet is a superset of another project in the same
# sheet.
m = search(r'^(.+)_(\d+)$', sample['Sample_Project'])
if m[1] == project_name:
results.append(sample['orig_name'])

return sorted(set(results))

def _get_sample_names_from_mapping_file(self, project_name):
if project_name is None:
return list(self.mapping_file.sample_name)
Expand Down
1 change: 0 additions & 1 deletion sequence_processing_pipeline/tests/test_NuQCJob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,6 @@ def test_regular_expressions(self):
self._helper(job.json_regex, good_names, bad_names)

def test_generate_mmi_filter_cmds(self):
# CHARLIE
double_db_paths = ["db_path/mmi_1.db", "db_path/mmi_2.db"]
job = NuQCJob(self.fastq_root_path, self.output_path,
self.good_sample_sheet_path, double_db_paths,
Expand Down
15 changes: 15 additions & 0 deletions sequence_processing_pipeline/tests/test_Pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def setUp(self):
self.good_run_dir = self.path(self.good_run_id)
self.runinfo_file = self.path(self.good_run_id, 'RunInfo.xml')
self.rtacomplete_file = self.path(self.good_run_id, 'RTAComplete.txt')
self.good_sheet_w_replicates = self.path('good_sheet_w_replicates.csv')

# most of the tests here were written with the assumption that these
# files already exist.
Expand Down Expand Up @@ -152,6 +153,20 @@ def test_get_sample_names_from_sample_sheet(self):
obs = set(pipeline._get_sample_names_from_sample_sheet(param))
self.assertEqual(obs, exp)

def test_get_orig_names_from_sheet_with_replicates(self):
pipeline = Pipeline(self.good_config_file, self.good_run_id,
self.good_sheet_w_replicates, None,
self.output_file_path, self.qiita_id,
Pipeline.METAGENOMIC_PTYPE)

obs = pipeline.get_orig_names_from_sheet('Feist_11661')
exp = {'BLANK.43.12G', 'BLANK.43.12H', 'JBI.KHP.HGL.021',
'JBI.KHP.HGL.022', 'JBI.KHP.HGL.023', 'JBI.KHP.HGL.024',
'RMA.KHP.rpoS.Mage.Q97D', 'RMA.KHP.rpoS.Mage.Q97E',
'RMA.KHP.rpoS.Mage.Q97L', 'RMA.KHP.rpoS.Mage.Q97N'}

self.assertEqual(set(obs), exp)

def test_required_file_checks(self):
# begin this test by deleting the RunInfo.txt file and verifying that
# Pipeline object will raise an Error.
Expand Down

0 comments on commit 734ebd1

Please sign in to comment.