aboutsummaryrefslogtreecommitdiff
path: root/wqflask/base/webqtlDataset.py
blob: f8491bb15c3e0034b283dc5d201e343fa8c35744 (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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# 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 Drs. Robert W. Williams and Xiaodong Zhou (2010)
# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
#
#
#
# This module is used by GeneNetwork project (www.genenetwork.org)
#
# Created by GeneNetwork Core Team 2010/08/10
#
# Last updated by GeneNetwork Core Team 2010/10/20

from htmlgen import HTMLgen2 as HT

import webqtlConfig



class webqtlDataset:
    """
    Database class defines a database in webqtl, can be either Microarray,
    Published phenotype, genotype, or user input database(temp)
    """

    def __init__(self, dbName, cursor=None):

        assert dbName
        self.id = 0
        self.name = ''
        self.type = ''
        self.riset = ''
        self.cursor = cursor

        #temporary storage
        if dbName.find('Temp') >= 0:
            self.searchfield = ['name','description']
            self.disfield = ['name','description']
            self.type = 'Temp'
            self.id = 1
            self.fullname = 'Temporary Storage'
            self.shortname = 'Temp'
        elif dbName.find('Publish') >= 0:
            self.searchfield = ['name','post_publication_description','abstract','title','authors']
            self.disfield = ['name','pubmed_id',
                            'pre_publication_description', 'post_publication_description', 'original_description',
                            'pre_publication_abbreviation', 'post_publication_abbreviation',
                            'lab_code', 'submitter', 'owner', 'authorized_users',
                            'authors','title','abstract', 'journal','volume','pages','month',
                            'year','sequence', 'units', 'comments']
            self.type = 'Publish'
        elif dbName.find('Geno') >= 0:
            self.searchfield = ['name','chr']
            self.disfield = ['name','chr','mb', 'source2', 'sequence']
            self.type = 'Geno'
        else: #ProbeSet
            self.searchfield = ['name','description','probe_target_description',
                    'symbol','alias','genbankid','unigeneid','omim',
                    'refseq_transcriptid','probe_set_specificity', 'probe_set_blat_score']
            self.disfield = ['name','symbol','description','probe_target_description',
                    'chr','mb','alias','geneid','genbankid', 'unigeneid', 'omim',
                    'refseq_transcriptid','blatseq','targetseq','chipid', 'comments',
                    'strand_probe','strand_gene','probe_set_target_region',
                    'probe_set_specificity', 'probe_set_blat_score','probe_set_blat_mb_start',
                    'probe_set_blat_mb_end', 'probe_set_strand',
                    'probe_set_note_by_rw', 'flag']
            self.type = 'ProbeSet'
        self.name = dbName
        if self.cursor and self.id == 0:
            self.retrieveName()

    def __str__(self):
        return self.name

    __repr__ = __str__


    def getRISet(self):
        assert self.cursor
        if self.type == 'Publish':
            query = '''
                            SELECT
                                    InbredSet.Name, InbredSet.Id
                            FROM
                                    InbredSet, PublishFreeze
                            WHERE
                                    PublishFreeze.InbredSetId = InbredSet.Id AND
                                    PublishFreeze.Name = "%s"
                    ''' % self.name
        elif self.type == 'Geno':
            query = '''
                            SELECT
                                    InbredSet.Name, InbredSet.Id
                            FROM
                                    InbredSet, GenoFreeze
                            WHERE
                                    GenoFreeze.InbredSetId = InbredSet.Id AND
                                    GenoFreeze.Name = "%s"
                    ''' % self.name
        elif self.type == 'ProbeSet':
            query = '''
                            SELECT
                                    InbredSet.Name, InbredSet.Id
                            FROM
                                    InbredSet, ProbeSetFreeze, ProbeFreeze
                            WHERE
                                    ProbeFreeze.InbredSetId = InbredSet.Id AND
                                    ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId AND
                                    ProbeSetFreeze.Name = "%s"
                    ''' % self.name
        else:
            return ""
        self.cursor.execute(query)
        RISet, RIID = self.cursor.fetchone()
        if RISet == 'BXD300':
            RISet = "BXD"
        self.riset = RISet
        self.risetid = RIID
        return RISet


    def retrieveName(self):
        assert self.id == 0 and self.cursor
        query = '''
                SELECT
                        Id, Name, FullName, ShortName
                FROM
                        %sFreeze
                WHERE
                        public > %d AND
                        (Name = "%s" OR FullName = "%s" OR ShortName = "%s")
          '''% (self.type, webqtlConfig.PUBLICTHRESH, self.name, self.name, self.name)
        try:
            self.cursor.execute(query)
            self.id,self.name,self.fullname,self.shortname=self.cursor.fetchone()
        except:
            raise KeyError, `self.name`+' doesn\'t exist.'


    def genHTML(self, Class='c0dd'):
        return  HT.Href(text = HT.Span('%s Database' % self.fullname, Class= "fwb " + Class),
                url= webqtlConfig.INFOPAGEHREF % self.name,target="_blank")