- PROTOCOL_END_POINTS_DICT = dict(PROTOCOL_END_POINTS)
- stopping_point = models.CharField(max_length=25,
- choices=PROTOCOL_END_POINTS,
- default='Done')
-
- amplified_from_sample = models.ForeignKey('self',
- related_name='amplified_into_sample',
- blank=True, null=True)
-
- undiluted_concentration = models.DecimalField("Concentration",
- max_digits=5, decimal_places=2, blank=True, null=True,
- help_text = "Undiluted concentration (ng/\u00b5l)")
- # note \u00b5 is the micro symbol in unicode
- successful_pM = models.DecimalField(max_digits=9,
- decimal_places=1, blank=True, null=True)
- ten_nM_dilution = models.BooleanField(default=False)
- gel_cut_size = models.IntegerField(default=225, blank=True, null=True)
- insert_size = models.IntegerField(blank=True, null=True)
- notes = models.TextField(blank=True)
-
- bioanalyzer_summary = models.TextField(blank=True,default="")
- bioanalyzer_concentration = models.DecimalField(max_digits=5,
- decimal_places=2, blank=True, null=True,
- help_text="(ng/\u00b5l)")
- bioanalyzer_image_url = models.URLField(blank=True,default="")
-
- def __str__(self):
- return '#%s: %s' % (self.id, self.library_name)
-
- class Meta:
- verbose_name_plural = "libraries"
- #ordering = ["-creation_date"]
- ordering = ["-id"]
-
- def antibody_name(self):
- str ='<a target=_self href="/admin/samples/antibody/'+self.antibody.id.__str__()+'/" title="'+self.antibody.__str__()+'">'+self.antibody.label+'</a>'
- return str
- antibody_name.allow_tags = True
-
- def organism(self):
- return self.library_species.common_name
-
- def index_sequences(self):
- """Return a dictionary of multiplex index id to sequence
- Return None if the library can't multiplex,
-
- """
- if self.library_type is None:
- return None
- if not self.library_type.can_multiplex:
- return None
- if self.multiplex_id is None or len(self.multiplex_id) == 0:
- return 'Err: id empty'
- sequences = {}
- multiplex_expressions = self.multiplex_id.split(',')
- for multiplex_term in multiplex_expressions:
- pairs = multiplex_term.split('-')
- if len(pairs) == 1:
- key = pairs[0]
- seq = self._lookup_index(pairs[0])
- elif len(pairs) == 2:
- key = pairs[0] + '-' + pairs[1]
- seq0 = self._lookup_index(pairs[0])
- seq1 = self._lookup_index(pairs[1])
- if seq0 is None or seq1 is None:
- seq = None
- else:
- seq = seq0 + '-' + seq1
- else:
- raise RuntimeError("Too many - seperated sequences")
- if seq is None:
- seq = 'Err: index not found'
- sequences[key] = seq
- return sequences
-
- def _lookup_index(self, multiplex_id):
- try:
- multiplex = MultiplexIndex.objects.get(
- adapter_type = self.library_type.id,
- multiplex_id = multiplex_id)
- return multiplex.sequence
- except MultiplexIndex.DoesNotExist as e:
- return None
-
- def index_sequence_text(self, seperator=' '):
- """Return formatted multiplex index sequences"""
- sequences = self.index_sequences()
- if sequences is None:
- return ""
- if isinstance(sequences, six.string_types):
- return sequences
- multiplex_ids = sequences.keys()
- multiplex_ids.sort()
- return seperator.join(( "%s:%s" %(i,sequences[i]) for i in multiplex_ids))
- index_sequence_text.short_description = "Index"
-
-
- def affiliation(self):
- affs = self.affiliations.all().order_by('name')
- tstr = ''
- ar = []
- for t in affs:
- ar.append(t.__str__())
- return '%s' % (", ".join(ar))
-
- def is_archived(self):
- """
- returns True if archived else False
- """
- if self.longtermstorage_set.count() > 0:
- return True
- else:
- return False
-
- def stopping_point_name(self):
- end_points = Library.PROTOCOL_END_POINTS_DICT
- name = end_points.get(self.stopping_point, None)
- if name is None:
- name = "Lookup Error"
- logger.error("protocol stopping point in database didn't match names in library model")
- return name
-
-
- def libtags(self):
- affs = self.tags.all().order_by('tag_name')
- ar = []
- for t in affs:
- ar.append(t.__str__())
- return '%s' % ( ", ".join(ar))
-
- def DataRun(self):
- str ='<a target=_self href="/admin/experiments/datarun/?q='+self.id+'" title="Check All Data Runs for This Specific Library ..." ">Data Run</a>'
- return str
- DataRun.allow_tags = True
-
- def aligned_m_reads(self):
- return getLibReads(self.id)
-
- def aligned_reads(self):
- res = getLibReads(self.id)
-
- # Check data sanity
- if res[2] != "OK":
- return '<div style="border:solid red 2px">'+res[2]+'</div>'
-
- rc = "%1.2f" % (res[1]/1000000.0)
- # 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
- if res[0] > 0:
- bgcolor = '#ff3300' # Red
- rc_thr = [10000000,5000000,3000000]
- if self.experiment_type == 'RNA-seq':
- rc_thr = [20000000,10000000,6000000]
-
- if res[1] > rc_thr[0]:
- bgcolor = '#66ff66' # Green
- else:
- if res[1] > rc_thr[1]:
- bgcolor ='#00ccff' # Blue
+ PROTOCOL_END_POINTS_DICT = dict(PROTOCOL_END_POINTS)
+ stopping_point = models.CharField(max_length=25,
+ choices=PROTOCOL_END_POINTS,
+ default='Done')
+
+ amplified_from_sample = models.ForeignKey(
+ 'self',
+ related_name='amplified_into_sample',
+ blank=True, null=True)
+
+ undiluted_concentration = models.DecimalField(
+ "Concentration",
+ max_digits=5, decimal_places=2, blank=True, null=True,
+ help_text="Undiluted concentration (ng/\u00b5l)")
+ # note \u00b5 is the micro symbol in unicode
+ successful_pM = models.DecimalField(
+ max_digits=9, decimal_places=1, blank=True, null=True)
+ ten_nM_dilution = models.BooleanField(default=False)
+ gel_cut_size = models.IntegerField(default=225, blank=True, null=True)
+ insert_size = models.IntegerField(blank=True, null=True)
+ notes = models.TextField(blank=True)
+
+ bioanalyzer_summary = models.TextField(blank=True, default="")
+ bioanalyzer_concentration = models.DecimalField(
+ max_digits=5, decimal_places=2, blank=True, null=True,
+ help_text="(ng/\u00b5l)")
+ bioanalyzer_image_url = models.URLField(blank=True, default="")
+
+ def __str__(self):
+ return '#%s: %s' % (self.id, self.library_name)
+
+ class Meta:
+ verbose_name_plural = "libraries"
+ # ordering = ["-creation_date"]
+ ordering = ["-id"]
+
+ def antibody_name(self):
+ str ='<a target=_self href="/admin/samples/antibody/'+self.antibody.id.__str__()+'/" title="'+self.antibody.__str__()+'">'+self.antibody.label+'</a>'
+ return str
+ antibody_name.allow_tags = True
+
+ def organism(self):
+ return self.library_species.common_name
+
+ def index_sequences(self):
+ """Return a dictionary of multiplex index id to sequence
+ Return None if the library can't multiplex,
+ """
+ if self.library_type is None:
+ return None
+ if not self.library_type.can_multiplex:
+ return None
+ if self.multiplex_id is None or len(self.multiplex_id) == 0:
+ return 'Err: id empty'
+ sequences = {}
+ multiplex_expressions = self.multiplex_id.split(',')
+ for multiplex_term in multiplex_expressions:
+ pairs = multiplex_term.split('-')
+ if len(pairs) == 1:
+ key = pairs[0]
+ seq = self._lookup_index(pairs[0])
+ elif len(pairs) == 2:
+ key = pairs[0] + '-' + pairs[1]
+ seq0 = self._lookup_index(pairs[0])
+ seq1 = self._lookup_index(pairs[1])
+ if seq0 is None or seq1 is None:
+ seq = None
+ else:
+ seq = seq0 + '-' + seq1
+ else:
+ raise RuntimeError("Too many - seperated sequences")
+ if seq is None:
+ seq = 'Err: index not found'
+ sequences[key] = seq
+ return sequences
+
+ def _lookup_index(self, multiplex_id):
+ try:
+ multiplex = MultiplexIndex.objects.get(
+ adapter_type=self.library_type.id,
+ multiplex_id=multiplex_id)
+ return multiplex.sequence
+ except MultiplexIndex.DoesNotExist as e:
+ return None
+
+ def index_sequence_text(self, seperator=' '):
+ """Return formatted multiplex index sequences"""
+ sequences = self.index_sequences()
+ if sequences is None:
+ return ""
+ if isinstance(sequences, six.string_types):
+ return sequences
+ multiplex_ids = sorted(sequences)
+ return seperator.join(("%s:%s" % (i,sequences[i]) for i in multiplex_ids))
+ index_sequence_text.short_description = "Index"
+
+ def affiliation(self):
+ affs = self.affiliations.all().order_by('name')
+ tstr = ''
+ ar = []
+ for t in affs:
+ ar.append(t.__str__())
+ return '%s' % (", ".join(ar))
+
+ def is_archived(self):
+ """returns True if archived else False
+ """
+ if self.longtermstorage_set.count() > 0:
+ return True