Skip to content

Commit

Permalink
add pep_ms tests, refactor (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 27, 2024
1 parent 2e12832 commit b557328
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 34 deletions.
2 changes: 1 addition & 1 deletion samplesheets/assayapps/meta_ms/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

from copy import deepcopy

from samplesheets.assayapps.meta_ms.plugins import RAW_DATA_COLL
from samplesheets.assayapps.tests.base import AssayPluginTestBase
from samplesheets.rendering import SIMPLE_LINK_TEMPLATE
from samplesheets.views import MISC_FILES_COLL, RESULTS_COLL


# Local constants
RAW_DATA_COLL = 'RawData'
REPORT_NAME = 'report.txt'
FILE_NAME = 'file1.txt'
FILE_NAME2 = 'file2.txt'
Expand Down
2 changes: 1 addition & 1 deletion samplesheets/assayapps/microarray/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from django.conf import settings

from samplesheets.assayapps.microarray.plugins import RAW_DATA_COLL
from samplesheets.assayapps.tests.base import AssayPluginTestBase


# Local constants
RAW_DATA_COLL = 'RawData'
HYBRID_SCAN_NAME = 'alpha-S1-E1-H1'
SCAN_NAME_UPDATE = 'alpha-S1-E1-scan-name'
IMAGE_FILE = 'image.tiff'
Expand Down
32 changes: 0 additions & 32 deletions samplesheets/assayapps/pep_ms/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,8 @@ def update_row(self, row, table, assay, index):
return row
base_url = settings.IRODS_WEBDAV_URL + assay_path

# Check if MaxQuant is found
# NOTE: Currently disabled
'''
max_quant_found = False
for i in range(len(row)):
header = table['field_header'][i]
if (
header['obj_cls'] == 'Process'
and header['value'].lower() == 'analysis software name'
and row[i]['value'] == 'MaxQuant'
):
max_quant_found = True
break
'''

for i in range(len(row)):
header = table['field_header'][i]

# Data files
if (
header['obj_cls'] == 'GenericMaterial'
Expand All @@ -114,20 +96,6 @@ def update_row(self, row, table, assay, index):
row[i]['link'] = (
base_url + '/' + RAW_DATA_COLL + '/' + row[i]['value']
)

# Process parameter files
# NOTE: Currently disabled
'''
elif (
max_quant_found
and header['obj_cls'] == 'Process'
and header['value'].lower() == 'analysis database file'
):
row[i]['link'] = (
base_url + '/' + MAX_QUANT_COLL + '/' + row[i]['value']
)
'''

return row

def get_shortcuts(self, assay):
Expand Down
Empty file.
73 changes: 73 additions & 0 deletions samplesheets/assayapps/pep_ms/tests/test_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""Plugin tests for the the pep_ms assay plugin"""

import os

from copy import deepcopy

from samplesheets.assayapps.pep_ms.plugins import RAW_DATA_COLL, MAX_QUANT_COLL
from samplesheets.assayapps.tests.base import AssayPluginTestBase
from samplesheets.models import ISA_META_ASSAY_PLUGIN


# Local constants
PLUGIN_NAME = 'samplesheets_assay_pep_ms'
FILE_NAME = 'file1.txt'
FILE_NAME2 = 'file2.txt'


class TestMetaMSAssayPlugin(AssayPluginTestBase):
"""Tests for meta_ms assay plugin"""

plugin_name = PLUGIN_NAME
template_name = 'ms_meta_biocrates'

def setUp(self):
super().setUp()
# Override plugin
self.assay.comments[ISA_META_ASSAY_PLUGIN] = PLUGIN_NAME
self.assay.save()

def test_get_row_path(self):
"""Test get_row_path()"""
row_path = self.plugin.get_row_path(
self.assay_table['table_data'][0],
self.assay_table,
self.assay,
self.assay_path,
)
expected = os.path.join(self.assay_path, RAW_DATA_COLL)
self.assertEqual(row_path, expected)

def test_update_row(self):
"""Test update_row()"""
self.assay_table['table_data'][0][44]['value'] = FILE_NAME
self.assay_table['table_data'][0][51]['value'] = FILE_NAME2
row_ex = deepcopy(self.assay_table['table_data'][0])
row_ex[44]['link'] = os.path.join(
self.base_url, RAW_DATA_COLL, FILE_NAME
)
row_ex[51]['link'] = os.path.join(
self.base_url, RAW_DATA_COLL, FILE_NAME2
)
row = self.plugin.update_row(
self.assay_table['table_data'][0], self.assay_table, self.assay, 0
)
self.assertEqual(row, row_ex)

# TODO: Test with empty file names after fixing #2017

def test_get_shortcuts(self):
"""Test get_shortcuts()"""
expected = [
{
'id': 'raw_data',
'label': 'Raw Data',
'path': os.path.join(self.assay_path, RAW_DATA_COLL),
},
{
'id': 'maxquant_results',
'label': 'MaxQuant Results',
'path': os.path.join(self.assay_path, MAX_QUANT_COLL),
},
]
self.assertEqual(self.plugin.get_shortcuts(self.assay), expected)

0 comments on commit b557328

Please sign in to comment.