diff options
author | zsloan | 2019-09-20 13:13:03 -0500 |
---|---|---|
committer | GitHub | 2019-09-20 13:13:03 -0500 |
commit | a708a0097e29509b209494e21a09f49d79467750 (patch) | |
tree | 3d8fe0530ee36ec65a72ed5196a6e0243c5c1c71 /wqflask/utility | |
parent | ff67d4bb0e15339697e97c918df1f1cc4385dce6 (diff) | |
parent | 78d3086c3978525065d91c0e02f2c2e0583f8705 (diff) | |
download | genenetwork2-a708a0097e29509b209494e21a09f49d79467750.tar.gz |
Merge branch 'testing' into 360_update_htmlgen
Diffstat (limited to 'wqflask/utility')
-rw-r--r-- | wqflask/utility/gen_geno_ob.py | 270 | ||||
-rw-r--r-- | wqflask/utility/tools.py | 9 | ||||
-rw-r--r-- | wqflask/utility/type_checking.py | 2 |
3 files changed, 145 insertions, 136 deletions
diff --git a/wqflask/utility/gen_geno_ob.py b/wqflask/utility/gen_geno_ob.py index 5824b0b3..5172369f 100644 --- a/wqflask/utility/gen_geno_ob.py +++ b/wqflask/utility/gen_geno_ob.py @@ -1,135 +1,137 @@ -from __future__ import absolute_import, division, print_function
-
-class genotype(object):
- """
- Replacement for reaper.Dataset so we can remove qtlreaper use while still generating mapping output figure
- """
-
- def __init__(self, filename):
- self.group = None
- self.type = "riset"
- self.prgy = []
- self.nprgy = 0
- self.mat = -1
- self.pat = 1
- self.het = 0
- self.unk = "U"
- self.filler = False
- self.mb_exists = False
-
- #ZS: This is because I'm not sure if some files switch the column that contains Mb/cM positions; might be unnecessary
- self.cm_column = 2
- self.mb_column = 3
-
- self.chromosomes = []
-
- self.read_file(filename)
-
- def __iter__(self):
- return iter(self.chromosomes)
-
- def __getitem__(self, index):
- return self.chromosomes[index]
-
- def __len__(self):
- return len(self.chromosomes)
-
- def read_file(self, filename):
-
- with open(filename, 'r') as geno_file:
- lines = geno_file.readlines()
-
- this_chr = "" #ZS: This is so it can track when the chromosome changes as it iterates through markers
- chr_ob = None
- for line in lines:
- if line[0] == "#":
- continue
- elif line[0] == "@":
- label = line.split(":")[0][1:]
- if label == "name":
- self.group = line.split(":")[1]
- elif label == "filler":
- if line.split(":")[1] == "yes":
- self.filler = True
- elif label == "type":
- self.type = line.split(":")[1]
- elif label == "mat":
- self.mat = line.split(":")[1]
- elif label == "pat":
- self.pat = line.split(":")[1]
- elif label == "het":
- self.het = line.split(":")[1]
- elif label == "unk":
- self.unk = line.split(":")[1]
- else:
- continue
- elif line[:3] == "Chr":
- header_row = line.split("\t")
- if header_row[2] == "Mb":
- self.mb_exists = True
- self.mb_column = 2
- self.cm_column = 3
- elif header_row[3] == "Mb":
- self.mb_exists = True
- self.mb_column = 3
- elif header_row[2] == "cM":
- self.cm_column = 2
-
- if self.mb_exists:
- self.prgy = header_row[4:]
- else:
- self.prgy = header_row[3:]
- self.nprgy = len(self.prgy)
- else:
- if line.split("\t")[0] != this_chr:
- if this_chr != "":
- self.chromosomes.append(chr_ob)
- this_chr = line.split("\t")[0]
- chr_ob = Chr(line.split("\t")[0], self)
- chr_ob.add_marker(line.split("\t"))
-
-class Chr(object):
- def __init__(self, name, geno_ob):
- self.name = name
- self.loci = []
- self.mb_exists = geno_ob.mb_exists
- self.cm_column = geno_ob.cm_column
- self.mb_column = geno_ob.mb_column
- self.geno_ob = geno_ob
-
- def __iter__(self):
- return iter(self.loci)
-
- def __getitem__(self, index):
- return self.loci[index]
-
- def __len__(self):
- return len(self.loci)
-
- def add_marker(self, marker_row):
- self.loci.append(Locus(marker_row, self.geno_ob))
-
-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"
- }
-
- 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
+from __future__ import absolute_import, division, print_function + +class genotype(object): + """ + Replacement for reaper.Dataset so we can remove qtlreaper use while still generating mapping output figure + """ + + def __init__(self, filename): + self.group = None + self.type = "riset" + self.prgy = [] + self.nprgy = 0 + self.mat = -1 + self.pat = 1 + self.het = 0 + self.unk = "U" + self.filler = False + self.mb_exists = False + + #ZS: This is because I'm not sure if some files switch the column that contains Mb/cM positions; might be unnecessary + self.cm_column = 2 + self.mb_column = 3 + + self.chromosomes = [] + + self.read_file(filename) + + def __iter__(self): + return iter(self.chromosomes) + + def __getitem__(self, index): + return self.chromosomes[index] + + def __len__(self): + return len(self.chromosomes) + + def read_file(self, filename): + + with open(filename, 'r') as geno_file: + lines = geno_file.readlines() + + this_chr = "" #ZS: This is so it can track when the chromosome changes as it iterates through markers + chr_ob = None + for line in lines: + if line[0] == "#": + continue + elif line[0] == "@": + label = line.split(":")[0][1:] + if label == "name": + self.group = line.split(":")[1] + elif label == "filler": + if line.split(":")[1] == "yes": + self.filler = True + elif label == "type": + self.type = line.split(":")[1] + elif label == "mat": + self.mat = line.split(":")[1] + elif label == "pat": + self.pat = line.split(":")[1] + elif label == "het": + self.het = line.split(":")[1] + elif label == "unk": + self.unk = line.split(":")[1] + else: + continue + elif line[:3] == "Chr": + header_row = line.split("\t") + if header_row[2] == "Mb": + self.mb_exists = True + self.mb_column = 2 + self.cm_column = 3 + elif header_row[3] == "Mb": + self.mb_exists = True + self.mb_column = 3 + elif header_row[2] == "cM": + self.cm_column = 2 + + if self.mb_exists: + self.prgy = header_row[4:] + else: + self.prgy = header_row[3:] + self.nprgy = len(self.prgy) + else: + if line.split("\t")[0] != this_chr: + if this_chr != "": + self.chromosomes.append(chr_ob) + this_chr = line.split("\t")[0] + chr_ob = Chr(line.split("\t")[0], self) + chr_ob.add_marker(line.split("\t")) + + self.chromosomes.append(chr_ob) + +class Chr(object): + def __init__(self, name, geno_ob): + self.name = name + self.loci = [] + self.mb_exists = geno_ob.mb_exists + self.cm_column = geno_ob.cm_column + self.mb_column = geno_ob.mb_column + self.geno_ob = geno_ob + + def __iter__(self): + return iter(self.loci) + + def __getitem__(self, index): + return self.loci[index] + + def __len__(self): + return len(self.loci) + + def add_marker(self, marker_row): + self.loci.append(Locus(marker_row, self.geno_ob)) + +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" + } + + 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 diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 8b2260f5..ec9f01bd 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -107,6 +107,9 @@ def js_path(module=None): return try_guix raise "No JS path found for "+module+" (if not in Guix check JS_GN_PATH)" +def reaper_command(guess=None): + return get_setting("REAPER_COMMAND",guess) + def gemma_command(guess=None): return assert_bin(get_setting("GEMMA_COMMAND",guess)) @@ -274,6 +277,7 @@ SMTP_CONNECT = get_setting('SMTP_CONNECT') SMTP_USERNAME = get_setting('SMTP_USERNAME') SMTP_PASSWORD = get_setting('SMTP_PASSWORD') +REAPER_COMMAND = app_set("REAPER_COMMAND",reaper_command()) GEMMA_COMMAND = app_set("GEMMA_COMMAND",gemma_command()) assert(GEMMA_COMMAND is not None) PLINK_COMMAND = app_set("PLINK_COMMAND",plink_command()) @@ -285,11 +289,14 @@ assert_dir(TEMPDIR) JS_GUIX_PATH = get_setting("JS_GUIX_PATH") assert_dir(JS_GUIX_PATH) assert_dir(JS_GUIX_PATH+'/cytoscape-panzoom') + CSS_PATH = "UNKNOWN" # assert_dir(JS_PATH) -JS_TWITTER_POST_FETCHER_PATH = get_setting("JS_TWITTER_POST_FETCHER_PATH",js_path("Twitter-Post-Fetcher")) + +JS_TWITTER_POST_FETCHER_PATH = get_setting("JS_TWITTER_POST_FETCHER_PATH",js_path("javascript-twitter-post-fetcher")) assert_dir(JS_TWITTER_POST_FETCHER_PATH) assert_file(JS_TWITTER_POST_FETCHER_PATH+"/js/twitterFetcher_min.js") + JS_CYTOSCAPE_PATH = get_setting("JS_CYTOSCAPE_PATH",js_path("cytoscape")) assert_dir(JS_CYTOSCAPE_PATH) assert_file(JS_CYTOSCAPE_PATH+'/cytoscape.min.js') diff --git a/wqflask/utility/type_checking.py b/wqflask/utility/type_checking.py index 220e5f62..f15b17e2 100644 --- a/wqflask/utility/type_checking.py +++ b/wqflask/utility/type_checking.py @@ -27,7 +27,7 @@ def get_float(vars,name,default=None): if name in vars: if is_float(vars[name]): return float(vars[name]) - return None + return default def get_int(vars,name,default=None): if name in vars: |