Beispiel #1
0
    def _write_table(self, table, filename, region_names):
        if not any(table["<NA>"][None][None][1:]):
            table.pop("<NA>")

        zeros = [0] * (_MAX_DEPTH + 1)
        first = lambda pair: (pair[0] or "")
        rows = [["Name", "Sample", "Library", "Contig", "Size", "MaxDepth"] + ["MD_%03i" % i for i in xrange(1, _MAX_DEPTH + 1)]]
        for sample, libraries in sorted(table.iteritems(), key = first):
            for library, regions in sorted(libraries.iteritems(), key = first):
                for (region, size) in sorted(region_names.items(), key = first):
                    key = (self._target_name, sample, library, region)
                    row = [("*" if value is None else value) for value in key]

                    counts = regions.get(region, zeros)
                    row.append(size)
                    row.append(self._calc_max_depth(counts))
                    row.extend(self._calc_cumfrac(counts))
                    rows.append(row)

                    if (key[-1] is None) and self._max_contigs_reached:
                        row = list(row)
                        row[3] = "<Genome>"
                        rows.append(row)

                rows.append("#")
            rows.extend("#")

        while rows and rows[-1] == "#":
            rows.pop()

        with open(filename, "w") as table_file:
            table_file.write(_HEADER % datetime.datetime.now().isoformat())
            for line in padded_table(rows):
                table_file.write(line)
                table_file.write("\n")
Beispiel #2
0
    def finalize(self):
        """Called by the pipeline at the termination of a run. By default,
        this function prints the location of the log-file if one was created
        during the run (e.g. if there were errors), and a summary of all nodes.
        """
        runtime = (self._end_time or 0) - (self._start_time or 0)

        if self.states[self.ERROR]:
            print_err("Done; but errors were detected ...")
        else:
            print_info("Done ...")

        print_info()
        rows = [("  Number of nodes:", sum(self.states)),
                ("  Number of done nodes:", self.states[self.DONE]),
                ("  Number of runable nodes:", self.states[self.RUNABLE]),
                ("  Number of queued nodes:", self.states[self.QUEUED]),
                ("  Number of outdated nodes:", self.states[self.OUTDATED]),
                ("  Number of failed nodes:", self.states[self.ERROR]),
                ("  Pipeline runtime:", _fmt_runtime(round(runtime)))]

        for line in text.padded_table(rows):
            print_info(line)

        print_info()
        print_info("Use --list-output-files to view status of output files.")

        logfile = pypeline.logger.get_logfile()
        if logfile:
            print_debug("Log-file located at %r" % (logfile, ))

        print_info()
Beispiel #3
0
    def finalize(self):
        """Called by the pipeline at the termination of a run. By default,
        this function prints the location of the log-file if one was created
        during the run (e.g. if there were errors), and a summary of all nodes.
        """
        runtime = (self._end_time or 0) - (self._start_time or 0)

        if self.states[self.ERROR]:
            print_err("Done; but errors were detected ...")
        else:
            print_info("Done ...")

        print_info()
        rows = [("  Number of nodes:", sum(self.states)),
                ("  Number of done nodes:", self.states[self.DONE]),
                ("  Number of runable nodes:", self.states[self.RUNABLE]),
                ("  Number of queued nodes:", self.states[self.QUEUED]),
                ("  Number of outdated nodes:", self.states[self.OUTDATED]),
                ("  Number of failed nodes:", self.states[self.ERROR]),
                ("  Pipeline runtime:", _fmt_runtime(round(runtime)))]

        for line in text.padded_table(rows):
            print_info(line)

        print_info()
        print_info("Use --list-output-files to view status of output files.")

        logfile = pypeline.logger.get_logfile()
        if logfile:
            print_debug("Log-file located at %r" % (logfile,))

        print_info()
Beispiel #4
0
    def _write_tables(self, out, genomes):
        rows = [[
            "Target", "Sample", "Library", "Measure", "Value", "# Description"
        ]]
        for (target, samples) in sorted(
                self._read_tables(self._prefixes, genomes).iteritems()):
            for (sample, libraries) in sorted(samples.iteritems()):
                for (library, prefixes) in sorted(libraries.iteritems()):
                    ordered = [("reads", prefixes.pop("reads"))
                               ] if "reads" in prefixes else []
                    ordered.extend(sorted(prefixes.items()))

                    for (prefix, table) in ordered:
                        table.pop("hits_unique_nts(%s)" % prefix, None)

                        for (key, (value,
                                   comment)) in sorted(table.iteritems(),
                                                       key=_measure_ordering):
                            if isinstance(
                                    value,
                                    numbers.Number) and math.isnan(value):
                                value = "NA"
                            rows.append(
                                (target, sample, library, key, value, comment))
                        rows.append("")
                    rows.append("")

        for line in text.padded_table(rows):
            out.write("%s\n" % line)
Beispiel #5
0
def _write_table(table, filename):
    _calculate_totals(table)
    rows = _build_rows(table)
    with open(filename, "w") as table_file:
        table_file.write(_HEADER % datetime.datetime.now().isoformat())
        for line in padded_table(rows):
            table_file.write(line)
            table_file.write("\n")
Beispiel #6
0
    def _write_areas_of_interest(self, table, rois):
        table.write("# Regions Of Interest:\n")
        rows = [["Genome", "ROI", "Size", "NFeatures", "NIntervals", "Path"]]
        for (_, roi) in sorted(rois.items()):
            rows.append([roi[key] for key in ("Genome", "Name", "Size", "NFeatures", "NIntervals", "Path")])

        for line in text.padded_table(rows):
            table.write("#     %s\n" % (line,))
Beispiel #7
0
    def _write_areas_of_interest(self, table, rois):
        table.write("# Regions Of Interest:\n")
        rows = [["Genome", "ROI", "Size", "NFeatures", "NIntervals", "Path"]]
        for (_, roi) in sorted(rois.items()):
            rows.append([roi[key] for key in ("Genome", "Name", "Size", "NFeatures", "NIntervals", "Path")])

        for line in text.padded_table(rows):
            table.write("#     %s\n" % (line,))
Beispiel #8
0
    def _write_genomes(self, table, genomes):
        table.write("# Genomes:\n")
        rows = [["Name", "Label", "Contigs", "Size", "Prefix"]]
        for (_, prefix) in sorted(self._prefixes.items()):
            stats = genomes[prefix["Name"]]
            rows.append((prefix["Name"], prefix.get("Label", "-"), stats["NContigs"], stats["Size"], prefix["Path"]))

        for line in text.padded_table(rows):
            table.write("#     %s\n" % (line,))
Beispiel #9
0
    def _write_genomes(self, table, genomes):
        table.write("# Genomes:\n")
        rows = [["Name", "Label", "Contigs", "Size", "Prefix"]]
        for (_, prefix) in sorted(self._prefixes.items()):
            stats = genomes[prefix["Name"]]
            rows.append((prefix["Name"], prefix.get("Label", "-"), stats["NContigs"], stats["Size"], prefix["Path"]))

        for line in text.padded_table(rows):
            table.write("#     %s\n" % (line,))
Beispiel #10
0
def print_table(handle, args, totals):
    lengths = collect_references(args, handle)

    if args.outfile == "-":
        output_handle = sys.stdout
    else:
        output_handle = open(args.outfile, "w")

    with output_handle:
        rows = build_table(args.target_name, totals, lengths)
        output_handle.write(_HEADER % datetime.datetime.now().isoformat())
        output_handle.write("\n")
        for line in padded_table(rows):
            output_handle.write(line)
            output_handle.write("\n")
Beispiel #11
0
def print_table(handle, args, totals):
    lengths = collect_references(args, handle)

    if args.outfile == "-":
        output_handle = sys.stdout
    else:
        output_handle = open(args.outfile, "w")

    with output_handle:
        rows = build_table(args.target_name, totals, lengths)
        output_handle.write(_HEADER % datetime.datetime.now().isoformat())
        output_handle.write("\n")
        for line in padded_table(rows):
            output_handle.write(line)
            output_handle.write("\n")
Beispiel #12
0
def write_table(table, filename):
    table = calculate_totals(table)
    rows = build_rows(table)

    if filename == "-":
        output_handle = sys.stdout
    else:
        output_handle = open(filename, "w")

    try:
        output_handle.write(TABLE_HEADER % datetime.datetime.now().isoformat())
        for line in padded_table(rows):
            output_handle.write(line)
            output_handle.write("\n")
    finally:
        if output_handle is not sys.stdout:
            output_handle.close()
Beispiel #13
0
def write_table(table, filename):
    table = calculate_totals(table)
    rows = build_rows(table)

    if filename == "-":
        output_handle = sys.stdout
    else:
        output_handle = open(filename, "w")

    try:
        output_handle.write(TABLE_HEADER % datetime.datetime.now().isoformat())
        for line in padded_table(rows):
            output_handle.write(line)
            output_handle.write("\n")
    finally:
        if output_handle is not sys.stdout:
            output_handle.close()
Beispiel #14
0
    def _write_tables(self, out, genomes):
        rows = [["Target", "Sample", "Library", "Measure", "Value", "# Description"]]
        for (target, samples) in sorted(self._read_tables(self._prefixes, genomes).iteritems()):
            for (sample, libraries) in sorted(samples.iteritems()):
                for (library, prefixes) in sorted(libraries.iteritems()):
                    ordered = [("reads", prefixes.pop("reads"))] if "reads" in prefixes else []
                    ordered.extend(sorted(prefixes.items()))

                    for (prefix, table) in ordered:
                        table.pop("hits_unique_nts(%s)" % prefix, None)

                        for (key, (value, comment)) in sorted(table.iteritems(), key=_measure_ordering):
                            if isinstance(value, numbers.Number) and math.isnan(value):
                                value = "NA"
                            rows.append((target, sample, library, key, value, comment))
                        rows.append("")
                    rows.append("")

        for line in text.padded_table(rows):
            out.write("%s\n" % line)
Beispiel #15
0
    def _write_table(self, table, filename, region_names):
        if not any(table["<NA>"][None][None][1:]):
            table.pop("<NA>")

        zeros = [0] * (_MAX_DEPTH + 1)
        first = lambda pair: (pair[0] or "")
        rows = [["Name", "Sample", "Library", "Contig", "Size", "MaxDepth"] +
                ["MD_%03i" % i for i in xrange(1, _MAX_DEPTH + 1)]]
        for sample, libraries in sorted(table.iteritems(), key=first):
            for library, regions in sorted(libraries.iteritems(), key=first):
                for (region, size) in sorted(region_names.items(), key=first):
                    key = (self._target_name, sample, library, region)
                    row = [("*" if value is None else value) for value in key]

                    counts = regions.get(region, zeros)
                    row.append(size)
                    row.append(self._calc_max_depth(counts))
                    row.extend(self._calc_cumfrac(counts))
                    rows.append(row)

                    if (key[-1] is None) and self._max_contigs_reached:
                        row = list(row)
                        row[3] = "<Genome>"
                        rows.append(row)

                rows.append("#")
            rows.extend("#")

        while rows and rows[-1] == "#":
            rows.pop()

        with open(filename, "w") as table_file:
            table_file.write(_HEADER % datetime.datetime.now().isoformat())
            for line in padded_table(rows):
                table_file.write(line)
                table_file.write("\n")
Beispiel #16
0
def _padded_table(*args, **kwargs):
    return list(padded_table(*args, **kwargs))
Beispiel #17
0
def _padded_table(*args, **kwargs):
    return list(padded_table(*args, **kwargs))