Skip to content

Commit c2537db

Browse files
committed
Add plotting of deamination frequencies
1 parent bc7cd1f commit c2537db

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

conf/process.config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ process {
176176
ext.args = "${params.doublestranded ? 'doublestranded' : ''}"
177177
}
178178

179+
withName:"PLOT_DEAM" {
180+
publishDir = [
181+
[
182+
path: "${outdir}/stats",
183+
mode: "copy",
184+
saveAs: { "${meta.RG}_04_deamination_positions/${meta.Family}.${meta.Species}.plot.jpg" },
185+
pattern: "*.jpg",
186+
],
187+
]
188+
}
189+
179190
withName:"SAMTOOLS_MPILEUP" {
180191
ext.args = "--output-BP-5 --no-output-ends --no-output-ins --no-output-del --no-output-ins --no-output-del --min-BQ 0 -R --ff 0"
181192
publishDir = [
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
process PLOT_DEAM{
2+
container (workflow.containerEngine ? "merszym/pandas_plt:nextflow" : null)
3+
tag "${meta.id}"
4+
label 'local'
5+
6+
input:
7+
tuple val(meta), path(tsv), path(confidence)
8+
9+
output:
10+
path("*.jpg") , emit: jpg
11+
12+
script:
13+
"""
14+
plot_deam_patterns.py ${tsv} ${meta.Family}.${meta.Species}
15+
"""
16+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#! /usr/bin/env python3
2+
3+
import pandas as pd
4+
import seaborn as sns
5+
import matplotlib.pyplot as plt
6+
import sys
7+
8+
df = pd.read_csv(sys.argv[1], sep='\t')
9+
title = sys.argv[2]
10+
11+
df = df.melt(id_vars=['Sub'])
12+
13+
bases = list(set(df['Sub']))
14+
palette = {x:'lightgrey' for x in bases}
15+
palette.update({'C->T':'red', "G->A":'black'})
16+
17+
#now plot the rate
18+
# fix the positions first
19+
20+
df['Position in Sequence'] = df.apply(lambda x: int(x.variable) if int(x.variable) > 0 else int(x.variable)+21, axis=1)
21+
df['Frequency'] = df['value'].apply(lambda x: float(x))
22+
df['Substitution'] = df['Sub']
23+
24+
g = sns.lineplot(
25+
data = df,
26+
x='Position in Sequence',
27+
y='Frequency',
28+
hue='Substitution',
29+
palette=palette
30+
)
31+
32+
ticks = list(range(0,11))
33+
ticks.extend(list(range(-10,0)))
34+
35+
# Update the x-ticks
36+
g.set_ylabel("Frequency [%]")
37+
g.set_xticks(list(range(0,21)))
38+
g.set_xticklabels(ticks)
39+
g.axvline(x=10.5, ymax=0.5, ls="--", color='grey')
40+
g.set_title(title)
41+
42+
plt.tight_layout()
43+
plt.savefig(f"{title}_plot.jpg", dpi=300)

workflows/08_deamination_stats.nf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ include { BAM_DEAM_STATS as BAM_DEAM_BEST } from '../modules/local/bam_deam_sta
22
include { BAM_DEAM_STATS as BAM_DEAM_FIXED } from '../modules/local/bam_deam_stats'
33
include { MASK_DEAMINATION } from '../modules/local/mask_deamination'
44
include { SAMTOOLS_MPILEUP } from '../modules/local/samtools_mpileup'
5+
include { PLOT_DEAM } from '../modules/local/pandas_plot_deam'
56

67
workflow deamination_stats {
78
take: best
@@ -22,6 +23,8 @@ workflow deamination_stats {
2223
}
2324
.set{ best }
2425

26+
ch_positions = BAM_DEAM_BEST.out.positions
27+
2528
// Now for the fixed
2629

2730
BAM_DEAM_FIXED( fixed )
@@ -40,10 +43,17 @@ workflow deamination_stats {
4043
}
4144
.set{ fixed }
4245

46+
ch_positions = ch_positions.mix(BAM_DEAM_FIXED.out.positions)
47+
48+
// Plot deamination rates
49+
PLOT_DEAM(ch_positions)
50+
51+
// And continue with the fixed files...
52+
4353
MASK_DEAMINATION( fixed )
4454

4555
//
46-
// And create Mpileups
56+
// Create Mpileups
4757
//
4858

4959
SAMTOOLS_MPILEUP( MASK_DEAMINATION.out.bam )

0 commit comments

Comments
 (0)