1 from django.db import models
2 from htswfrontend import settings
3 from htswfrontend.htsw_reports.libinfopar import *
5 class Primer(models.Model):
6 primer_name = models.CharField(max_length=100, db_index=True)
7 primer_seq = models.CharField(max_length=50, blank=True, null=True)
8 notes = models.TextField(blank=True)
10 return '%s' % (self.primer_name)
12 ordering = ["primer_name"]
14 list_display = ('primer_name','primer_seq','notes')
17 'fields': (('primer_name'),('primer_seq'),('notes'))
21 class Antibody(models.Model):
22 antigene = models.CharField(max_length=500, db_index=True)
24 # SQL to add column: alter table fctracker_antibody add column "nickname" varchar(20) NULL;
25 nickname = models.CharField(max_length=20,blank=True,null=True, db_index=True,verbose_name = 'Short Name')
26 catalog = models.CharField(max_length=50, unique=True, db_index=True)
27 antibodies = models.CharField(max_length=500, db_index=True)
28 source = models.CharField(max_length=500, blank=True, db_index=True)
29 biology = models.TextField(blank=True)
30 notes = models.TextField(blank=True)
32 return '%s - %s (%s)' % (self.antigene, self.antibodies, self.catalog)
34 verbose_name_plural = "antibodies"
35 ordering = ["antigene"]
37 list_display = ('antigene','nickname','antibodies','catalog','source','biology','notes')
38 list_filter = ('antibodies','source')
41 'fields': (('antigene','nickname','antibodies'),('catalog','source'),('biology'),('notes'))
45 class Cellline(models.Model):
46 cellline_name = models.CharField(max_length=100, unique=True, db_index=True)
47 nickname = models.CharField(max_length=20,blank=True,null=True, db_index=True,verbose_name = 'Short Name')
48 notes = models.TextField(blank=True)
50 return '%s' % (self.cellline_name)
53 ordering = ["cellline_name"]
56 list_display = ('cellline_name','nickname','notes')
59 'fields': (('cellline_name','nickname'),('notes'),)
63 class Condition(models.Model):
64 condition_name = models.CharField(max_length=2000, unique=True, db_index=True)
65 nickname = models.CharField(max_length=20,blank=True,null=True, db_index=True,verbose_name = 'Short Name')
66 notes = models.TextField(blank=True)
68 return '%s' % (self.condition_name)
71 ordering = ["condition_name"]
74 list_display = ('condition_name','nickname','notes')
77 'fields': (('condition_name','nickname'),('notes'),)
81 class Species(models.Model):
82 scientific_name = models.CharField(max_length=256, unique=False, db_index=True, core=True)
83 common_name = models.CharField(max_length=256, blank=True)
84 use_genome_build = models.CharField(max_length=100, blank=False, null=False)
87 return '%s (%s)|%s' % (self.scientific_name, self.common_name, self.use_genome_build)
90 verbose_name_plural = "species"
91 ordering = ["scientific_name"]
96 'fields': (('scientific_name', 'common_name'), ('use_genome_build'))
100 class Affiliation(models.Model):
101 name = models.CharField(max_length=256, db_index=True, core=True,verbose_name='Group Name')
102 contact = models.CharField(max_length=256, null=True, blank=True,verbose_name='Contact Name')
103 email = models.EmailField(null=True,blank=True)
107 if self.contact != '':
108 str += ' ('+self.contact+')'
112 ordering = ["name","contact"]
113 unique_together = (("name", "contact"),)
116 list_display = ('name','contact','email')
119 'fields': (('name','contact','email'))
123 class Tag(models.Model):
124 tag_name = models.CharField(max_length=100, db_index=True,core=True,blank=False,null=False)
126 #('Antibody','Antibody'),
127 #('Cellline', 'Cellline'),
128 #('Condition', 'Condition'),
129 ('Library', 'Library'),
132 context = models.CharField(max_length=50, choices=TAG_CONTEXT, default='Library')
135 return '%s' % (self.tag_name)
138 ordering = ["context","tag_name"]
141 list_display = ('tag_name','context')
144 'fields': ('tag_name','context')
148 class Library(models.Model):
149 library_id = models.CharField(max_length=30, unique=True, db_index=True, core=True)
150 library_name = models.CharField(max_length=100, unique=True, core=True)
151 library_species = models.ForeignKey(Species, core=True)
152 cell_line = models.ForeignKey(Cellline,core=True)
153 condition = models.ForeignKey(Condition,core=True)
154 antibody = models.ForeignKey(Antibody,blank=True,null=True,core=True)
155 # New field Aug/25/08. SQL: alter table fctracker_library add column "lib_affiliation" varchar(256) NULL;
156 affiliations = models.ManyToManyField(Affiliation,related_name='library_affiliations',null=True,filter_interface=models.HORIZONTAL)
157 # New field Nov/14/08
158 tags = models.ManyToManyField(Tag,related_name='library_tags',blank=True,null=True,filter_interface=models.HORIZONTAL)
159 # New field Aug/19/08
160 # SQL to add column: alter table fctracker_library add column "replicate" smallint unsigned NULL;
161 REPLICATE_NUM = ((1,1),(2,2),(3,3),(4,4))
162 replicate = models.PositiveSmallIntegerField(choices=REPLICATE_NUM,default=1)
165 ('INPUT_RXLCh','INPUT_RXLCh'),
166 ('ChIP-seq', 'ChIP-seq'),
167 ('Sheared', 'Sheared'),
168 ('RNA-seq', 'RNA-seq'),
169 ('Methyl-seq', 'Methyl-seq'),
170 ('DIP-seq', 'DIP-seq'),
172 experiment_type = models.CharField(max_length=50, choices=EXPERIMENT_TYPES, default='ChIP-seq')
174 creation_date = models.DateField(blank=True, null=True)
175 made_for = models.CharField(max_length=50, blank=True,verbose_name = 'ChIP/DNA/RNA Made By')
176 made_by = models.CharField(max_length=50, blank=True,verbose_name = 'Library Made By')
178 PROTOCOL_END_POINTS = (
179 ('Completed','Completed'),
181 ('Sample', 'Raw sample'),
182 ('Progress', 'In progress'),
183 ('1A', 'Ligation, then gel'),
184 ('PCR', 'Ligation, then PCR'),
185 ('1Ab', 'Ligation, PCR, then gel'),
186 ('1Aa', 'Ligation, gel, then PCR'),
187 ('2A', 'Ligation, PCR, gel, PCR'),
189 stopping_point = models.CharField(max_length=50, choices=PROTOCOL_END_POINTS, default='Completed')
190 amplified_from_sample = models.ForeignKey('self', blank=True, null=True)
192 undiluted_concentration = models.DecimalField("Template concentr. (ng/ul)",max_digits=5, decimal_places=2, blank=True, null=True)
193 ten_nM_dilution = models.BooleanField()
194 successful_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=True, null=True)
195 avg_lib_size = models.IntegerField(default=225, blank=True, null=True)
196 notes = models.TextField(blank=True)
199 return '%s: %s' % (self.library_id, self.library_name)
202 verbose_name_plural = "libraries"
203 ordering = ["-creation_date"] #["-library_id"]
205 def antibody_name(self):
206 str ='<a target=_self href="/admin/fctracker/antibody/'+self.antibody.id.__str__()+'/" title="'+self.antibody.__str__()+'">'+self.antibody.nickname+'</a>'
208 antibody_name.allow_tags = True
211 return self.library_species.common_name
214 return self.condition.nickname
216 def affiliation(self):
217 affs = self.affiliations.all().order_by('name')
221 ar.append(t.__str__())
222 return '%s' % (", ".join(ar))
225 affs = self.tags.all().order_by('tag_name')
229 ar.append(t.__str__())
230 return '%s' % (", ".join(ar))
233 str ='<a target=_self href="/admin/exp_track/datarun/?q='+self.library_id+'" title="Check All Data Runs for This Specific Library ..." ">DataRuns ..</a>'
235 DataRun.allow_tags = True
237 def aligned_m_reads(self):
238 return getLibReads(self.library_id)
240 def aligned_reads(self):
241 res = getLibReads(self.library_id)
245 return '<div style="border:solid red 2px">'+res[2]+'</div>'
247 rc = "%1.2f" % (res[1]/1000000.0)
248 # Color Scheme: green is more than 12M, blue is more than 5M, orange is more than 3M and red is less. For RNAseq, all those thresholds should be doubled
250 bgcolor = '#ff3300' # Red, the color for minimum read count
251 rc_thr = [12000000,5000000,3000000]
252 if self.experiment_type == 'RNA-seq':
253 rc_thr = [20000000,10000000,6000000]
255 if res[1] > rc_thr[0]:
256 bgcolor = '#66ff66' # Green
258 if res[1] > rc_thr[1]:
259 bgcolor ='#00ccff' # Blue
261 if res[1] > rc_thr[2]:
262 bgcolor ='#ffcc33' # Orange
263 tstr = '<div style="background-color:'+bgcolor+';color:black">'
264 tstr += res[0].__str__()+' Lanes, '+rc+' M'
266 else: tstr = 'not processed yet'
268 aligned_reads.allow_tags = True
271 date_hierarchy = "creation_date"
274 ##search_fields = ['library_id','library_name','affiliations__name','affiliations__contact','made_by','made_for','antibody__antigene','antibody__catalog','antibody__antibodies','antibody__source','cell_line__cellline_name','library_species__scientific_name','library_species__common_name','library_species__use_genome_build']
275 search_fields = ['library_id','library_name','cell_line__cellline_name','library_species__scientific_name','library_species__common_name','library_species__use_genome_build']
276 list_display = ('affiliation','library_id','aligned_reads','DataRun','library_name','experiment_type','org','replicate','antibody_name','cell_line','cond','libtags','made_by','creation_date')
277 list_display_links = ('library_id', 'library_name')
278 list_filter = ('experiment_type','affiliations','library_species','tags','made_for', 'made_by','replicate','antibody','cell_line','condition')
281 'fields': (('replicate','library_id','library_name'),('library_species'),('experiment_type'),('cell_line','condition','antibody'),)
283 ('Creation Information:', {
284 'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('avg_lib_size','undiluted_concentration', 'ten_nM_dilution', 'successful_pM'), 'notes',)
286 ('Library/Project Affiliation:', {
287 'fields' : (('affiliations'),('tags'),)