flowcraft/templates/assembly_report.py
def get_summary_stats(self, output_csv=None):
        """Generates a CSV report with summary statistics about the assembly

        The calculated statistics are:

            - Number of contigs
            - Average contig size
            - N50
            - Total assembly length
            - Average GC content
            - Amount of missing data

        Parameters
        ----------
        output_csv: str
            Name of the output CSV file.
        """

        contig_size_list = []

        self.summary_info["ncontigs"] = len(self.contigs)

        for contig_id, sequence in self.contigs.items():

            logger.debug("Processing contig: {}".format(contig_id))

            # Get contig sequence size
            contig_len = len(sequence)

            # Add size for average contig size
            contig_size_list.append(contig_len)

            # Add to total assembly length
            self.summary_info["total_len"] += contig_len

            # Add to average gc
            self.summary_info["avg_gc"].append(
                sum(map(sequence.count, ["G", "C"])) / contig_len
            )

            # Add to missing data
            self.summary_info["missing_data"] += sequence.count("N")

        # Get average contig size
        logger.debug("Getting average contig size")
        self.summary_info["avg_contig_size"] = \
            sum(contig_size_list) / len(contig_size_list)

        # Get average gc content
        logger.debug("Getting average GC content")
        self.summary_info["avg_gc"] = \
            sum(self.summary_info["avg_gc"]) / len(self.summary_info["avg_gc"])

        # Get N50
        logger.debug("Getting N50")
        cum_size = 0
        for l in sorted(contig_size_list, reverse=True):
            cum_size += l
            if cum_size >= self.summary_info["total_len"] / 2:
                self.summary_info["n50"] = l
                break

        if output_csv:
            logger.debug("Writing report to csv")
            # Write summary info to CSV
            with open(output_csv, "w") as fh:
                summary_line = "{}, {}\\n".format(
                    self.sample, ",".join(
                        [str(x) for x in self.summary_info.values()]))
                fh.write(summary_line)
def get_summary_stats(self, output_csv=None):
        contig_size_list = []

        self.summary_info["ncontigs"] = len(self.contigs)

        for contig_id, sequence in self.contigs.items():

            logger.debug("Processing contig: {}".format(contig_id))

            # Get contig sequence size
            contig_len = len(sequence)

            # Add size for average contig size
            contig_size_list.append(contig_len)

            # Add to total assembly length
            self.summary_info["total_len"] += contig_len

            # Add to average gc
            self.summary_info["avg_gc"].append(
                sum(map(sequence.count, ["G", "C"])) / contig_len
            )

            # Add to missing data
            self.summary_info["missing_data"] += sequence.count("N")

        # Get average contig size
        logger.debug("Getting average contig size")
        self.summary_info["avg_contig_size"] = \
            sum(contig_size_list) / len(contig_size_list)

        # Get average gc content
        logger.debug("Getting average GC content")
        self.summary_info["avg_gc"] = \
            sum(self.summary_info["avg_gc"]) / len(self.summary_info["avg_gc"])

        # Get N50
        logger.debug("Getting N50")
        cum_size = 0
        for l in sorted(contig_size_list, reverse=True):
            cum_size += l
            if cum_size >= self.summary_info["total_len"] / 2:
                self.summary_info["n50"] = l
                break

        if output_csv:
            logger.debug("Writing report to csv")
            # Write summary info to CSV
            with open(output_csv, "w") as fh:
                summary_line = "{}, {}\\n".format(
                    self.sample, ",".join(
                        [str(x) for x in self.summary_info.values()]))
                fh.write(summary_line)
def get_summary_stats ( self , output_csv = None ) : contig_size_list = [ ] self . summary_info [ "ncontigs" ] = len ( self . contigs ) for contig_id , sequence in self . contigs . items ( ) : logger . debug ( "Processing contig: {}" . format ( contig_id ) ) # Get contig sequence size contig_len = len ( sequence ) # Add size for average contig size contig_size_list . append ( contig_len ) # Add to total assembly length self . summary_info [ "total_len" ] += contig_len # Add to average gc self . summary_info [ "avg_gc" ] . append ( sum ( map ( sequence . count , [ "G" , "C" ] ) ) / contig_len ) # Add to missing data self . summary_info [ "missing_data" ] += sequence . count ( "N" ) # Get average contig size logger . debug ( "Getting average contig size" ) self . summary_info [ "avg_contig_size" ] = sum ( contig_size_list ) / len ( contig_size_list ) # Get average gc content logger . debug ( "Getting average GC content" ) self . summary_info [ "avg_gc" ] = sum ( self . summary_info [ "avg_gc" ] ) / len ( self . summary_info [ "avg_gc" ] ) # Get N50 logger . debug ( "Getting N50" ) cum_size = 0 for l in sorted ( contig_size_list , reverse = True ) : cum_size += l if cum_size >= self . summary_info [ "total_len" ] / 2 : self . summary_info [ "n50" ] = l break if output_csv : logger . debug ( "Writing report to csv" ) # Write summary info to CSV with open ( output_csv , "w" ) as fh : summary_line = "{}, {}\\n" . format ( self . sample , "," . join ( [ str ( x ) for x in self . summary_info . values ( ) ] ) ) fh . write ( summary_line )
Generates a CSV report with summary statistics about the assembly

        The calculated statistics are:

            - Number of contigs
            - Average contig size
            - N50
            - Total assembly length
            - Average GC content
            - Amount of missing data

        Parameters
        ----------
        output_csv: str
            Name of the output CSV file.
Generates a CSV report with summary statistics about the assembly