Beispiel #1
0
    def run(self, vectorHtml=None):
        """ Run Lane HTML Documentation Building
        
            vectorHtml - vector of html tags
        """
        #1. Add HTML Report Header
        self.addHtmlReportHeader(vectorHtml)

        vectorHtml.append(
            '<H1 id="title"> <U> Methylation Pipeline Report Project %s </U> </H1>'
            % (self.name_project))

        vector_sample_links = []

        for sampleStats in self.vector_samples:
            sampleHtml = "%s/%s.html" % (self.output_dir, sampleStats.name)
            isizeHistogram = "%s/%s.isize.png" % (os.path.dirname(
                self.output_dir), sampleStats.name)
            png_mapq_histogram = "%s/%s.mapq.png" % (os.path.dirname(
                self.output_dir), sampleStats.name)
            sampleReport = SampleHtml(project_name=self.name_project,sample_stats=sampleStats,html_parent_path=self.project_html_document,\
                                      html_sample=sampleHtml,png_insert_size_histogram=isizeHistogram,png_mapq_histogram=png_mapq_histogram)
            vSampleHtml = []
            sampleReport.run(vSampleHtml)
            RunBasicStats.saveDocument(file_name=sampleHtml,
                                       vectorContent=vSampleHtml)
            vector_sample_links.append(os.path.basename(sampleHtml))

        #3.Links table
        self.createLinksSumupSampleTables(vector_html=vectorHtml,
                                          vector_links=vector_sample_links,
                                          samplesStats=self.vector_samples)

        #4.Close Html
        self.closeHtmlReport(vectorHtml=vectorHtml)
Beispiel #2
0
 def __init__(self,
              mapping_stats=None,
              png_mapq_histogram=None,
              png_insert_size_histogram=None):
     #Call Parent class constructor
     #super(RunBasicStats, self).__init__()
     RunBasicStats.__init__(
         self,
         mapping_stats=mapping_stats,
         png_mapq_histogram=png_mapq_histogram,
         png_insert_size_histogram=png_insert_size_histogram)
Beispiel #3
0
    def run(self, vectorSphinx=None):
        """ Run Sumup Sphinx Documentation Building
        
            vectorSphinx - vector of html tags
        """
        #1. Add SPHINX Report Header
        #Scaped name
        scaped_name = ""
        for character in self.name_project:
            if character == "_":
                scaped_name += "\\%s" % (character)
            else:
                scaped_name += "%s" % (character)

        self.addPartLine(
            ident=0,
            vectorSphinx=vectorSphinx,
            title="CpG Report from Methylation Pipeline Project %s" %
            (scaped_name))

        vectorDocuments = []
        vectorDocuments.append("SUMUP")

        #2. Create Sample and lanes Report
        for sample, stats in sorted(self.dictionary_samples.iteritems()):
            sampleSphinx = "%s/%s.rst" % (self.output_dir, sample)
            vectorDocuments.append("%s" % (sample))

            #Create Build SPHINX
            vector_sphinx = []
            sphinxReport = SphinxCpgsReport()

            sphinxReport.run(vectorSphinx=vector_sphinx,
                             ident=0,
                             lenCell=30,
                             cpgStats=stats,
                             output_dir=self.output_dir,
                             name=sample)

            #Store Sphinx file
            RunBasicStats.saveDocument(file_name=sampleSphinx,
                                       vectorContent=vector_sphinx)

        #3.Toc Table
        vectorSphinx.append("\n")
        self.addTocTree(vectorSphinx=vectorSphinx,
                        vectorDocuments=vectorDocuments)
Beispiel #4
0
def buildSphinxCpgReport(inputs=None, output_dir=None, name=None):
    """ Build Sphinx Variant report
    
        inputs -- dictionary of samples and json stats {"sample":"stats_cpg.json,meth_values_cpg.json"}
        output_dir -- Output directory to store html documents.
        name --  Name basic to build output results.
    """

    #Check output directory
    if not os.path.exists("%s/IMG/" % (output_dir)):
        os.makedirs("%s/IMG/" % (output_dir))

    #Dictionary Samples CpgStats {"sample":"stats_cpg.json"}
    dict_samples_cpg = {}

    for sample, json_files in inputs.iteritems():
        #CpgStats object
        cpgStats = CpgStats()
        #Json Parsing
        with open(json_files[0], 'r') as file_json:
            with open(json_files[1], 'r') as meth_json:
                cpgStats.update(dictionary=json.load(file_json),
                                methDict=json.load(meth_json))

        #Update directory of samples
        dict_samples_cpg[sample] = cpgStats

    #SumupSphinx object
    vector_sumup_sphinx = []
    sumupCpgSphinx = SumupCpgSphinx(output_dir=output_dir,
                                    name_project=name,
                                    dictionary_samples=dict_samples_cpg)
    sumupCpgSphinx.run(vectorSphinx=vector_sumup_sphinx)
    RunBasicStats.saveDocument(file_name=sumupCpgSphinx.cpg_sphinx_document,
                               vectorContent=vector_sumup_sphinx)

    #Config python file
    cfgFile = ConfigSphinx(path_config_file="%s/conf.py" % (output_dir),
                           path_makefile_file="%s/Makefile" % (output_dir),
                           master_file=name,
                           project_name=name,
                           main_title='CPGs REPORT')
    cfgFile.run()
Beispiel #5
0
def buildCpgReport(inputs=None, output_dir=None, name=None):
    """ Build CpG report.
    
        inputs -- dictionary of samples and json stats {"sample":"stats_cpg.json,meth_values_cpg.json"}
        output_dir -- Output directory to store html documents.
        name --  Name basic to build output results.
    """

    #Check output directory
    if not os.path.exists("%s/IMG/" % (output_dir)):
        os.makedirs("%s/IMG/" % (output_dir))

    #Dictionary Samples CpgStats {"sample":"stats_cpg.json"}
    dict_samples_cpg = {}

    for sample, json_files in inputs.iteritems():
        #CpgStats object
        cpgStats = CpgStats()
        #Json Parsing
        with open(json_files[0], 'r') as file_json:
            with open(json_files[1], 'r') as meth_json:
                cpgStats.update(dictionary=json.load(file_json),
                                methDict=json.load(meth_json))

        #Update directory of samples
        dict_samples_cpg[sample] = cpgStats

    #IndexHtml object
    vector_index_html = []
    indexCpgHtml = IndexCpgHtml(output_dir=output_dir,
                                name_project=name,
                                dictionary_samples=dict_samples_cpg)
    indexCpgHtml.run(vectorHtml=vector_index_html)
    RunBasicStats.saveDocument(file_name=indexCpgHtml.cpg_html_document,
                               vectorContent=vector_index_html)

    #CSS object
    cssBuilder = BasicHtml()
    vector_css = []
    cssBuilder.buildStyleSheet(vector_css)
    RunBasicStats.saveDocument(file_name="%s/style.css" % (output_dir),
                               vectorContent=vector_css)
Beispiel #6
0
def buildReport(inputs=None, output_dir=None, name=None, ref_length=""):
    """ Build report per lane and sample.
    
        inputs -- Dictionary of samples and lanes [sample][fli]json_file
        output_dir -- Output directory to store html documents.
        name --  Name basic to build output results.
        ref_length -- Length of the reference
    """

    #Check output directory
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    #Proces list Lane files
    vector_samples = []
    for sample, fli_json in inputs.iteritems():
        list_stats_lanes = []
        for fli, json_files in fli_json.iteritems():
            for json_file in json_files:
                lane = LaneStats(name=fli,
                                 json_file=json_file,
                                 ref_length=int(ref_length))
                list_stats_lanes.append(lane)

        vector_samples.append(
            SampleStats(name=sample, list_lane_stats=list_stats_lanes))

    #IndexHtml object
    vector_index_html = []
    indexHtml = IndexHtml(output_dir=output_dir,
                          name_project=name,
                          vector_samples=vector_samples)
    indexHtml.run(vectorHtml=vector_index_html)
    RunBasicStats.saveDocument(file_name=indexHtml.project_html_document,
                               vectorContent=vector_index_html)

    #CSS object
    cssBuilder = BasicHtml()
    vector_css = []
    cssBuilder.buildStyleSheet(vector_css)
    RunBasicStats.saveDocument(file_name="%s/style.css" % (output_dir),
                               vectorContent=vector_css)
Beispiel #7
0
    def run(self, vectorHtml=None):
        """ Run Lane HTML Documentation Building
        
            vectorHtml - vector of html tags
        """
        #1. Add HTML Report Header
        self.addHtmlReportHeader(vectorHtml)

        vectorHtml.append(
            '<H1 id="title"> <U> CpG Report from Methylation Pipeline Project %s </U> </H1>'
            % (self.name_project))

        vector_sample_links = []

        for sample, stats in sorted(self.dictionary_samples.iteritems()):
            sampleHtml = "%s/%s_cpg.html" % (self.output_dir, sample)
            #Create Build HTML
            vSampleHtml = []

            sampleCpgReport = HtmlCpgReport()
            sampleCpgReport.run(vectorHtml=vSampleHtml,
                                cpgStats=stats,
                                output_dir=self.output_dir,
                                name=sample,
                                parentName=self.name_project,
                                parentDocument=self.cpg_html_document)
            self.closeHtmlReport(vectorHtml=vSampleHtml)
            RunBasicStats.saveDocument(file_name=sampleHtml,
                                       vectorContent=vSampleHtml)

            vector_sample_links.append([os.path.basename(sampleHtml), sample])

        #2.Links table
        self.createLinksTables(vector_html=vectorHtml,
                               vector_links=vector_sample_links,
                               title="Sample Reports",
                               color="blue")

        #3.Close Html
        self.closeHtmlReport(vectorHtml=vectorHtml)
Beispiel #8
0
def buildSphinxVariantReport(inputs=None, output_dir=None, name=None):
    """ Build Sphinx Variant report
    
        inputs -- List of json files
        output_dir -- Output directory to store html documents.
        name --  Name basic to build output results.
    """

    #Check output directory
    if not os.path.exists("%s/IMG/" % (output_dir)):
        os.makedirs("%s/IMG/" % (output_dir))

    #Proces list chromosome files
    dict_samples = {}
    for sample, chrom_json_files in inputs.iteritems():
        #Parsing json file
        basicStats = VariantStats()
        q20BasicStats = VariantStats()
        coverageStats = VariantStats()
        genotypeQualityStats = VariantStats()
        mutationChangesStats = VariantStats()
        mutationChangesQ20Stats = VariantStats()
        chromosomeStats = VariantStats()

        #Load al json files
        for json_file in chrom_json_files:
            with open(json_file, 'r') as file_json:
                data = json.load(file_json)
                basicStats.addValues({
                    "Total Snps":
                    data["TotalSnps"],
                    "Total indels":
                    data["TotalIndels"],
                    "Total Multiallelic":
                    data["TotalMultiallelic"]
                })
                q20BasicStats.addValues({
                    "Q>20 Snps":
                    data["q20Snps"],
                    "Q>20 indels":
                    data["q20Indels"],
                    "Q>20 Multiallelic":
                    data["q20Multiallelic"]
                })
                coverageStats.addValues(data["coverageVariants"])
                genotypeQualityStats.addValues(data["qualityVariants"])
                mutationChangesStats.addValues(data["mutations"])
                mutationChangesQ20Stats.addValues(data["mutationsQ20"])
                chromosomeStats.addValues(data["chromosomeVariants"])

        #Create Build HTML
        dict_samples[sample] = [
            basicStats, q20BasicStats, coverageStats, genotypeQualityStats,
            mutationChangesStats, mutationChangesQ20Stats, chromosomeStats
        ]

    #SumupSphinx object
    vector_sumup_sphinx = []
    sumupVariantsSphinx = SumupVariantsSphinx(output_dir=output_dir,
                                              name_project=name,
                                              dictionary_samples=dict_samples)
    sumupVariantsSphinx.run(vectorSphinx=vector_sumup_sphinx)
    RunBasicStats.saveDocument(
        file_name=sumupVariantsSphinx.variants_sphinx_document,
        vectorContent=vector_sumup_sphinx)

    #Config python file
    cfgFile = ConfigSphinx(path_config_file="%s/conf.py" % (output_dir),
                           path_makefile_file="%s/Makefile" % (output_dir),
                           master_file=name,
                           project_name=name,
                           main_title='VARIANTS REPORT')
    cfgFile.run()
Beispiel #9
0
def buildVariantReport(inputs=None, output_dir=None, name=None):
    """ Build variant report.
    
        inputs -- Dictionary of samples and list of files. [sample] [barcode_chrN.json,barcode_chrN+1.json]
        output_dir -- Output directory to store html documents.
        name --  Name basic to build output results.
    """

    #Check output directory
    if not os.path.exists("%s/IMG/" % (output_dir)):
        os.makedirs("%s/IMG/" % (output_dir))

    #Proces list chromosome files
    dict_samples = {}

    for sample, chrom_json_files in inputs.iteritems():
        #Parsing json file
        basicStats = VariantStats()
        q20BasicStats = VariantStats()
        coverageStats = VariantStats()
        genotypeQualityStats = VariantStats()
        mutationChangesStats = VariantStats()
        mutationChangesQ20Stats = VariantStats()
        chromosomeStats = VariantStats()

        #Load al json files
        for json_file in chrom_json_files:
            with open(json_file, 'r') as file_json:
                data = json.load(file_json)
                basicStats.addValues({
                    "Total Snps":
                    data["TotalSnps"],
                    "Total indels":
                    data["TotalIndels"],
                    "Total Multiallelic":
                    data["TotalMultiallelic"]
                })
                q20BasicStats.addValues({
                    "Q>20 Snps":
                    data["q20Snps"],
                    "Q>20 indels":
                    data["q20Indels"],
                    "Q>20 Multiallelic":
                    data["q20Multiallelic"]
                })
                coverageStats.addValues(data["coverageVariants"])
                genotypeQualityStats.addValues(data["qualityVariants"])
                mutationChangesStats.addValues(data["mutations"])
                mutationChangesQ20Stats.addValues(data["mutationsQ20"])
                chromosomeStats.addValues(data["chromosomeVariants"])

        #Create Build HTML
        dict_samples[sample] = [
            basicStats, q20BasicStats, coverageStats, genotypeQualityStats,
            mutationChangesStats, mutationChangesQ20Stats, chromosomeStats
        ]

    #IndexHtml object
    vector_index_html = []
    indexVariantsHtml = IndexVariantsHtml(output_dir=output_dir,
                                          name_project=name,
                                          dictionary_samples=dict_samples)
    indexVariantsHtml.run(vectorHtml=vector_index_html)
    RunBasicStats.saveDocument(
        file_name=indexVariantsHtml.variants_html_document,
        vectorContent=vector_index_html)

    #CSS object
    cssBuilder = BasicHtml()
    vector_css = []
    cssBuilder.buildStyleSheet(vector_css)
    RunBasicStats.saveDocument(file_name="%s/style.css" % (output_dir),
                               vectorContent=vector_css)
Beispiel #10
0
                qualityNonRefCpG, plotMethylation, summaryMethylation
            ]
        }

    #Create Index BSCall Report
    htmlIndexBsCall = HtmlIndexBsCall(output_dir=output_dir,
                                      name_project=name,
                                      samples_stats=dict_samples,
                                      samples_summary=dict_samples_summaries)
    htmlIndexBsCall.createPage()

    #CSS object
    cssBuilder = BasicHtml()
    vector_css = []
    cssBuilder.buildStyleSheet(vector_css)
    RunBasicStats.saveDocument(file_name="%s/style.css" % (output_dir),
                               vectorContent=vector_css)

    #Create Index BSCall Report
    sphinxIndexBsCall = SphinxIndexBsCall(output_dir="%s/SPHINX/" %
                                          (output_dir),
                                          name_project=name,
                                          samples_stats=dict_samples)
    sphinxIndexBsCall.createPage()

    #Config python file
    cfgFile = ConfigSphinx(path_config_file="%s/SPHINX/conf.py" % (output_dir),
                           path_makefile_file="%s/SPHINX/Makefile" %
                           (output_dir),
                           master_file=name,
                           project_name=name,
                           main_title='BSCALL REPORT')
Beispiel #11
0
    def run(self, vectorHtml=None):
        """ Run Lane HTML Documentation Building
        
            vectorHtml - vector of html tags
        """

        #1. Add HTML Report Header
        self.addHtmlStartReport(vectorHtml=vectorHtml)
        self.addSpaceSection(vectorHtml=vectorHtml)
        self.addSectionTitle(vectorHtml=vectorHtml,
                             title="Mapping Stats (Reads)")
        vectorHtml.extend(self.createStatsTable(color='blue'))

        self.addSpaceSection(vectorHtml=vectorHtml)
        self.addSectionTitle(vectorHtml=vectorHtml,
                             title="Uniqueness (Fragments)")
        vectorHtml.extend(
            self.createUniqueFragmentsTable(
                color='green',
                unique_fragments=self.mapping_stats.totalSampleUniqueReads,
                average_unique=self.mapping_stats.averageSampleUniqueReads))

        self.addSpaceSection(vectorHtml=vectorHtml)
        self.addSectionTitle(vectorHtml=vectorHtml,
                             title="Mapping Stats (Bases)")
        vectorHtml.extend(self.createBasesStatsTable(color='blue'))

        self.addSpaceSection(vectorHtml=vectorHtml)
        self.addSectionTitle(vectorHtml=vectorHtml,
                             title="Bisulfite Conversion Rate")
        vectorHtml.extend(self.createBisulfiteConversionRate(color='green'))

        if self.is_paired:
            self.addSpaceSection(vectorHtml=vectorHtml)
            self.addSectionTitle(vectorHtml=vectorHtml, title="Correct Pairs")
            vectorHtml.extend(
                self.createSingleValueTable(
                    color='blue',
                    name='Correct Pairs',
                    value=self.mapping_stats.correct_pairs))

        #2. Lane Stats and links per lane
        vLaneLinksVector = []
        for laneStats in self.mapping_stats.list_lane_stats:
            htmlLane = "%s/%s.html" % (os.path.dirname(
                self.html_parent_path), laneStats.name)
            mapqHistogram = "%s/%s.mapq.png" % (os.path.dirname(
                self.html_parent_path), laneStats.name)
            isizeHistogram = "%s/%s.isize.png" % (os.path.dirname(
                self.html_parent_path), laneStats.name)
            vLaneHtml = []
            laneHtml = LaneHtml(project_name=self.project_name,
                                sample_name=self.mapping_stats.name,
                                lane_stats=laneStats,
                                png_mapq_histogram=mapqHistogram,
                                png_insert_size_histogram=isizeHistogram,
                                html_parent_path=self.html_sample)
            laneHtml.run(vLaneHtml)
            RunBasicStats.saveDocument(file_name=htmlLane,
                                       vectorContent=vLaneHtml)
            vLaneLinksVector.append(
                [laneStats.name, os.path.basename(htmlLane)])

        #3.Mapping Quality
        self.addSpaceSection(vectorHtml=vectorHtml)
        self.addSectionTitle(vectorHtml=vectorHtml, title="Mapping Quality")
        vectorHtml.extend(self.buildMapqHistogram(color='green'))

        #4. Insert Size Plot
        if self.is_paired:
            self.addSpaceSection(vectorHtml=vectorHtml)
            self.addSectionTitle(vectorHtml=vectorHtml,
                                 title="Insert Size Plot")
            vectorHtml.extend(self.buildInsertSizePlot(color='blue'))

        #5.Links table
        self.addSpaceSection(vectorHtml=vectorHtml)
        self.addSectionTitle(vectorHtml=vectorHtml,
                             title="Mapping Lanes Reports")
        self.createLinksTables(vectorHtml,
                               vLaneLinksVector,
                               title="LANE REPORTS",
                               color="green")
        #6. Close html
        self.closeHtmlReport(vectorHtml=vectorHtml)