annotate signac-createObject.R @ 0:6e0b320d8b6a draft default tip

"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
author gaelcge
date Tue, 02 Aug 2022 19:11:27 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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("--h5-file"),
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 = "Filtered peak BC matrix file in h5 format."
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("--metadata"),
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 = "Metadata file."
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("--genome"),
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 = "Genome version."
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("--output-object-file"),
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 = "File name in which to store serialized R matrix object."
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("--fragment-file"),
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 = "Fragment file from CellRanger-ATAC."
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("--min-cells"),
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 = "Lower number of cells identified per peak."
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("--min-features"),
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 = "Minimum number of features per cell to be retained."
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
62 )
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
63 )
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
64
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
65 opt <- wsc_parse_args(option_list)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
66
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
67 suppressPackageStartupMessages(require(Seurat))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
68 suppressPackageStartupMessages(require(Signac))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
69
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
70 atac_h5_matrix <- Read10X_h5(filename = opt$h5_file)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
71 print(paste("counts:",dim(atac_h5_matrix)))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
72
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
73 metadata <- read.csv(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
74 file = opt$metadata,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
75 header = TRUE,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
76 row.names = 1
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
77 )
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
78 print(paste("metadata:",dim(metadata)))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
79
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
80 chrom_assay <- CreateChromatinAssay(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
81 counts = atac_h5_matrix,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
82 sep = c(":", "-"),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
83 genome = opt$genome,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
84 fragments = opt$fragment_file,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
85 min.cells = as.numeric(opt$min_cells),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
86 min.features = as.numeric(opt$min_features)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
87 )
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
88 print(chrom_assay)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
89
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
90 #metadata <- subset(metadata,rownames(metadata) %in% colnames(chrom_assay))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
91
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
92 signac_object <- CreateSeuratObject(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
93 counts = chrom_assay,
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
94 assay = "peaks",
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
95 meta.data = metadata
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
96 )
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
97 print(signac_object)
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
98 print(signac_object[['peaks']])
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
99 print(granges(signac_object))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
100 # cat(c(
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
101 # '# Object summary',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
102 # capture.output(print(signac_object)),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
103 # '\n# Metadata sample',
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
104 # capture.output(head(signac_object@meta.data))
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
105 # ),
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
106 # sep = '\n')
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
107
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
108 # Output to a serialized R object
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
109
6e0b320d8b6a "planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
gaelcge
parents:
diff changeset
110 saveRDS(signac_object, file = opt$output_object_file)