Skip to content

Commit

Permalink
Validate study assay sample overlap (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Kuhring committed Apr 16, 2021
1 parent 61e279c commit 8ddeb18
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 3 additions & 1 deletion altamisa/apps/isatab_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def run_warnings_caught(args):
StudyValidator(investigation, study_info, studies[s]).validate()
for a, assay_info in enumerate(study_info.assays):
if assay_info.path:
AssayValidator(investigation, study_info, assay_info, assays[s][a]).validate()
AssayValidator(
investigation, study_info, assay_info, assays[s][a], studies[s]
).validate()


def main(argv=None):
Expand Down
37 changes: 36 additions & 1 deletion altamisa/isatab/validate_assay_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ def __init__(
study_info: models.StudyInfo,
study: models.Study,
):

self._study_info = study_info
self._assay_info = None
self._model = study
Expand All @@ -495,6 +494,8 @@ class AssayValidator(_AssayAndStudyValidator):
:param assay_info: The corresponding assay information
:type assay: models.Assay
:param assay: The Assay model to validate
:type parent_study: models.Study
:param parent_study: Optional: The parent Study of the current Assay (for extended validation)
"""

_model_type = MODEL_TYPE_ASSAY
Expand All @@ -505,8 +506,42 @@ def __init__(
study_info: models.StudyInfo,
assay_info: models.AssayInfo,
assay: models.Assay,
parent_study: models.Study = None,
):
self._study_info = study_info
self._assay_info = assay_info
self._model = assay
self._parent_study = parent_study
super().__init__(investigation)

def validate(self):
"""Validate the assay"""
# Independent validations
super().validate()
# Study-dependent validations
if self._parent_study:
self._validate_dependency()

def _validate_dependency(self):
"""Validate if assay complies with parent study"""

# Check if all samples in the assays are declared in the parent study
# Collect materials of type "Sample Name"
study_samples = [
m.name
for m in self._parent_study.materials.values()
if m.type == table_headers.SAMPLE_NAME
]
assay_samples = [
m.name for m in self._model.materials.values() if m.type == table_headers.SAMPLE_NAME
]
# Collect and list assay samples missing in study
samples_not_in_study = [s for s in assay_samples if s not in study_samples]
if samples_not_in_study:
tpl = "Found samples in assay '{}' but not in parent study '{}':\\n{}"
msg = tpl.format(
self._assay_info.path.name,
self._study_info.info.path.name,
", ".join(samples_not_in_study),
)
warnings.warn(msg, ModerateIsaValidationWarning)
1 change: 1 addition & 0 deletions tests/data/i_warnings/a_warnings.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Sample Name Protocol REF Extract Name Protocol REF Labeled Extract Name Label Protocol REF Assay Name Raw Data File Raw Data File
0815-N1 extraction 0815-N1-DNA1 labeling nucleic acid sequencing 0815-N1-DNA1-WES1 0815-N1-DNA1-WES1_L???_???_R1.fastq.gz 0815-N1-DNA1-WES1_L???_???_R2.fastq.gz
0815-N2 extraction 0815-N1-DNA1 labeling nucleic acid sequencing 0815-N1-DNA1-WES1 0815-N1-DNA1-WES1_L???_???_R1.fastq.gz 0815-N1-DNA1-WES1_L???_???_R2.fastq.gz
2 changes: 1 addition & 1 deletion tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_isatab_validate():
with pytest.warns(IsaWarning) as record:
assert not isatab_validate.main(argv)

assert 15 == len(record)
assert 17 == len(record)


def test_isatab2isatab(tmpdir):
Expand Down

0 comments on commit 8ddeb18

Please sign in to comment.