1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# This program is available from Source Forge: at GeneNetwork Project
# (sourceforge.net/projects/genenetwork/).
#
# Contact Dr. Robert W. Williams at rwilliams@uthsc.edu
#
#
# This module is used by GeneNetwork project (www.genenetwork.org)
from pprint import pformat as pf
from base.trait import create_trait
from base import data_set
from utility import webqtlUtil, helper_functions, corr_result_helpers
import utility.webqtlUtil # this is for parallel computing only.
from wqflask.correlation import correlation_functions
from MySQLdb import escape_string as escape
from flask import Flask, g
class ComparisonBarChart:
def __init__(self, start_vars):
trait_db_list = [trait.strip()
for trait in start_vars['trait_list'].split(',')]
helper_functions.get_trait_db_obs(self, trait_db_list)
self.all_sample_list = []
self.traits = []
self.insufficient_shared_samples = False
# ZS: Getting initial group name before verifying all traits are in the same group in the following loop
this_group = self.trait_list[0][1].group.name
for trait_db in self.trait_list:
if trait_db[1].group.name != this_group:
self.insufficient_shared_samples = True
break
else:
this_group = trait_db[1].group.name
this_trait = trait_db[0]
self.traits.append(this_trait)
this_sample_data = this_trait.data
for sample in this_sample_data:
if sample not in self.all_sample_list:
self.all_sample_list.append(sample)
if self.insufficient_shared_samples:
pass
else:
self.sample_data = []
for trait_db in self.trait_list:
this_trait = trait_db[0]
this_sample_data = this_trait.data
this_trait_vals = []
for sample in self.all_sample_list:
if sample in this_sample_data:
this_trait_vals.append(this_sample_data[sample].value)
else:
this_trait_vals.append('')
self.sample_data.append(this_trait_vals)
self.js_data = dict(traits=[trait.name for trait in self.traits],
samples=self.all_sample_list,
sample_data=self.sample_data,)
def get_trait_db_obs(self, trait_db_list):
self.trait_list = []
for i, trait_db in enumerate(trait_db_list):
if i == (len(trait_db_list) - 1):
break
trait_name, dataset_name = trait_db.split(":")
#print("dataset_name:", dataset_name)
dataset_ob = data_set.create_dataset(dataset_name)
trait_ob = create_trait(dataset=dataset_ob,
name=trait_name,
cellid=None)
self.trait_list.append((trait_ob, dataset_ob))
#print("trait_list:", self.trait_list)
|