# -*- coding: utf-8 -*-


def parse_mipsex(qcm_data):
    """Parse out sample sex from qc metrics data."""
    samples_sex = parse_samples(qcm_data)
    sexes = {sample_id: sex for sample_id, sex in samples_sex}
    return sexes


def parse_samples(qcm_data):
    """Parse out the relevant sample information."""
    fam_key = list(qcm_data.keys())[0]
    for segment_id, values in qcm_data[fam_key].items():
        if segment_id != fam_key:
            # sample data entry, find main section
            for sebsection_id, data in values.items():
                if '_lanes_' in sebsection_id:
                    yield segment_id, data['ChanjoSexCheck']['gender']

@@ -302,24 +302,361 @@
 rmation.%22%22%22%0A
+    if 'sample' in qcm_data:%0A        # it's a MIP 4 analysis!%0A        for sample_id, values in qcm_data%5B'sample'%5D.items():%0A            for segment_id, data in values.items():%0A                if '_lanes_' in segment_id:%0A                    yield sample_id, data%5B'chanjo_sexcheck'%5D%5B'gender'%5D%0A    else:%0A        # it's a MIP 3 analysis!%0A    
     fam_key 
@@ -682,24 +682,28 @@
 s())%5B0%5D%0A    
+  
+  
 for segment_
@@ -735,32 +735,36 @@
 m_key%5D.items():%0A
+    
         if segme
@@ -793,16 +793,20 @@
         
+    
 # sample
@@ -844,24 +844,28 @@
             
+ 
+   
 for sebsecti
@@ -903,32 +903,36 @@
                 
+    
 if '_lanes_' in 
@@ -942,24 +942,28 @@
 section_id:%0A
+    
             

support mip4 for parsing chanjo sex