aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/gen_geno_ob.py
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask/utility/gen_geno_ob.py')
-rw-r--r--wqflask/utility/gen_geno_ob.py106
1 files changed, 75 insertions, 31 deletions
diff --git a/wqflask/utility/gen_geno_ob.py b/wqflask/utility/gen_geno_ob.py
index 5172369f..23b0b650 100644
--- a/wqflask/utility/gen_geno_ob.py
+++ b/wqflask/utility/gen_geno_ob.py
@@ -1,5 +1,8 @@
from __future__ import absolute_import, division, print_function
+import utility.logger
+logger = utility.logger.getLogger(__name__ )
+
class genotype(object):
"""
Replacement for reaper.Dataset so we can remove qtlreaper use while still generating mapping output figure
@@ -34,8 +37,36 @@ class genotype(object):
def __len__(self):
return len(self.chromosomes)
- def read_file(self, filename):
+ def read_rdata_output(self, qtl_results):
+ #ZS: This is necessary because R/qtl requires centimorgan marker positions, which it normally gets from the .geno file, but that doesn't exist for HET3-ITP (which only has RData), so it needs to read in the marker cM positions from the results
+ self.chromosomes = [] #ZS: Overwriting since the .geno file's contents are just placeholders
+
+ this_chr = "" #ZS: This is so it can track when the chromosome changes as it iterates through markers
+ chr_ob = None
+ for marker in qtl_results:
+ locus = Locus(self)
+ if (str(marker['chr']) != this_chr) and this_chr != "X": #ZS: This is really awkward but works as a temporary fix
+ if this_chr != "":
+ self.chromosomes.append(chr_ob)
+ this_chr = str(marker['chr'])
+ if this_chr == "20":
+ this_chr = "X"
+ chr_ob = Chr(this_chr, self)
+ if 'chr' in marker:
+ locus.chr = str(marker['chr'])
+ if 'name' in marker:
+ locus.name = marker['name']
+ if 'Mb' in marker:
+ locus.Mb = marker['Mb']
+ if 'cM' in marker:
+ locus.cM = marker['cM']
+ chr_ob.loci.append(locus)
+
+ self.chromosomes.append(chr_ob)
+
+ return self
+ def read_file(self, filename):
with open(filename, 'r') as geno_file:
lines = geno_file.readlines()
@@ -47,20 +78,20 @@ class genotype(object):
elif line[0] == "@":
label = line.split(":")[0][1:]
if label == "name":
- self.group = line.split(":")[1]
+ self.group = line.split(":")[1].strip()
elif label == "filler":
- if line.split(":")[1] == "yes":
+ if line.split(":")[1].strip() == "yes":
self.filler = True
elif label == "type":
- self.type = line.split(":")[1]
+ self.type = line.split(":")[1].strip()
elif label == "mat":
- self.mat = line.split(":")[1]
+ self.mat = line.split(":")[1].strip()
elif label == "pat":
- self.pat = line.split(":")[1]
+ self.pat = line.split(":")[1].strip()
elif label == "het":
- self.het = line.split(":")[1]
+ self.het = line.split(":")[1].strip()
elif label == "unk":
- self.unk = line.split(":")[1]
+ self.unk = line.split(":")[1].strip()
else:
continue
elif line[:3] == "Chr":
@@ -109,29 +140,42 @@ class Chr(object):
return len(self.loci)
def add_marker(self, marker_row):
- self.loci.append(Locus(marker_row, self.geno_ob))
+ self.loci.append(Locus(self.geno_ob, marker_row))
class Locus(object):
- def __init__(self, marker_row, geno_ob):
- self.chr = marker_row[0]
- self.name = marker_row[1]
- self.cM = float(marker_row[geno_ob.cm_column])
- self.Mb = float(marker_row[geno_ob.mb_column]) if geno_ob.mb_exists else None
-
- geno_table = {
- geno_ob.mat: -1,
- geno_ob.pat: 1,
- geno_ob.het: 0,
- geno_ob.unk: "U"
- }
-
+ def __init__(self, geno_ob, marker_row = None):
+ self.chr = None
+ self.name = None
+ self.cM = None
+ self.Mb = None
self.genotype = []
- if geno_ob.mb_exists:
- start_pos = 4
- else:
- start_pos = 3
- for allele in marker_row[start_pos:]:
- if allele in geno_table.keys():
- self.genotype.append(geno_table[allele])
- else: #ZS: Some genotype appears that isn't specified in the metadata, make it unknown
- self.genotype.append("U") \ No newline at end of file
+ if marker_row:
+ self.chr = marker_row[0]
+ self.name = marker_row[1]
+ try:
+ self.cM = float(marker_row[geno_ob.cm_column])
+ except:
+ self.cM = float(marker_row[geno_ob.mb_column]) if geno_ob.mb_exists else 0
+ try:
+ self.Mb = float(marker_row[geno_ob.mb_column]) if geno_ob.mb_exists else None
+ except:
+ self.Mb = self.cM
+
+ geno_table = {
+ geno_ob.mat: -1,
+ geno_ob.pat: 1,
+ geno_ob.het: 0,
+ geno_ob.unk: "U"
+ }
+
+ self.genotype = []
+ if geno_ob.mb_exists:
+ start_pos = 4
+ else:
+ start_pos = 3
+
+ for allele in marker_row[start_pos:]:
+ if allele in geno_table.keys():
+ self.genotype.append(geno_table[allele])
+ else: #ZS: Some genotype appears that isn't specified in the metadata, make it unknown
+ self.genotype.append("U") \ No newline at end of file