@@ -0,0 +1,2814 @@
+%22%22%22%0AFlowcell object%0A%22%22%22%0A%0Aimport os%0Aimport sys%0Aimport yaml%0Aimport json%0Aimport csv%0Aimport glob%0Afrom cStringIO import StringIO%0A%0Afrom pmtools.lib.runinfo import _yaml_to_tab%0A    %0Aclass Flowcell(object):%0A    lanelabels = %5B%22lane%22, %22description%22, %22flowcell_id%22, %22genome_build%22, %22analysis%22%5D%0A    mplabels = %5B%22barcode_type%22, %22barcode_id%22, %22sample_prj%22, %22name%22, %22sequence%22%5D%0A    header = lanelabels + mplabels%0A    runinfo_tab = None%0A    %0A    def __init__(self, infile=None):%0A        if not infile:%0A            return%0A        with open(infile) as fh:%0A            runinfo_yaml = yaml.load(fh)%0A        self.runinfo_tab = self._yaml_to_tab(runinfo_yaml)%0A%0A    def __repr__(self):%0A        return str(self.runinfo_tab)%0A    %0A    def as_yaml(self):%0A        return self._tab_to_yaml()%0A%0A    def _yaml_to_tab(self, runinfo_yaml):%0A        %22%22%22Convert yaml to internal representation%22%22%22%0A        out = %5B%5D%0A        for info in runinfo_yaml:%0A            laneinfo = %5Binfo.get(x, None) for x in self.lanelabels%5D%0A            for mp in info.get(%22multiplex%22, None):%0A                mpinfo = %5Bmp.get(x, None) for x in self.mplabels%5D%0A                line = laneinfo + mpinfo%0A                out.append(line)%0A        return out%0A%0A    def _tab_to_yaml(self):%0A        %22%22%22Convert internal representation to yaml%22%22%22%0A        yaml_out = dict()%0A        for row in self.runinfo_tab:%0A            (lane, description, flowcell_id, genome_build, analysis,%0A             barcode_type, barcode_id, sample_prj, name, sequence) = row%0A            if not yaml_out.has_key(lane):%0A                yaml_out%5Blane%5D = dict(lane=lane, genome_build=genome_build, description=description,%0A                                      analysis=analysis, flowcell_id=flowcell_id, multiplex=%5B%5D)%0A            yaml_out%5Blane%5D%5B%22multiplex%22%5D.append(dict(barcode_id=barcode_id, barcode_type=barcode_type, genome_build=genome_build,%0A                                                    name=name, sample_prj=sample_prj, sequence=sequence))%0A        return yaml.dump(yaml_out.values())%0A        %0A    def _get_rows(i):%0A        return %5Brow for row in self.runinfo_tab%5Bi:%5D%5D%0A%0A    def _column(label):%0A        i = self.header.index(label)%0A        return %5Brow%5Bi%5D for row in self.runinfo_tab%5D%0A%0A    def projects(self):%0A        %22%22%22List flowcell projects%22%22%22%0A        return list(set(self._column(%22sample_prj%22)))%0A%0A    def lanes(self):%0A        %22%22%22List flowcell lanes%22%22%22%0A        return list(set(self._column(runinfo_tab, %22lane%22)))%0A%0A    def barcodes(self):%0A        %22%22%22List barcodes%22%22%22%0A        pass%0A%0A    def subset(self, column, query):%0A        %22%22%22Subset runinfo. Returns new flowcell object.%22%22%22%0A        pruned_fc = Flowcell()%0A        vals = list(self._column(column))%0A        i = %5Bj + 1 for j in range(0, len(vals)) if vals%5Bj%5D==query%5D%0A        pruned_fc.runinfo_tab = %5Bruninfo_tab%5Bj%5D for j in i%5D%0A        return pruned_fc%0A%0A

Add flowcell code