Removed all Antibody related fields from the Library search_fields list. The Library...
[htsworkflow.git] / htswfrontend / htswfrontend / fctracker / models.py
1 from django.db import models
2 from htswfrontend import settings
3
4 class Primer(models.Model):
5   primer_name = models.CharField(max_length=100, db_index=True)
6   primer_seq = models.CharField(max_length=50, blank=True, null=True)
7   notes = models.TextField(blank=True)
8   def __str__(self):
9     return '%s' % (self.primer_name)
10   class Meta:
11     ordering = ["primer_name"]
12   class Admin:
13       list_display = ('primer_name','primer_seq','notes')
14       fields = (
15         (None, {
16             'fields': (('primer_name'),('primer_seq'),('notes'))
17         }),
18        )
19
20 class Antibody(models.Model):
21   antigene = models.CharField(max_length=500, db_index=True)
22   # New field Aug/20/08                                                                                                                                                            
23   # SQL to add column: alter table fctracker_antibody add column "nickname" varchar(20) NULL;
24   nickname = models.CharField(max_length=20,blank=True,null=True, db_index=True,verbose_name = 'Short Name')
25   catalog = models.CharField(max_length=50, unique=True, db_index=True)
26   antibodies = models.CharField(max_length=500, db_index=True)
27   source = models.CharField(max_length=500, blank=True, db_index=True)
28   biology = models.TextField(blank=True)
29   notes = models.TextField(blank=True)
30   def __str__(self):
31     return '%s - %s (%s)' % (self.antigene, self.antibodies, self.catalog)
32   class Meta:
33     verbose_name_plural = "antibodies"
34     ordering = ["antigene"]
35   class Admin:
36       list_display = ('antigene','nickname','antibodies','catalog','source','biology','notes')
37       list_filter = ('antibodies','source')
38       fields = (
39         (None, {
40             'fields': (('antigene','nickname','antibodies'),('catalog','source'),('biology'),('notes'))
41         }),
42        )
43
44 class Cellline(models.Model):
45   cellline_name = models.CharField(max_length=100, unique=True, db_index=True)
46   notes = models.TextField(blank=True)
47   def __str__(self):
48     return '%s' % (self.cellline_name)
49
50   class Meta:
51     ordering = ["cellline_name"]
52
53   class Admin:
54       list_display = ('cellline_name','notes')
55       fields = (
56         (None, {
57             'fields': (('cellline_name'),('notes'),)
58         }),
59        )
60
61 class Condition(models.Model):
62   condition_name = models.CharField(max_length=2000, unique=True, db_index=True)
63   notes = models.TextField(blank=True)
64   def __str__(self):
65     return '%s' % (self.condition_name)
66
67   class Meta:
68     ordering = ["condition_name"]
69
70   class Admin:
71       list_display = ('condition_name','notes')
72       fields = (
73         (None, {
74             'fields': (('condition_name'),('notes'),)
75         }),
76        )
77
78 class Species(models.Model):
79   scientific_name = models.CharField(max_length=256, unique=False, db_index=True, core=True)
80   common_name = models.CharField(max_length=256, blank=True)
81   use_genome_build = models.CharField(max_length=100, blank=False, null=False)
82
83   def __str__(self):
84     return '%s (%s)|%s' % (self.scientific_name, self.common_name, self.use_genome_build)
85   
86   class Meta:
87     verbose_name_plural = "species"
88     ordering = ["scientific_name"]
89   
90   class Admin:
91       fields = (
92         (None, {
93             'fields': (('scientific_name', 'common_name'), ('use_genome_build'))
94         }),
95       )
96
97 class Affiliation(models.Model):
98   name = models.CharField(max_length=256, db_index=True, core=True,verbose_name='Group Name')
99   contact = models.CharField(max_length=256, null=True, blank=True,verbose_name='Contact Name')  
100   email = models.EmailField(null=True,blank=True)
101   
102   def __str__(self):
103     str = self.name
104     if self.contact != '':
105       str += ' ('+self.contact+')' 
106     return str
107
108   class Meta:
109     ordering = ["name","contact"]
110     unique_together = (("name", "contact"),)
111
112   class Admin:
113       list_display = ('name','contact','email')
114       fields = (
115         (None, {
116             'fields': (('name','contact','email'))
117         }),
118       )
119
120 class Library(models.Model):
121   library_id = models.CharField(max_length=30, unique=True, db_index=True, core=True)
122   library_name = models.CharField(max_length=100, unique=True, core=True)
123   library_species = models.ForeignKey(Species, core=True)
124   cell_line = models.ForeignKey(Cellline,core=True)
125   condition = models.ForeignKey(Condition,core=True)
126   antibody = models.ForeignKey(Antibody,blank=True,null=True,core=True)
127   # New field Aug/25/08. SQL: alter table fctracker_library add column "lib_affiliation" varchar(256)  NULL;
128   affiliations = models.ManyToManyField(Affiliation,related_name='library_affiliations',null=True,filter_interface=models.HORIZONTAL)
129   # New field Aug/19/08
130   # SQL to add column: alter table fctracker_library add column "replicate" smallint unsigned NULL;
131   REPLICATE_NUM = ((1,1),(2,2),(3,3),(4,4))
132   replicate =  models.PositiveSmallIntegerField(choices=REPLICATE_NUM,default=1) 
133
134   EXPERIMENT_TYPES = (
135       ('INPUT_RXLCh','INPUT_RXLCh'),
136       ('ChIP-seq', 'ChIP-seq'),
137       ('Sheared', 'Sheared'),
138       ('RNA-seq', 'RNA-seq'),
139       ('Methyl-seq', 'Methyl-seq'),
140       ('DIP-seq', 'DIP-seq'),
141     ) 
142   experiment_type = models.CharField(max_length=50, choices=EXPERIMENT_TYPES, default='ChIP-seq')
143
144   creation_date = models.DateField(blank=True, null=True)
145   made_for = models.CharField(max_length=50, blank=True,verbose_name = 'ChIP/DNA/RNA Made By')
146   made_by = models.CharField(max_length=50, blank=True,verbose_name = 'Library Made By')
147   
148   PROTOCOL_END_POINTS = (
149       ('Completed','Completed'),
150       ('?', 'Unknown'),
151       ('Sample', 'Raw sample'),
152       ('Progress', 'In progress'),
153       ('1A', 'Ligation, then gel'),
154       ('PCR', 'Ligation, then PCR'),
155       ('1Ab', 'Ligation, PCR, then gel'),
156       ('1Aa', 'Ligation, gel, then PCR'),
157       ('2A', 'Ligation, PCR, gel, PCR'),
158     )
159   stopping_point = models.CharField(max_length=50, choices=PROTOCOL_END_POINTS, default='Completed')
160   amplified_from_sample = models.ForeignKey('self', blank=True, null=True)
161   
162   undiluted_concentration = models.DecimalField("Template concentr. (ng/ul)",max_digits=5, decimal_places=2, blank=True, null=True)
163   ten_nM_dilution = models.BooleanField()
164   successful_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=True, null=True)
165   avg_lib_size = models.IntegerField(default=225, blank=True, null=True)
166   notes = models.TextField(blank=True)
167   
168   def __str__(self):
169     return '%s: %s' % (self.library_id, self.library_name)
170   
171   class Meta:
172     verbose_name_plural = "libraries"
173     ordering = ["-library_id"]
174   
175   def antibody_name(self):
176     return self.antibody.nickname
177
178   def affiliation(self):
179     affs = self.affiliations.all().order_by('name')
180     tstr = ''
181     ar = []
182     for t in affs:
183         ar.append(t.__str__())
184     return '%s' % (", ".join(ar))
185
186   class Admin:
187     date_hierarchy = "creation_date"
188     save_as = True
189     save_on_top = True
190     ##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']
191     search_fields = ['library_id','library_name','cell_line__cellline_name','library_species__scientific_name','library_species__common_name','library_species__use_genome_build']
192     list_display = ('affiliation','library_id', 'library_name','experiment_type','replicate','antibody_name','cell_line','made_by','creation_date')
193     list_display_links = ('library_id', 'library_name')
194     list_filter = ('experiment_type','affiliations','library_species','made_for', 'made_by','replicate')
195     fields = (
196         (None, {
197             'fields': (('replicate','library_id','library_name'),('library_species'),('experiment_type'),('cell_line','condition','antibody'),)
198         }),
199         ('Creation Information:', {
200             'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('avg_lib_size','undiluted_concentration', 'ten_nM_dilution', 'successful_pM'), 'notes',)
201         }),
202         ('Library/Project Affiliation:', {
203             'fields' : (('affiliations'),)
204         }),
205         )