+
+ def save(self, cursor):
+ """
+ Add this entry to a DB2.0 database.
+ """
+ #FIXME: NEEDS SQL ESCAPING
+ header_macro = {'table': SEQUENCE_TABLE_NAME }
+ sql_header = "insert into %(table)s (" % header_macro
+ sql_columns = ['filetype','path','flowcell','lane']
+ sql_middle = ") values ("
+ sql_values = [self.filetype, self.path, self.flowcell, self.lane]
+ sql_footer = ");"
+ for name in ['read', 'pf', 'cycle']:
+ value = getattr(self, name)
+ if value is not None:
+ sql_columns.append(name)
+ sql_values.append(value)
+
+ sql = " ".join([sql_header,
+ ", ".join(sql_columns),
+ sql_middle,
+ # note the following makes a string like ?,?,?
+ ",".join(["?"] * len(sql_values)),
+ sql_footer])
+
+ return cursor.execute(sql, sql_values)
+
+def get_flowcell_cycle(path):
+ """
+ Extract flowcell, cycle from pathname
+ """
+ rest, cycle = os.path.split(path)
+ rest, flowcell = os.path.split(rest)
+ cycle_match = re.match("C(?P<start>[0-9]+)-(?P<stop>[0-9]+)", cycle)
+ if cycle_match is None:
+ raise ValueError("Expected .../flowcell/cycle/ directory structure")
+ start = cycle_match.group('start')
+ if start is not None:
+ start = int(start)
+ stop = cycle_match.group('stop')
+ if stop is not None:
+ stop = int(stop)
+
+ return flowcell, start, stop