diff --git a/CHANGELOG.md b/CHANGELOG.md index dd16e9405..c74b32580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - bcftools annotate declaration in annotate CADD subworkflow [#624](https://github.com/nf-core/raredisease/pull/624) - Rhocallviz subworkflow will only be invocated once per sample [#621](https://github.com/nf-core/raredisease/pull/621) - Allow for VEP version 112 to be used and set it to default [#617](https://github.com/nf-core/raredisease/pull/617) +- Updated createCaseChannel function to include a check for maternal and paternal ids being set to a numeric 0 [#643](https://github.com/nf-core/raredisease/pull/643) ### Parameters diff --git a/lib/CustomFunctions.groovy b/lib/CustomFunctions.groovy index 1a8d02272..00680f099 100644 --- a/lib/CustomFunctions.groovy +++ b/lib/CustomFunctions.groovy @@ -2,34 +2,39 @@ import nextflow.Nextflow class CustomFunctions { + // Helper function to check if a value is neither 0, "0", nor "" + private static boolean isNonZeroNonEmpty(value) { + return (value instanceof String && value != "" && value != "0") || + (value instanceof Number && value != 0) + } // Function to get a list of metadata (e.g. case id) for the case [ meta ] public static LinkedHashMap createCaseChannel(List rows) { def case_info = [:] - def probands = [] - def upd_children = [] + def probands = [] as Set + def upd_children = [] as Set def father = "" def mother = "" - for (item in rows) { - if (item.phenotype == 2) { - probands.add(item.sample) + rows.each { item -> + if (item?.phenotype == 2) { + probands << item.sample } - if ( (item.paternal!="0") && (item.paternal!="") && (item.maternal!="0") && (item.maternal!="") ) { - upd_children.add(item.sample) + if (isNonZeroNonEmpty(item?.paternal) && isNonZeroNonEmpty(item?.maternal)) { + upd_children << item.sample } - if ( (item.paternal!="0") && (item.paternal!="") ) { + if (isNonZeroNonEmpty(item?.paternal)) { father = item.paternal } - if ( (item.maternal!="0") && (item.maternal!="") ) { + if (isNonZeroNonEmpty(item?.maternal)) { mother = item.maternal } } case_info.father = father case_info.mother = mother - case_info.probands = probands.unique() - case_info.upd_children = upd_children.unique() + case_info.probands = probands.toList() + case_info.upd_children = upd_children.toList() case_info.id = rows[0].case_id return case_info