Mercurial > repos > gaelcge > r_signac_galaxy
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6e0b320d8b6a |
---|---|
1 #!/usr/bin/env Rscript | |
2 | |
3 # Load optparse we need to check inputs | |
4 | |
5 suppressPackageStartupMessages(require(optparse)) | |
6 | |
7 # Load common functions | |
8 | |
9 suppressPackageStartupMessages(require(workflowscriptscommon)) | |
10 | |
11 # parse options | |
12 | |
13 option_list = list( | |
14 make_option( | |
15 c("--h5-file"), | |
16 action = "store", | |
17 default = NA, | |
18 type = 'character', | |
19 help = "Filtered peak BC matrix file in h5 format." | |
20 ), | |
21 make_option( | |
22 c("--metadata"), | |
23 action = "store", | |
24 default = NA, | |
25 type = 'character', | |
26 help = "Metadata file." | |
27 ), | |
28 make_option( | |
29 c("--genome"), | |
30 action = "store", | |
31 default = NA, | |
32 type = 'character', | |
33 help = "Genome version." | |
34 ), | |
35 make_option( | |
36 c("--output-object-file"), | |
37 action = "store", | |
38 default = NA, | |
39 type = 'character', | |
40 help = "File name in which to store serialized R matrix object." | |
41 ), | |
42 make_option( | |
43 c("--fragment-file"), | |
44 action = "store", | |
45 default = NA, | |
46 type = 'character', | |
47 help = "Fragment file from CellRanger-ATAC." | |
48 ), | |
49 make_option( | |
50 c("--min-cells"), | |
51 action = "store", | |
52 default = NA, | |
53 type = 'character', | |
54 help = "Lower number of cells identified per peak." | |
55 ), | |
56 make_option( | |
57 c("--min-features"), | |
58 action = "store", | |
59 default = NA, | |
60 type = 'character', | |
61 help = "Minimum number of features per cell to be retained." | |
62 ) | |
63 ) | |
64 | |
65 opt <- wsc_parse_args(option_list) | |
66 | |
67 suppressPackageStartupMessages(require(Seurat)) | |
68 suppressPackageStartupMessages(require(Signac)) | |
69 | |
70 atac_h5_matrix <- Read10X_h5(filename = opt$h5_file) | |
71 print(paste("counts:",dim(atac_h5_matrix))) | |
72 | |
73 metadata <- read.csv( | |
74 file = opt$metadata, | |
75 header = TRUE, | |
76 row.names = 1 | |
77 ) | |
78 print(paste("metadata:",dim(metadata))) | |
79 | |
80 chrom_assay <- CreateChromatinAssay( | |
81 counts = atac_h5_matrix, | |
82 sep = c(":", "-"), | |
83 genome = opt$genome, | |
84 fragments = opt$fragment_file, | |
85 min.cells = as.numeric(opt$min_cells), | |
86 min.features = as.numeric(opt$min_features) | |
87 ) | |
88 print(chrom_assay) | |
89 | |
90 #metadata <- subset(metadata,rownames(metadata) %in% colnames(chrom_assay)) | |
91 | |
92 signac_object <- CreateSeuratObject( | |
93 counts = chrom_assay, | |
94 assay = "peaks", | |
95 meta.data = metadata | |
96 ) | |
97 print(signac_object) | |
98 print(signac_object[['peaks']]) | |
99 print(granges(signac_object)) | |
100 # cat(c( | |
101 # '# Object summary', | |
102 # capture.output(print(signac_object)), | |
103 # '\n# Metadata sample', | |
104 # capture.output(head(signac_object@meta.data)) | |
105 # ), | |
106 # sep = '\n') | |
107 | |
108 # Output to a serialized R object | |
109 | |
110 saveRDS(signac_object, file = opt$output_object_file) |