def test_sample_from_rundir(): sample_rundir = ("./DEMUX/140627_D00410_0080_AH9BVFADXX/Unaligned" "/Project_331195/Sample_000107T_sureselect7") sample_id = sample_from_rundir(sample_rundir) assert sample_id == '000107T' # ... and with trailing slash: sample_id = sample_from_rundir(sample_rundir + '/') assert sample_id == '000107T'
def add_flowcell(flowcell_dir, samples=None): """Create a new instance of a Spof to the database.""" logger.debug('extracting info from run dir') flowcell_id = extract_flowcell(flowcell_dir) demux_date = date_from_rundir(flowcell_dir) run_folder = path(flowcell_dir).realpath().basename() logger.debug('check of the flowcell already exists') flowcell_obj = Flowcell.query.filter_by(flowcell_id=flowcell_id).first() if flowcell_obj is None: if samples is None: sample_rundirs = get_sample_rundirs(flowcell_dir) sample_ids = (sample_from_rundir(sample_dir) for sample_dir in sample_rundirs) samples = [Sample.query.filter_by(lims_id=sample_id).one() for sample_id in sample_ids] logger.debug('creating new Flowcell record') flowcell_obj = Flowcell(flowcell_id=flowcell_id, demux_folder=run_folder, demuxed_at=demux_date, samples=samples) logger.debug('committing to database') return flowcell_obj