Mercurial > repos > gaelcge > r_signac_galaxy
annotate signac-subset.R @ 0:6e0b320d8b6a draft default tip
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
author | gaelcge |
---|---|
date | Tue, 02 Aug 2022 19:11:27 +0000 |
parents | |
children |
rev | line source |
---|---|
0
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
1 #!/usr/bin/env Rscript |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
2 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
3 # Load optparse we need to check inputs |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
4 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
5 suppressPackageStartupMessages(require(optparse)) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
6 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
7 # Load common functions |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
8 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
9 suppressPackageStartupMessages(require(workflowscriptscommon)) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
10 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
11 # parse options |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
12 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
13 option_list = list( |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
14 make_option( |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
15 c("--signac-object"), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
16 action = "store", |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
17 default = NA, |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
18 type = 'character', |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
19 help = "" |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
20 ), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
21 make_option( |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
22 c("--peak-region-fragments-min"), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
23 action = "store", |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
24 default = NA, |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
25 type = 'character', |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
26 help = "." |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
27 ), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
28 make_option( |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
29 c("--peak-region-fragments-max"), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
30 action = "store", |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
31 default = NA, |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
32 type = 'character', |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
33 help = "." |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
34 ), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
35 make_option( |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
36 c("--pct-reads-in-peaks"), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
37 action = "store", |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
38 default = NA, |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
39 type = 'character', |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
40 help = "." |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
41 ), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
42 make_option( |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
43 c("--blacklist-ratio"), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
44 action = "store", |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
45 default = NA, |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
46 type = 'character', |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
47 help = "." |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
48 ), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
49 make_option( |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
50 c("--nucleosome-signal"), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
51 action = "store", |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
52 default = NA, |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
53 type = 'character', |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
54 help = "." |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
55 ), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
56 make_option( |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
57 c("--tss-enrichment"), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
58 action = "store", |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
59 default = NA, |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
60 type = 'character', |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
61 help = "." |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
62 ), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
63 make_option( |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
64 c("--output-object-file"), |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
65 action = "store", |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
66 default = NA, |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
67 type = 'character', |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
68 help = "File name in which to store serialized R matrix object." |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
69 ) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
70 ) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
71 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
72 opt <- wsc_parse_args(option_list) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
73 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
74 suppressPackageStartupMessages(require(Signac)) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
75 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
76 # extract gene annotations from EnsDb |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
77 signac_object <- readRDS(file = opt$signac_object) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
78 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
79 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
80 ## transform input parameters to numeric |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
81 peak_region_fragments_min <- as.numeric(opt$peak_region_fragments_min) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
82 peak_region_fragments_max <- as.numeric(opt$peak_region_fragments_max) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
83 pct_reads_in_peaks_var <- as.numeric(opt$pct_reads_in_peaks) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
84 blacklist_ratio_var <- as.numeric(opt$blacklist_ratio) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
85 nucleosome_signal_var <- as.numeric(opt$nucleosome_signal) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
86 tss_enrichment_var <- as.numeric(opt$tss_enrichment) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
87 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
88 print("Signac object before filtering:") |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
89 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
90 signac_object |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
91 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
92 signac_object <- subset(signac_object, peak_region_fragments > peak_region_fragments_min) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
93 signac_object <- subset(signac_object, peak_region_fragments < peak_region_fragments_max) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
94 signac_object <- subset(signac_object, pct_reads_in_peaks > pct_reads_in_peaks_var) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
95 signac_object <- subset(signac_object, blacklist_ratio < blacklist_ratio_var) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
96 signac_object <- subset(signac_object, nucleosome_signal < nucleosome_signal_var) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
97 signac_object <- subset(signac_object, TSS.enrichment > tss_enrichment_var) |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
98 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
99 print("Signac object after filtering:") |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
100 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
101 signac_object |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
102 |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
103 # Output to a serialized R object |
6e0b320d8b6a
"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff
changeset
|
104 saveRDS(signac_object, file = opt$output_object_file) |