Skip to content

Commit

Permalink
adding lefse tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcantor22 committed Aug 8, 2024
1 parent 8894169 commit 976ccb3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 47 deletions.
10 changes: 7 additions & 3 deletions mmeds/resources/lefse_config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
class: class_col
subclass: subclass_col
subjects: subjects_col
tables:
- taxa_table_L6
classes:
- Sex
- Group
subclasses:
- Group
35 changes: 21 additions & 14 deletions mmeds/tests/unit/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from time import sleep

from mmeds.util import run_analysis, load_config, upload_sequencing_run_local
from mmeds.summary import summarize_qiime
from mmeds.spawn import Watcher
from mmeds.logging import Logger
from mmeds.tools.analysis import Analysis
Expand All @@ -24,9 +23,11 @@ def setUpClass(self):
self.watcher.connect()
self.queue = self.watcher.get_queue()
self.config = load_config(fig.DEFAULT_CONFIG, fig.TEST_MIXED_METADATA, 'standard_pipeline')
self.config_lefse = load_config(fig.DEFAULT_CONFIG_LEFSE, fig.TEST_MIXED_METADATA, 'lefse')
self.analysis = []
with Database(owner=fig.TEST_USER_0, testing=True) as db:
self.analysis_code = db.create_access_code()
self.analysis_code_0 = db.create_access_code()
self.analysis_code_1 = db.create_access_code()

def test_a_upload_sequencing_run(self):
""" Upload sequencing run for analysis """
Expand All @@ -41,30 +42,36 @@ def test_b_analysis_init(self):
""" Test analysis object """
with Database(owner=fig.TEST_USER_0, testing=True) as db:
self.runs = db.get_sequencing_run_locations(fig.TEST_MIXED_METADATA, fig.TEST_USER_0)
self.analysis += [Analysis(self.queue, fig.TEST_USER_0, self.analysis_code, fig.TEST_CODE_MIXED,
self.analysis += [Analysis(self.queue, fig.TEST_USER_0, self.analysis_code_0, fig.TEST_CODE_MIXED,
'standard_pipeline', 'default', 'test_init', self.config, True, self.runs, False, threads=2)]
self.analysis += [Analysis(self.queue, fig.TEST_USER_0, self.analysis_code_1, fig.TEST_CODE_MIXED,
'lefse', 'default', 'test_lefse', self.config_lefse, True, {}, False, threads=2)]


def test_b_standard_pipeline(self):
def test_c_standard_pipeline(self):
""" Test running a standard analysis """
# run_analysis() executes analyses synchronously rather than submitting as a job
run_analysis(self.test_study, 'standard_pipeline', testing=True)
"""
summarize_qiime(f'{self.test_study}/Qiime2_0', 'standard_pipeline', testing=True)

check for summary pdf, also gets uploaded as an artifact in github actions for inspection
pdf_output = Path(f'{self.test_study}/Qiime2_0/summary/[email protected]')
self.assertTrue(pdf_output.exists())
"""

def test_c_analysis_class(self):
""" Test the analysis object """
def test_d_analysis_class(self):
""" Test the analysis objects """
analysis = self.analysis[0]
analysis.run()

info = analysis.get_info()
table = Path(info['path']) / 'tables' / 'taxa_table_L6.qza'
table.touch()

self.assertEquals(info['owner'], fig.TEST_USER_0)
self.assertEquals(info['analysis_code'], self.analysis_code_0)

def test_e_lefse_analysis_class(self):
lefse_analysis = self.analysis[1]
lefse_analysis.run()

info = lefse_analysis.get_info()
self.assertEquals(info['owner'], fig.TEST_USER_0)
self.assertEquals(info['analysis_code'], self.analysis_code)
self.assertEquals(info['analysis_code'], self.analysis_code_1)

def test_d_analysis_utils(self):
""" Test that adding files to the tool object works properly """
Expand Down
30 changes: 0 additions & 30 deletions mmeds/tools/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,32 +227,6 @@ def create_snakemake_file(self):
with open(snakefile, "wt") as f:
f.write(workflow_text)

def summary(self):
""" Setup script to create summary. """
self.add_path('summary')
if self.testing:
self.jobtext.append('module load mmeds-stable;')
else:
self.jobtext.append(
'conda deactivate; source activate /hpc/users/mmedsadmin/.admin_modules/jupyter; ml texlive/2018')
# Make sure the kernel is up to date
self.jobtext.append('python -m ipykernel install --user --name jupyter --display-name "Jupyter"')
cmd = [
'summarize.py ',
'--path "{}"'.format(self.run_dir),
'--workflow_type {};'.format(self.doc.workflow_type)
]
self.jobtext.append(' '.join(cmd))

def zip(self):
"""
Create a zip of the whole analyis directory.
This way a user can download the whole thing
if they are so inclined.
"""
cmd = f'zip -r {self.run_dir}.zip {self.run_dir};'
self.jobtext.append(cmd)

def copy_taxonomic_database(self):
""" Copy in the database (e.g. greengenes, silva) to be used for classification"""
database_file = TAXONOMIC_DATABASES[self.config["taxonomic_database"]]
Expand Down Expand Up @@ -373,10 +347,6 @@ def setup_analysis(self, summary=False):
self.jobtext.append(f"snakemake --use-conda --cores {self.num_jobs} --default-resource tmpdir=\"tmp_dir\"")
self.jobtext.append('echo "MMEDS_FINISHED"')

Logger.debug("adding summary")
if summary:
self.summary()

submitfile = self.path / 'submitfile'
self.add_path(submitfile, '.sh', 'submitfile')
# Define the job and error files
Expand Down

0 comments on commit 976ccb3

Please sign in to comment.