1 from django.db import models
2 from htsworkflow.frontend.samples.models import *
3 from htsworkflow.frontend.settings import options
4 from django.core.exceptions import ObjectDoesNotExist
7 class ClusterStation(models.Model):
8 name = models.CharField(max_length=50, unique=True)
10 def __unicode__(self):
11 return unicode(self.name)
13 class Sequencer(models.Model):
14 name = models.CharField(max_length=50, unique=True)
16 def __unicode__(self):
17 return unicode(self.name)
21 default_pM = int(options.get('frontend', 'default_pm'))
23 logging.error("invalid value for frontend.default_pm")
28 class FlowCell(models.Model):
30 flowcell_id = models.CharField(max_length=20, unique=True, db_index=True)
31 run_date = models.DateTimeField()
32 advanced_run = models.BooleanField(default=False)
33 paired_end = models.BooleanField(default=False)
34 read_length = models.IntegerField(default=32) #Stanford is currenlty 25
36 cluster_station = models.ForeignKey(ClusterStation, default=3)
37 sequencer = models.ForeignKey(Sequencer, default=1)
39 notes = models.TextField(blank=True)
41 def __unicode__(self):
42 return unicode(self.flowcell_id)
46 str +='<a target=_balnk href="/experiments/'+self.flowcell_id+'" title="Create XLS like sheet for this Flowcell ..." ">Create LOG</a>'
48 t = DataRun.objects.get(fcid=self.id)
49 str +='<br/><a target=_self href="/admin/experiments/datarun/?q='+self.flowcell_id+'" title="Check Data Runs ..." ">DataRun ..</a>'
50 except ObjectDoesNotExist:
51 str += '<br/><span style="color:red">not sequenced</span>'
53 Create_LOG.allow_tags = True
56 library_url = '/admin/samples/library/%s'
59 for lane in self.lane_set.all():
60 cluster_estimate = lane.cluster_estimate
61 if cluster_estimate is not None:
62 cluster_estimate = "%s k" % ((int(cluster_estimate)/1000), )
64 cluster_estimate = 'None'
65 library_id = lane.library_id
66 library = lane.library
67 element = '<tr><td>%d</td><td><a href="%s">%s</a></td><td>%s</td></tr>'
68 expanded_library_url = library_url %(library_id,)
69 html.append(element % (lane.lane_number, expanded_library_url, library, cluster_estimate))
70 html.append('</table>')
71 return "\n".join(html)
72 Lanes.allow_tags = True
75 ordering = ["-run_date"]
77 ### -----------------------
78 class DataRun(models.Model):
79 ConfTemplate = "CONFIG PARAMS WILL BE GENERATED BY THE PIPELINE SCRIPT.\nYOU'LL BE ABLE TO EDIT AFTER IF NEEDED."
80 run_folder = models.CharField(max_length=50,unique=True, db_index=True)
81 fcid = models.ForeignKey(FlowCell,verbose_name="Flowcell Id")
82 config_params = models.TextField(default=ConfTemplate)
83 run_start_time = models.DateTimeField()
84 RUN_STATUS_CHOICES = (
85 (0, 'Sequencer running'), ##Solexa Data Pipeline Not Yet Started'),
86 (1, 'Data Pipeline Started'),
87 (2, 'Data Pipeline Interrupted'),
88 (3, 'Data Pipeline Finished'),
89 (4, 'CollectReads Started'),
90 (5, 'CollectReads Finished'),
94 run_status = models.IntegerField(choices=RUN_STATUS_CHOICES, default=0)
95 run_note = models.TextField(blank=True)
98 def main_status(self):
100 if self.run_status >= 5:
101 str += ' style="color:green">'
102 str += '<b>'+self.RUN_STATUS_CHOICES[self.run_status][1]+'</b>'
103 str += '<br/><br/>' #<span style="color:red;font-size:80%;">New!</span>'
104 str +='<br/><a target=_balnk href="'+settings.TASKS_PROJS_SERVER+'/Flowcells/'+self.fcid.flowcell_id+'/'+self.fcid.flowcell_id+'_QC_Summary.html" title="View QC Summaries of this run ..." ">View QC Page</a>'
106 str += '>'+self.RUN_STATUS_CHOICES[self.run_status][1]
110 main_status.allow_tags = True
112 main_status.allow_tags = True
114 def Flowcell_Info(self):
115 str = '<b>'+self.fcid.__str__()+'</b>'
116 str += ' (c: '+self.fcid.cluster_mac_id+', s: '+self.fcid.seq_mac_id+')'
117 str += '<div style="margin-top:5px;">'
118 str +='<a title="View Lane List here ..." onClick="el = document.getElementById(\'LanesOf'+self.fcid.__str__()+'\');if(el) (el.style.display==\'none\'?el.style.display=\'block\':el.style.display=\'none\')" style="cursor:pointer;color: #5b80b2;">View/hide lanes</a>'
119 str += '<div id="LanesOf'+self.fcid.__str__()+'" style="display:block;border:solid #cccccc 1px;width:350px">'
120 LanesList = '1: '+self.fcid.lane_1_library.__str__()+' ('+self.fcid.lane_1_library.library_species.use_genome_build+')<br/>2: '+self.fcid.lane_2_library.__str__()+' ('+self.fcid.lane_2_library.library_species.use_genome_build+')<br/>3: '+self.fcid.lane_3_library.__str__()+' ('+self.fcid.lane_3_library.library_species.use_genome_build+')<br/>4: '+self.fcid.lane_4_library.__str__()+' ('+self.fcid.lane_4_library.library_species.use_genome_build+')<br/>5: '+self.fcid.lane_5_library.__str__()+' ('+self.fcid.lane_5_library.library_species.use_genome_build+')<br/>6: '+self.fcid.lane_6_library.__str__()+' ('+self.fcid.lane_6_library.library_species.use_genome_build+')<br/>7: '+self.fcid.lane_7_library.__str__()+' ('+self.fcid.lane_7_library.library_species.use_genome_build+')<br/>8: '+self.fcid.lane_8_library.__str__()+' ('+self.fcid.lane_8_library.library_species.use_genome_build+')'
121 str += LanesList ## self.fcid.Lanes()
123 str += '<div><a title="open Flowcell record" href="/admin/exp_track/flowcell/'+self.fcid.id.__str__()+'/" target=_self>Edit Flowcell record</a>'
124 #str += '<span style="color:red;font-size:80%;margin-left:15px;margin-right:3px">New!</span>'
125 str +='<a style="margin-left:15px;" target=_balnk href="/exp_track/'+self.fcid.flowcell_id+'" title="View XLS like sheet for this Flowcell LOG ..." ">GA LOG Page</a>'
129 Flowcell_Info.allow_tags = True
132 class Lane(models.Model):
133 flowcell = models.ForeignKey(FlowCell)
134 lane_number = models.IntegerField(choices=[(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8)])
135 library = models.ForeignKey(Library)
136 pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=default_pM)
137 cluster_estimate = models.IntegerField(blank=True, null=True)
138 comment = models.TextField(null=True, blank=True)