-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsubread_featurecount_script.R
44 lines (28 loc) · 1.09 KB
/
rsubread_featurecount_script.R
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
library(Rsubread)
args <- commandArgs(trailingOnly = TRUE)
if (length(args) != 5) {
cat("Usage: Rscript featureCounts_script.R <bamFilesDirectory> <gtfFile> <isPairedEnd> <numThreads> <outputCSV>\n")
quit(status = 1)
}
filepath <- args[1]
gtfFile <- args[2]
isPairedEnd <- as.logical(args[3])
numThreads <- as.numeric(args[4])
outputCSV <- args[5]
if (!grepl("/$", filepath)) {
filepath <- paste0(filepath, "/")
}
filenames <- list.files(path = filepath, pattern = "\\.bam$", full.names = TRUE)
if (length(filenames) == 0) {
cat("No BAM files found in the specified directory.\n")
quit(status = 1)
}
# Running featureCounts
featurecounts <- featureCounts(files = filenames,
annot.ext = gtfFile,
isGTFAnnotationFile = TRUE,
nthreads = numThreads,
isPairedEnd = isPairedEnd,
countReadPairs = TRUE)
write.csv(featurecounts$counts, file = outputCSV, row.names = TRUE)
cat("FeatureCounts analysis completed successfully.\n")