2 from optparse import OptionParser
3 from pprint import pprint
10 self.conn = sqlite3.connect('fctracker.db')
14 def _make_dict_from_table(self, table_name, pkey_name):
16 c = self.conn.cursor()
17 c.execute('select * from %s;' % (table_name))
18 # extract just the field name
19 description = [ f[0] for f in c.description]
21 row_dict = dict(zip(description, row))
22 table[row_dict[pkey_name]] = row_dict
26 def _get_library(self):
27 self.library = self._make_dict_from_table(
32 def _get_species(self):
33 self.species = self._make_dict_from_table(
38 def _get_flowcells(self, where=None):
42 c = self.conn.cursor()
43 c.execute('select * from fctracker_flowcell %s;' % (where))
44 # extract just the field name
45 description = [ f[0] for f in c.description ]
47 row_dict = dict(zip(description, row))
48 for lane in [ 'lane_%d_library' % (i) for i in range(1,9) ]:
49 lane_library = self.library[row_dict[lane+"_id"]]
50 species_id = lane_library['library_species_id']
51 lane_library['library_species'] = self.species[species_id]
52 row_dict[lane] = lane_library
54 run_date = time.strptime(row_dict['run_date'], '%Y-%m-%d %H:%M:%S')
55 run_date = datetime.datetime(*run_date[:6])
56 row_dict['run_date'] = run_date
57 self.flowcells[row_dict['flowcell_id']] = row_dict
61 def flowcell_gone(name):
70 def report(flowcells):
72 for key, cell in flowcells.items():
73 flowcell_list.append( (cell['run_date'], key) )
75 for run_date, flowcell_id in flowcell_list:
76 cell = flowcells[flowcell_id]
77 if flowcell_gone(cell['flowcell_id']):
80 #print cell['flowcell_id'], cell['run_date']
82 lane = 'lane_%d' % (l)
83 print cell['run_date'].strftime('%y-%b-%d'),
84 print cell['flowcell_id'],
86 print l,cell['%s_library'%(lane)]['library_name'],
87 print '(%s)' % (cell['%s_library_id'%(lane)]),
88 print cell['%s_library'%(lane)]['library_species']['scientific_name']
94 parser = OptionParser()
95 parser.add_option("-w", "--where", dest="where",
96 help="add a where clause",
103 parser = make_parser()
105 opt, args = parser.parse_args(argv)
108 cells = fc._get_flowcells(opt.where)
113 if __name__ == "__main__":
114 sys.exit(main(sys.argv[1:]))