import logging
import os
import re
+import sre_constants
import types
import uuid
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core import urlresolvers
+from django.utils import timezone
from django.db import models
from django.db.models.signals import post_init, pre_save
from htsworkflow.util.conversion import parse_flowcell_id
from htsworkflow.pipelines import runfolder
+import pytz
+
LOGGER = logging.getLogger(__name__)
default_pM = 5
try:
default_pM = int(settings.DEFAULT_PM)
-except ValueError, e:
+except AttributeError, e:
LOGGER.error("invalid value for frontend.default_pm")
# how many days to wait before trying to re-import a runfolder
pre_save.connect(Sequencer.update_isdefault, sender=Sequencer)
+class FlowCellModel(models.Model):
+ name = models.TextField()
+ fixed_time = models.IntegerField(default=0, help_text='(seconds)')
+ per_cycle_time = models.IntegerField(default=0, help_text='(seconds)')
+ isdefault = models.BooleanField(default=False)
+
+ def __unicode__(self):
+ return unicode(self.name)
+
+ @classmethod
+ def default(cls):
+ d = cls.objects.filter(isdefault=True).all()
+ if len(d) > 0:
+ return d[-1]
+ return None
+
+ @staticmethod
+ def update_isdefault(sender, instance, **kwargs):
+ """Clear default if needed
+ """
+ if instance.isdefault:
+ for s in FlowCellType.objects.filter(isdefault=True).all():
+ if s.id != instance.id:
+ s.isdefault = False
+ s.save()
+
+pre_save.connect(FlowCellModel.update_isdefault, sender=FlowCellModel)
class FlowCell(models.Model):
flowcell_id = models.CharField(max_length=20, unique=True, db_index=True)
cluster_station = models.ForeignKey(ClusterStation, default=ClusterStation.default)
sequencer = models.ForeignKey(Sequencer, default=Sequencer.default)
+ flowcell_model = models.ForeignKey(FlowCellModel, default=FlowCellModel.default)
notes = models.TextField(blank=True)
def import_data_run(self, relative_pathname, run_xml_name, force=False):
"""Given a result directory import files"""
- now = datetime.datetime.now()
+ now = timezone.now()
run_dir = get_absolute_pathname(relative_pathname)
run_xml_path = os.path.join(run_dir, run_xml_name)
run.runfolder_name = run_xml_data.runfolder_name
run.cycle_start = run_xml_data.image_analysis.start
run.cycle_stop = run_xml_data.image_analysis.stop
- run.run_start_time = run_xml_data.image_analysis.date
+ naive_run_start_time = datetime.datetime.fromordinal(run_xml_data.image_analysis.date.toordinal())
+ run.run_start_time = pytz.timezone(settings.TIME_ZONE).localize(naive_run_start_time)
run.image_software = run_xml_data.image_analysis.software
run.image_version = run_xml_data.image_analysis.version
run.basecall_software = run_xml_data.bustard.software
run.alignment_software = run_xml_data.gerald.software
run.alignment_version = run_xml_data.gerald.version
- run.last_update_time = datetime.datetime.now()
+ run.last_update_time = timezone.now()
run.save()
run.update_result_files()
self.datafile_set.add(newfile)
- self.last_update_time = datetime.datetime.now()
+ self.last_update_time = timezone.now()
def lane_files(self):
lanes = {}
name = models.CharField(max_length=50)
mimetype = models.CharField(max_length=50, null=True, blank=True)
# regular expression from glob.fnmatch.translate
- regex = models.CharField(max_length=50, null=True, blank=True)
+ regex = models.TextField(null=True, blank=True)
def parse_filename(self, pathname):
"""Does filename match our pattern?
#return u"<FileType: %s>" % (self.name,)
return self.name
+ def regex_is_valid(self):
+ try:
+ regex = re.compile(self.regex)
+ except sre_constants.error as e:
+ return False
+ return re.compile(self.regex) is not None
def str_uuid():
"""Helper function to set default UUID in DataFile"""