aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/external_tools/send_to_bnw.py
blob: fdbc0d9349ea5208f8e9440f5400e988966192ad (plain)
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
# 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 gn2.base.trait import GeneralTrait
from gn2.utility import helper_functions, corr_result_helpers


class SendToBNW:
    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)

        trait_samples_list = []

        for trait_db in self.trait_list:
            trait_1 = trait_db[0]
            this_sample_data = trait_1.data

            trait1_samples = list(this_sample_data.keys())
            trait_samples_list.append(trait1_samples)

        shared_samples = list(
            set(trait_samples_list[0]).intersection(*trait_samples_list))

        self.form_value = ""  # ZS: string that is passed to BNW through form
        values_list = []
        for trait_db in self.trait_list:
            this_trait = trait_db[0]
            this_sample_data = this_trait.data

            trait_vals = []
            for sample in this_sample_data:
                if sample in shared_samples:
                    trait_vals.append(this_sample_data[sample].value)

            values_list.append(trait_vals)
            self.form_value += "_" + str(this_trait.name) + ","

        values_list = zip(*values_list)
        self.form_value = self.form_value[:-1]
        self.form_value += ";"

        for row in values_list:
            has_none = False
            for cell in row:
                if not cell:
                    has_none = True
                    break
            if has_none:
                continue
            self.form_value += ",".join(str(cell) for cell in row)
            self.form_value += ";"