-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_qPCRs.py
198 lines (156 loc) · 6.03 KB
/
process_qPCRs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
"""
===========================
process_qPCRs
===========================
:Author: Jack Riley
:Date: 01/12/2021
Overview
========
Pipeline used in the analysis of qPCR data for RNA stability experiments
Usage
=====
To execute this pipeline in an interactive ShARC session or from a personal
device (not recommended) use the following command:
"python <path_to_pipeline_folder>/process_qPCRs.py make full -v5"
To execute this pipeline to the ShARC cluster, use the following:
"submit_pipeline <path_to_pipeline_folder>/process_qPCRs.py make full -v5"
Configuration
=============
Coming soon...
Input files
===========
csv files placed into inputs.dir folder. Files should be named as follows "$GENENAME_$ISOFORM.csv".
Requirements
============
Packages required:
- Python3
- cgat/cgatcore
- R packages:
- dplyr
- tidyr
- stringr
- data.table
- tibble
- ggplot2
All reqs are installed in the conda environment "stem_utrons".
Pipeline output
===============
Outlying techrep/biorep-filtered .csv file with raw CTs per biorep (sem = sem of techreps) --> "$GENENAME/$GENENAME_$ISOFORM_CTs.csv
Merged 2^-ddCT values --> "$GENENAME/$GENENAME_ddCTs.csv
RNA stability plot comparing retaining and splicing isoform (normalized to spliced isoform) --> "$GENENAME/$GENENAME_stability_plot.png"
Code
====
"""
###################
##### imports #####
###################
from ruffus import *
from ruffus.combinatorics import product
import sys
import os
import shutil
from gffutils import DataIterator as DataIterator
import sqlite3
import subprocess
import glob
import csv
from cgatcore import experiment as E
import cgat.Sra as Sra
from cgatcore import pipeline as P
import cgatpipelines.tasks.rnaseq as RnaSeq
import tempfile
############################################
##### Create a directory for each gene #####
############################################
@follows(mkdir("outputs.dir"))
@transform("inputs.dir/*.csv", regex("(.+)/(.+)_(.+).csv"), output=r"outputs.dir/\2/\2_\3.csv")
def create_dir_structure(infile, outfile):
folder_name = os.path.dirname(outfile)
statement = """mkdir -p %(folder_name)s &&
cp %(infile)s %(outfile)s"""
to_cluster = False
P.run(statement)
#########################
##### RUN R SCRIPTS #####
#########################
@follows(create_dir_structure)
@transform("outputs.dir/*/*.csv", regex("(.+)/(.+)/(.+)_(.+).csv"), output=r"\1/\2/outlying_techreps_removed/otr_\3_\4.csv")
def remove_outlying_techreps(infile, outfile):
folder_name = os.path.dirname(outfile)
current_file = __file__
pipeline_path = os.path.abspath(current_file)
pipeline_directory = os.path.dirname(pipeline_path)
statement = """mkdir -p %(folder_name)s &&
Rscript %(pipeline_directory)s/remove_outlying_techreps.R %(infile)s %(outfile)s"""
to_cluster = False
P.run(statement)
@follows(remove_outlying_techreps)
@transform("outputs.dir/*/outlying_techreps_removed/otr_*", regex("(.+)/(.+)/(.+)/otr_(.+)_(.+).csv"), output=r"\1/\2/merged_techreps/merged_\4_\5.csv")
def merge_techreps(infile, outfile):
folder_name = os.path.dirname(outfile)
current_file = __file__
pipeline_path = os.path.abspath(current_file)
pipeline_directory = os.path.dirname(pipeline_path)
statement = """mkdir -p %(folder_name)s &&
Rscript %(pipeline_directory)s/summarize_CTs.R %(infile)s %(outfile)s"""
to_cluster = False
P.run(statement)
@follows(merge_techreps)
@collate("outputs.dir/*/merged_techreps/*.csv", regex("(.+)/(.+)/(.+)/merged_(.+)_(.+).csv"), output=r"\1/\2/dCTs/dCT_\4.csv")
def calc_dCTs(infile, outfile):
folder_name = os.path.dirname(outfile)
current_file = __file__
pipeline_path = os.path.abspath(current_file)
pipeline_directory = os.path.dirname(pipeline_path)
file1, file2 = infile
statement = """mkdir -p %(folder_name)s &&
Rscript %(pipeline_directory)s/calc_dCT.R %(file1)s %(file2)s %(outfile)s"""
to_cluster = False
P.run(statement)
@follows(calc_dCTs)
@transform("outputs.dir/*/dCTs/*.csv", regex("(.+)/(.+)/(.+)/dCT_(.+).csv"), output=r"\1/\2/outlying_bioreps_removed/obr_dCT_\4.csv")
def remove_outlying_bioreps(infile, outfile):
folder_name = os.path.dirname(outfile)
current_file = __file__
pipeline_path = os.path.abspath(current_file)
pipeline_directory = os.path.dirname(pipeline_path)
statement = """mkdir -p %(folder_name)s &&
Rscript %(pipeline_directory)s/remove_outlying_bioreps.R %(infile)s %(outfile)s"""
to_cluster = False
P.run(statement)
@follows(remove_outlying_bioreps)
@transform("outputs.dir/*/outlying_bioreps_removed/obr*", regex("(.+)/(.+)/(.+)/obr_dCT_(.+).csv"), output=r"\1/\2/ddCT/\4_ddCTs.csv")
def calc_ddCTs(infile, outfile):
folder_name = os.path.dirname(outfile)
current_file = __file__
pipeline_path = os.path.abspath(current_file)
pipeline_directory = os.path.dirname(pipeline_path)
statement = """mkdir -p %(folder_name)s &&
Rscript %(pipeline_directory)s/calc_ddCT.R %(infile)s %(outfile)s"""
to_cluster=False
P.run(statement)
@follows(calc_ddCTs)
@transform("outputs.dir/*/ddCT/*", regex("(.+)/(.+)/(.+)/(.+)_ddCTs.csv"), output=r"\1/\2/\4_stability_plot.png")
def draw_stability_plot(infile, outfile):
folder_name = os.path.dirname(outfile)
current_file = __file__
pipeline_path = os.path.abspath(current_file)
pipeline_directory = os.path.dirname(pipeline_path)
statement = """Rscript %(pipeline_directory)s/draw_stability_plots.R %(infile)s %(outfile)s"""
to_cluster=False
P.run(statement)
###################
##### utility #####
###################
@follows(create_dir_structure, remove_outlying_techreps, merge_techreps, calc_dCTs, remove_outlying_bioreps, calc_ddCTs, draw_stability_plot)
def full():
pass
##################
###### misc ######
##################
def main(argv=None):
if argv is None:
argv = sys.argv
P.main(argv)
if __name__ == "__main__":
sys.exit(P.main(sys.argv))