Unverified Commit 86cb2cc8 authored by Chris Cheshire's avatar Chris Cheshire Committed by GitHub
Browse files

Merge pull request #25 from luslab/dev

Varying number of replicates now supported in GENERATE_REPORTS
parents 48911644 c6246a93
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
[![GitHub Actions Linting Status](https://github.com/nf-core/cutandrun/workflows/nf-core%20linting/badge.svg)](https://github.com/nf-core/cutandrun/actions)
[![Nextflow](https://img.shields.io/badge/nextflow-%E2%89%A521.04.0-brightgreen.svg)](https://www.nextflow.io/)

[![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg)](https://bioconda.github.io/)
[![Docker](https://img.shields.io/docker/automated/nfcore/cutandrun.svg)](https://hub.docker.com/r/nfcore/cutandrun)
[![Get help on Slack](http://img.shields.io/badge/slack-nf--core%20%23cutandrun-4A154B?logo=slack)](https://nfcore.slack.com/channels/cutandrun)

+20 −27
Original line number Diff line number Diff line
@@ -243,22 +243,11 @@ class Reports:
        self.frag_series = pd.DataFrame({'group' : group_arr, 'replicate' : rep_arr, 'frag_len' : frag_lens, 'occurences' : frag_counts})

        # ---------- Data - Peak stats --------- #
        # create number of peaks df
        unique_groups = self.seacr_beds.group.unique()
        unique_replicates = self.seacr_beds.replicate.unique()
        self.df_no_peaks = pd.DataFrame(index=range(0,(len(unique_groups)*len(unique_replicates))), columns=['group','replicate','all_peaks'])
        k=0 # counter

        for i in list(range(len(unique_groups))):
            for j in list(range(len(unique_replicates))):
                self.df_no_peaks.at[k,'all_peaks'] = self.seacr_beds[(self.seacr_beds['group']==unique_groups[i]) & (self.seacr_beds['replicate']==unique_replicates[j])].shape[0]
                self.df_no_peaks.at[k,'group'] = unique_groups[i]
                self.df_no_peaks.at[k,'replicate'] = unique_replicates[j]
                k=k+1
        self.seacr_beds_group_rep = self.seacr_beds[['group','replicate']].groupby(['group','replicate']).size().reset_index().rename(columns={0:'all_peaks'})

        # ---------- Data - Reproducibility of peaks between replicates --------- #
        # empty dataframe to fill in loop
        self.reprod_peak_stats = self.df_no_peaks
        self.reprod_peak_stats = self.seacr_beds_group_rep #self.df_no_peaks
        self.reprod_peak_stats = self.reprod_peak_stats.reindex(columns=self.reprod_peak_stats.columns.tolist() + ['no_peaks_reproduced','peak_reproduced_rate'])

        # create permutations list
@@ -275,20 +264,24 @@ class Reports:
        # create pyranges objects and fill df
        unique_groups = self.seacr_beds.group.unique()
        unique_replicates = self.seacr_beds.replicate.unique()
        rep_permutations = array_permutate(range(len(unique_replicates)))
        self.replicate_number = len(unique_replicates)
        # print("this is rep_permutations")
        # print(rep_permutations)
        self.replicate_number = 1
        self.multiple_reps = True
        if (len(unique_groups) == self.seacr_beds_group_rep.shape[0]):
            self.multiple_reps = False

        if self.replicate_number > 1:
        if self.multiple_reps:
            idx_count=0
            for i in list(range(len(unique_groups))):
                group_i = unique_groups[i]
                for k in list(range(len(unique_replicates))):
                group_reps = len(self.seacr_beds_group_rep[self.seacr_beds_group_rep['group'] == group_i])
                if group_reps < 2:
                    continue
                rep_permutations = array_permutate(range(group_reps))
                for k in list(range(group_reps)):
                    pyr_query = pr.PyRanges()
                    rep_perm = rep_permutations[k]
                    for j in rep_perm:
                        rep_i = unique_replicates[j]
                        rep_i = "R" + str(range(group_reps)[j]+1)
                        peaks_i = self.seacr_beds[(self.seacr_beds['group']==group_i) & (self.seacr_beds['replicate']==rep_i)]
                        pyr_subject = pr.PyRanges(chromosomes=peaks_i['chrom'], starts=peaks_i['start'], ends=peaks_i['end'])
                        if(len(pyr_query) > 0):
@@ -301,6 +294,7 @@ class Reports:

                    if (pyr_query.empty):
                        self.reprod_peak_stats.at[idx_count, 'no_peaks_reproduced'] = 0

                    else :
                        pyr_starts = pyr_query.values()[0]['Start']
                        unique_pyr_starts = pyr_starts.unique()
@@ -370,7 +364,6 @@ class Reports:
        data["frag_hist"] = data4

        # Plot 5
        if self.replicate_number > 1:
        plot5, data5 = self.replicate_heatmap()
        plots["replicate_heatmap"] = plot5
        data["replicate_heatmap"] = data5
@@ -391,7 +384,7 @@ class Reports:
        data["peak_widths"] = data7b

        # Plot 7c
        if self.replicate_number > 1:
        if self.multiple_reps:
            plot7c, data7c = self.reproduced_peaks()
            plots["reproduced_peaks"] = plot7c
            data["reproduced_peaks"] = data7c
@@ -577,10 +570,10 @@ class Reports:
        fig, ax = plt.subplots()
        fig.suptitle("Total Peaks")

        ax = sns.boxplot(data=self.df_no_peaks, x='group', y='all_peaks', palette = "magma")
        ax = sns.boxplot(data=self.seacr_beds_group_rep, x='group', y='all_peaks', palette = "magma")
        ax.set_ylabel("No. of Peaks")

        return fig, self.df_no_peaks
        return fig, self.seacr_beds_group_rep

    # 7b - Width of peaks
    def peak_widths(self):
+28 −17
Original line number Diff line number Diff line
#!/bin/bash

wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/meta_table.csv
wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R1_raw.csv
wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R1.bed.stringent.bed
wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R1.frag_len.txt
wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R1.frags.bin500.awk.bed
wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R1.sorted.bam
wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R2_raw.csv
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/meta_table.csv
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R1_raw.csv
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R1.bed.stringent.bed
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R1.frag_len.txt
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R1.frags.bin500.awk.bed
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R1.sorted.bam
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/h3k27me3_R2_raw.csv

wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/igg_R1_raw.csv
wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/igg_R1.frag_len.txt
wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/igg_R1.frags.bin500.awk.bed
wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/igg_R1.sorted.bam
wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/igg_R2_raw.csv
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/igg_R1_raw.csv
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/igg_R1.frag_len.txt
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/igg_R1.frags.bin500.awk.bed
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/igg_R1.sorted.bam
# wget -nc -P dev/docker/static_reports/test_data/ https://raw.githubusercontent.com/luslab/test-datasets/cutandrun/testdata/dev_reporting/small/igg_R2_raw.csv

# docker run --rm -v "$PWD":/home/repo -it luslab/cutandrun-dev-reporting:latest /home/repo/bin/reporting.py gen_reports \
# --meta /home/repo/dev/docker/static_reports/test_data/meta_table.csv \
# --raw_frag /home/repo/dev/docker/static_reports/test_data/*frag_len.txt \
# --bin_frag /home/repo/dev/docker/static_reports/test_data/*bin500*.bed \
# --seacr_bed /home/repo/dev/docker/static_reports/test_data/*bed.*.bed \
# --bams /home/repo/dev/docker/static_reports/test_data/*sorted.bam \
# --output /home/repo/dev/docker/static_reports/test_output \
# --log /home/repo/dev/docker/static_reports/test_output/log.txt

docker run --rm -v "$PWD":/home/repo -it luslab/cutandrun-dev-reporting:latest /home/repo/bin/reporting.py gen_reports \
--meta /home/repo/dev/docker/static_reports/test_data/meta_table.csv \
--raw_frag /home/repo/dev/docker/static_reports/test_data/*frag_len.txt \
--bin_frag /home/repo/dev/docker/static_reports/test_data/*bin500*.bed \
--seacr_bed /home/repo/dev/docker/static_reports/test_data/*bed.*.bed \
--bams /home/repo/dev/docker/static_reports/test_data/*sorted.bam \
--meta /home/repo/dev/docker/static_reports/test_data/tmp_dir/meta_table.csv \
--raw_frag /home/repo/dev/docker/static_reports/test_data/tmp_dir/*frag_len.txt \
--bin_frag /home/repo/dev/docker/static_reports/test_data/tmp_dir/*bin500*.bed \
--seacr_bed /home/repo/dev/docker/static_reports/test_data/tmp_dir/*bed.*.bed \
--bams /home/repo/dev/docker/static_reports/test_data/tmp_dir/*sorted.bam \
--output /home/repo/dev/docker/static_reports/test_output \
--log /home/repo/dev/docker/static_reports/test_output/log.txt