def write_xls(self,xls_file): """ Write the report to an XLS file """ wb = XLSWorkBook("Barcodes Report") ws = wb.add_work_sheet("barcodes") for item in self._content: content = item[0] attrs = item[1] style = None if attrs.get('title',False): style = XLSStyle(bold=True, color='white', bgcolor='gray50') elif attrs.get('heading',False): style = XLSStyle(bold=True, bgcolor='gray25') elif attrs.get('strong',False): style = XLSStyle(bold=True) ws.append_row(data=content.split('\t'),style=style) wb.save_as_xls(xls_file)
def xls(self,xls_out=None): """Output an XLS spreadsheet with the sample data Create and return a simple_xls.XLSWorkBook object representing the statistics for all the samples. If the 'xls_out' argument is supplied then an XLS spreadsheet file will also be written to the name it contains. Arguments: xls_out: (optional) specify the name of an XLS file to write the spreadsheet to. Will overwrite an existing file with the same name. Returns XLSWorkBook object. """ # Set up reusable spreadsheet styles reads_style = XLSStyle(bgcolor='ivory',border='medium', number_format=NumberFormats.THOUSAND_SEPARATOR, centre=True) pcent_style = XLSStyle(bgcolor='ivory',border='medium', number_format=NumberFormats.PERCENTAGE, centre=True) headr_style = XLSStyle(color='red',bgcolor='ivory',border='medium') table_style = XLSStyle(bgcolor='ivory',border='medium',centre=True) # Create spreadsheet wb = XLSWorkBook() mapping = wb.add_work_sheet("mapping") mapping.insert_column('A',data=["Sample", '', "total reads", "didn't align", "total mapped reads", " % of all reads", "uniquely mapped", " % of all reads", " % of mapped reads"], from_row=3) mapping['A1'] = "MAPPING STATS" mapping.set_style(XLSStyle(bold=True),'A1','A11') # Build spreadsheet for sample in self.samples: sample_name = sample.name # Add input file names to sample ids if there were multiple input files if len(self.files) > 1 and sample.filen is not None: sample_name += " (" + sample.filen + ")" # Insert data into the spreadsheet col = mapping.append_column(data=[sample_name, '', sample.total_reads, sample.didnt_align, "=#5-#6", "=#7/#5", sample.uniquely_mapped, "=#9/#5", "=#9/#7"], from_row=3) mapping.set_style(headr_style,cell(col,3)) mapping.set_style(table_style,cell(col,4)) mapping.set_style(reads_style,cell(col,5),cell(col,7)) mapping.set_style(pcent_style,cell(col,8)) mapping.set_style(reads_style,cell(col,9)) mapping.set_style(pcent_style,cell(col,10),cell(col,11)) # Header mapping['C1'] = "Mapped with Bowtie" mapping.set_style(XLSStyle(centre=True),'C1') # Finished if xls_out is not None: print "Writing statistics to XLS file %s" % xls_out wb.save_as_xls(xls_out) return wb
def xls(self, xls_out=None): """Output an XLS spreadsheet with the sample data Create and return a simple_xls.XLSWorkBook object representing the statistics for all the samples. If the 'xls_out' argument is supplied then an XLS spreadsheet file will also be written to the name it contains. Arguments: xls_out: (optional) specify the name of an XLS file to write the spreadsheet to. Will overwrite an existing file with the same name. Returns XLSWorkBook object. """ # Set up reusable spreadsheet styles reads_style = XLSStyle(bgcolor='ivory', border='medium', number_format=NumberFormats.THOUSAND_SEPARATOR, centre=True) pcent_style = XLSStyle(bgcolor='ivory', border='medium', number_format=NumberFormats.PERCENTAGE, centre=True) headr_style = XLSStyle(color='red', bgcolor='ivory', border='medium') table_style = XLSStyle(bgcolor='ivory', border='medium', centre=True) # Create spreadsheet wb = XLSWorkBook() mapping = wb.add_work_sheet("mapping") mapping.insert_column('A', data=[ "Sample", '', "total reads", "didn't align", "total mapped reads", " % of all reads", "uniquely mapped", " % of all reads", " % of mapped reads" ], from_row=3) mapping['A1'] = "MAPPING STATS" mapping.set_style(XLSStyle(bold=True), 'A1', 'A11') # Build spreadsheet for sample in self.samples: sample_name = sample.name # Add input file names to sample ids if there were multiple input files if len(self.files) > 1 and sample.filen is not None: sample_name += " (" + sample.filen + ")" # Insert data into the spreadsheet col = mapping.append_column(data=[ sample_name, '', sample.total_reads, sample.didnt_align, "=#5-#6", "=#7/#5", sample.uniquely_mapped, "=#9/#5", "=#9/#7" ], from_row=3) mapping.set_style(headr_style, cell(col, 3)) mapping.set_style(table_style, cell(col, 4)) mapping.set_style(reads_style, cell(col, 5), cell(col, 7)) mapping.set_style(pcent_style, cell(col, 8)) mapping.set_style(reads_style, cell(col, 9)) mapping.set_style(pcent_style, cell(col, 10), cell(col, 11)) # Header mapping['C1'] = "Mapped with Bowtie" mapping.set_style(XLSStyle(centre=True), 'C1') # Finished if xls_out is not None: print("Writing statistics to XLS file %s" % xls_out) wb.save_as_xls(xls_out) return wb