From 2c7499b42640d0396f203cd0d680fa7c404521ec Mon Sep 17 00:00:00 2001
From: Floreal Cabanettes <floreal.cabanettes@inra.fr>
Date: Fri, 25 Aug 2017 15:57:49 +0200
Subject: [PATCH] Fix genotypes in build results

---
 build_results.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/build_results.py b/build_results.py
index af9fb38..dc33194 100755
--- a/build_results.py
+++ b/build_results.py
@@ -174,9 +174,10 @@ def get_genotypes(genotypes_file, true_vcf_file):
 
     # Real data:
     reader_t = VariantFile(true_vcf_file)
+    samples_t = None
     for rec_t in reader_t:
-        samples = rec_t.samples
-        genotypes[rec_t.id] = ["/".join(map(str, samples[x]["GT"])) for x in samples]
+        samples_t = rec_t.samples
+        genotypes[rec_t.id] = ["/".join(map(str, samples_t[x]["GT"])) for x in samples_t]
 
     nb_inds = len(list(genotypes.values())[0])
 
@@ -184,8 +185,9 @@ def get_genotypes(genotypes_file, true_vcf_file):
     reader = VariantFile(genotypes_file)
     for rec in reader:
         samples = rec.samples
-        genotypes[rec.id] = ["/".join(map(str, samples[x]["GT"])) for x in samples]
-        gt_quality[rec.id] = [samples[x]["GQ"] for x in samples]
+        genotypes[rec.id] = ["/".join(map(str, samples[x]["GT"])) for x in samples_t.keys()]  # Fixed: use samples keys
+        # from real data to keep the same order
+        gt_quality[rec.id] = [samples[x]["GQ"] for x in samples_t.keys()]
 
     return genotypes, gt_quality, nb_inds
 
-- 
GitLab