Repository: bihealth/biomedsheets

Issue:
InconsistentPedigreeException raised if father is missing
**Describe the bug**
In the case of incomplete families, InconsistentPedigreeException maybe raised incorrectly.



Comments:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 3958c1e..31e84e1 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -2,6 +2,13 @@
 BioMed Sheets Changelog
 =======================
 
+
+-----------------
+HEAD (unreleased)
+-----------------
+
+- Hotfix: fixed consistency check for Duo Cases (#26)
+
 -------
 v0.11.4
 -------
diff --git a/biomedsheets/shortcuts/germline.py b/biomedsheets/shortcuts/germline.py
index 67c5367..de3d9ac 100644
--- a/biomedsheets/shortcuts/germline.py
+++ b/biomedsheets/shortcuts/germline.py
@@ -354,7 +354,7 @@ class CohortBuilder:
                 if donor.mother_pk:
                     donor._mother = cohort.pk_to_donor[int(donor.mother_pk)]
                     # Consistent check - it shouldn't be 'None' if pedigree correctly joint
-                    if not pedigree.pk_to_donor.get(donor.father_pk, None):
+                    if not pedigree.pk_to_donor.get(donor.mother_pk, None):
                         raise InconsistentPedigreeException(error_msg.format(
                             id_=donor.bio_entity.secondary_id, join_by_field=self.join_by_field)
                         )


Test patch:
diff --git a/tests/test_shortcuts_germline.py b/tests/test_shortcuts_germline.py
index ecc30f9..30022c9 100644
--- a/tests/test_shortcuts_germline.py
+++ b/tests/test_shortcuts_germline.py
@@ -66,6 +66,52 @@ def tsv_sheet_germline_trio_plus():
     """.lstrip()))
     return f
 
+@pytest.fixture
+def tsv_sheet_germline_duo_w_mother():
+    """Example TSV germline sheet with duo - mother present.
+
+    :return: Returns StringIO with sample sheet for duo: index, mother.
+    """
+    return io.StringIO(textwrap.dedent("""
+    [Metadata]
+    schema\tgermline_variants
+    schema_version\tv1
+    title\tExample germline study
+    description\tSimple study with one trio plus
+
+    [Custom Fields]
+    key\tannotatedEntity\tdocs\ttype\tminimum\tmaximum\tunit\tchoices\tpattern
+    familyId\tbioEntity\tFamily\tstring\t.\t.\t.\t.\t.
+
+    [Data]
+    familyId\tpatientName\tfatherName\tmotherName\tsex\tisAffected\tlibraryType\tfolderName\thpoTerms
+    family1\tmother1\t0\t0\tM\tN\tWES\tmother1\t.
+    family1\tindex1\t0\tmother1\tM\tY\tWES\tindex1\t.
+    """.lstrip()))
+
+@pytest.fixture
+def tsv_sheet_germline_duo_w_father():
+    """Example TSV germline sheet with duo - father present.
+
+    :return: Returns StringIO with sample sheet for duo: index, father.
+    """
+    return io.StringIO(textwrap.dedent("""
+    [Metadata]
+    schema\tgermline_variants
+    schema_version\tv1
+    title\tExample germline study
+    description\tSimple study with one trio plus
+
+    [Custom Fields]
+    key\tannotatedEntity\tdocs\ttype\tminimum\tmaximum\tunit\tchoices\tpattern
+    familyId\tbioEntity\tFamily\tstring\t.\t.\t.\t.\t.
+
+    [Data]
+    familyId\tpatientName\tfatherName\tmotherName\tsex\tisAffected\tlibraryType\tfolderName\thpoTerms
+    family1\tfather1\t0\t0\tM\tN\tWES\tfather1\t.
+    family1\tindex1\tfather1\t0\tM\tY\tWES\tindex1\t.
+    """.lstrip()))
+
 @pytest.fixture
 def tsv_sheet_germline_inconsistent_pedigree():
     """Example TSV germline sheet with inconsistent pedigree definition.
@@ -418,13 +464,25 @@ def test_cohorts(sheet_germline):
 def test_sheet_germline_inconsistent_pedigree(
     tsv_sheet_germline_inconsistent_pedigree,
     tsv_sheet_germline_trio_plus,
+    tsv_sheet_germline_duo_w_mother,
+    tsv_sheet_germline_duo_w_father,
+
 ):
     """Tests Germline sheet for sheet with conflict information for joint field and row."""
-    # Sanity check
+    # Sanity checks
     shortcuts.GermlineCaseSheet(
         sheet=io_tsv.read_germline_tsv_sheet(tsv_sheet_germline_trio_plus),
         join_by_field='familyId'
     )
+    shortcuts.GermlineCaseSheet(
+        sheet=io_tsv.read_germline_tsv_sheet(tsv_sheet_germline_duo_w_mother),
+        join_by_field='familyId'
+    )
+    shortcuts.GermlineCaseSheet(
+        sheet=io_tsv.read_germline_tsv_sheet(tsv_sheet_germline_duo_w_father),
+        join_by_field='familyId'
+    )
+
     # Expect error as each member of the pedigree has its own `familyId` instead of a common one
     with pytest.raises(InconsistentPedigreeException):
         shortcuts.GermlineCaseSheet(