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 notes = models.TextField(blank=True)
49 return '%s' % (self.cellline_name)
52 ordering = ["cellline_name"]
55 list_display = ('cellline_name','notes')
58 'fields': (('cellline_name'),('notes'),)
62 class Condition(models.Model):
63 condition_name = models.CharField(max_length=2000, unique=True, db_index=True)
64 notes = models.TextField(blank=True)
66 return '%s' % (self.condition_name)
69 ordering = ["condition_name"]
72 list_display = ('condition_name','notes')
75 'fields': (('condition_name'),('notes'),)
79 class Species(models.Model):
80 scientific_name = models.CharField(max_length=256, unique=False, db_index=True, core=True)
81 common_name = models.CharField(max_length=256, blank=True)
82 use_genome_build = models.CharField(max_length=100, blank=False, null=False)
85 return '%s (%s)|%s' % (self.scientific_name, self.common_name, self.use_genome_build)
88 verbose_name_plural = "species"
89 ordering = ["scientific_name"]
94 'fields': (('scientific_name', 'common_name'), ('use_genome_build'))
98 class Affiliation(models.Model):
99 name = models.CharField(max_length=256, db_index=True, core=True,verbose_name='Group Name')
100 contact = models.CharField(max_length=256, null=True, blank=True,verbose_name='Contact Name')
101 email = models.EmailField(null=True,blank=True)
105 if self.contact != '':
106 str += ' ('+self.contact+')'
110 ordering = ["name","contact"]
111 unique_together = (("name", "contact"),)
114 list_display = ('name','contact','email')
117 'fields': (('name','contact','email'))
121 class Library(models.Model):
122 library_id = models.CharField(max_length=30, unique=True, db_index=True, core=True)
123 library_name = models.CharField(max_length=100, unique=True, core=True)
124 library_species = models.ForeignKey(Species, core=True)
125 cell_line = models.ForeignKey(Cellline,core=True)
126 condition = models.ForeignKey(Condition,core=True)
127 antibody = models.ForeignKey(Antibody,blank=True,null=True,core=True)
128 # New field Aug/25/08. SQL: alter table fctracker_library add column "lib_affiliation" varchar(256) NULL;
129 affiliations = models.ManyToManyField(Affiliation,related_name='library_affiliations',null=True,filter_interface=models.HORIZONTAL)
130 # New field Aug/19/08
131 # SQL to add column: alter table fctracker_library add column "replicate" smallint unsigned NULL;
132 REPLICATE_NUM = ((1,1),(2,2),(3,3),(4,4))
133 replicate = models.PositiveSmallIntegerField(choices=REPLICATE_NUM,default=1)
136 ('INPUT_RXLCh','INPUT_RXLCh'),
137 ('ChIP-seq', 'ChIP-seq'),
138 ('Sheared', 'Sheared'),
139 ('RNA-seq', 'RNA-seq'),
140 ('Methyl-seq', 'Methyl-seq'),
141 ('DIP-seq', 'DIP-seq'),
143 experiment_type = models.CharField(max_length=50, choices=EXPERIMENT_TYPES, default='ChIP-seq')
145 creation_date = models.DateField(blank=True, null=True)
146 made_for = models.CharField(max_length=50, blank=True,verbose_name = 'ChIP/DNA/RNA Made By')
147 made_by = models.CharField(max_length=50, blank=True,verbose_name = 'Library Made By')
149 PROTOCOL_END_POINTS = (
150 ('Completed','Completed'),
152 ('Sample', 'Raw sample'),
153 ('Progress', 'In progress'),
154 ('1A', 'Ligation, then gel'),
155 ('PCR', 'Ligation, then PCR'),
156 ('1Ab', 'Ligation, PCR, then gel'),
157 ('1Aa', 'Ligation, gel, then PCR'),
158 ('2A', 'Ligation, PCR, gel, PCR'),
160 stopping_point = models.CharField(max_length=50, choices=PROTOCOL_END_POINTS, default='Completed')
161 amplified_from_sample = models.ForeignKey('self', blank=True, null=True)
163 undiluted_concentration = models.DecimalField("Template concentr. (ng/ul)",max_digits=5, decimal_places=2, blank=True, null=True)
164 ten_nM_dilution = models.BooleanField()
165 successful_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=True, null=True)
166 avg_lib_size = models.IntegerField(default=225, blank=True, null=True)
167 notes = models.TextField(blank=True)
170 return '%s: %s' % (self.library_id, self.library_name)
173 verbose_name_plural = "libraries"
174 ordering = ["-creation_date"] #["-library_id"]
176 def antibody_name(self):
177 return self.antibody.nickname
180 return self.library_species.common_name
182 def affiliation(self):
183 affs = self.affiliations.all().order_by('name')
187 ar.append(t.__str__())
188 return '%s' % (", ".join(ar))
191 def aligned_reads(self):
192 res = getLibReads(self.library_id)
193 rc = "%1.2f" % (res[1]/1000000.0)
194 # Color Scheme: green is more than 10M, blue is more than 5M, orange is more than 3M and red is less. For RNAseq, all those thresholds should be doubled
196 bgcolor = '#ff3300' # Red
197 rc_thr = [10000000,5000000,3000000]
198 if self.experiment_type == 'RNA-seq':
199 rc_thr = [20000000,10000000,6000000]
201 if res[1] > rc_thr[0]:
202 bgcolor = '#66ff66' # Green
204 if res[1] > rc_thr[1]:
205 bgcolor ='#00ccff' # Blue
207 if res[1] > rc_thr[2]:
208 bgcolor ='#ffcc33' # Orange
209 tstr = '<div style="background-color:'+bgcolor+';color:black">'
210 tstr += res[0].__str__()+' Lanes, '+rc+' M Reads'
212 else: tstr = 'not processed yet'
214 aligned_reads.allow_tags = True
217 date_hierarchy = "creation_date"
220 ##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']
221 search_fields = ['library_id','library_name','cell_line__cellline_name','library_species__scientific_name','library_species__common_name','library_species__use_genome_build']
222 list_display = ('affiliation','library_id','aligned_reads','library_name','experiment_type','org','replicate','antibody_name','cell_line','made_by','creation_date')
223 list_display_links = ('library_id', 'library_name')
224 list_filter = ('experiment_type','affiliations','library_species','made_for', 'made_by','replicate')
227 'fields': (('replicate','library_id','library_name'),('library_species'),('experiment_type'),('cell_line','condition','antibody'),)
229 ('Creation Information:', {
230 'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('avg_lib_size','undiluted_concentration', 'ten_nM_dilution', 'successful_pM'), 'notes',)
232 ('Library/Project Affiliation:', {
233 'fields' : (('affiliations'),)