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 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
Example #4
0
            n_reported += 1
            if n_reported == 100:
                break
        json_data['undetermined_barcodes']['number_reported'] = n_reported

    # Write data to JSON file
    json_file = os.path.join(output_dir, "icell8_atac_stats.json")
    with open(json_file, 'w') as fp:
        json.dump(json_data, fp, indent=2)
    report("Wrote JSON file: %s" % json_file)

    # Write stats to XLSX file
    xlsx_stats_file = os.path.join(output_dir, "icell8_atac_stats.xlsx")
    wb = XLSWorkBook("ICELL8 scATAC-seq")
    # Summary
    ws = wb.add_work_sheet("summary", "Summary")
    data = json_data['summary']
    ws.insert_block_data("Command line: %s" % data['command_line'])
    ws.append_row([
        "Swap I1/I2 fastqs",
        "%s" % ('YES' if data['swap_i1_and_i2'] else 'NO', )
    ])
    ws.append_row([
        "Reverse complement",
        "%s" % (data['reverse_complement'].upper()
                if data['reverse_complement'] else '', )
    ])
    ws.append_row(["Number of cells", data['number_of_barcodes']])
    ws.append_row(
        ["Number of cells with reads", data['number_of_barcodes_with_reads']])
    # Reads per sample
    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