|
a |
|
b/bin/archr_gene_activity.R |
|
|
1 |
# Code for running ArchR to get ene expression matrices out |
|
|
2 |
# Useful links: |
|
|
3 |
# https://www.archrproject.com/articles/Articles/tutorial.html |
|
|
4 |
# https://www.archrproject.com/bookdown/calculating-gene-scores-in-archr.html |
|
|
5 |
library(optparse) |
|
|
6 |
|
|
|
7 |
|
|
|
8 |
# https://www.r-bloggers.com/passing-arguments-to-an-r-script-from-command-lines/ |
|
|
9 |
# https://stackoverflow.com/questions/13790610/passing-multiple-arguments-via-command-line-in-r |
|
|
10 |
option_list = list( |
|
|
11 |
make_option(c("-f", "--files"), type="character", default=NULL, |
|
|
12 |
help="Comma separated list of files", metavar="character"), |
|
|
13 |
make_option(c("-n", "--names"), type="character", default=NULL, |
|
|
14 |
help="Comma separated list of names", metavar="character"), |
|
|
15 |
make_option(c("-o", "--out"), type="character", default="archr_gene_act", |
|
|
16 |
help="output file name prefix [default= %default]", metavar = "character"), |
|
|
17 |
make_option(c("-g", "--genome"), type="character", default="hg38", |
|
|
18 |
help="Genome to use [default=%default]", metavar = "character") |
|
|
19 |
); |
|
|
20 |
|
|
|
21 |
opt_parser = OptionParser(option_list=option_list); |
|
|
22 |
opt = parse_args(opt_parser); |
|
|
23 |
|
|
|
24 |
if (is.null(opt$files)){ |
|
|
25 |
print_help(opt_parser) |
|
|
26 |
stop("At least one argument must be supplied (input file).n", call.=FALSE) |
|
|
27 |
} |
|
|
28 |
|
|
|
29 |
library(ArchR) |
|
|
30 |
|
|
|
31 |
addArchRGenome(opt$genome) |
|
|
32 |
|
|
|
33 |
inputFiles = strsplit(opt$files, ",")[[1]] |
|
|
34 |
inputSampleNames = strsplit(opt$names, ",")[[1]] |
|
|
35 |
|
|
|
36 |
ArrowFiles <- createArrowFiles(inputFiles = inputFiles, sampleNames = inputSampleNames, filterTSS = 4, filterFrags = 1000, addTileMat = TRUE, addGeneScoreMat = TRUE) |
|
|
37 |
proj <- ArchRProject(ArrowFiles = ArrowFiles, outputDirectory = opt$out, copyArrows = TRUE) |
|
|
38 |
proj <- addIterativeLSI(ArchRProj = proj, useMatrix = "TileMatrix", name = "IterativeLSI") |
|
|
39 |
proj <- addClusters(input = proj, reducedDims = "IterativeLSI") |
|
|
40 |
|
|
|
41 |
# # https://www.bioconductor.org/help/course-materials/2019/BSS2019/04_Practical_CoreApproachesInBioconductor.html |
|
|
42 |
mat = getMatrixFromProject(proj) |
|
|
43 |
writeMM(assays(mat)[['GeneScoreMatrix']], paste(opt$out, "_gene_activity.mtx", sep="")) # Write the numerical matrix |
|
|
44 |
write.csv(rowData(mat), paste(opt$out, "_gene_activity_var.csv", sep="")) |
|
|
45 |
write.csv(colData(mat), paste(opt$out, "_gene_activity_obs.csv", sep="")) |
|
|
46 |
|
|
|
47 |
# Save the ArchR project |
|
|
48 |
proj <- saveArchRProject(ArchRProj = proj) |