Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dfjenkins3/1be7e50c9f46cdeaf65025a9ec484865 to your computer and use it in GitHub Desktop.
Save dfjenkins3/1be7e50c9f46cdeaf65025a9ec484865 to your computer and use it in GitHub Desktop.
Create SCTKE from Rsubread and multiqc
library(singleCellTK)
createSCTKE_from_Rsubread_and_multiqc <- function(matdir, r1multi, r2multi){
r1annot <- read.table(r1multi, sep="\t", row.names = 1, header=TRUE)
colnames(r1annot) <- paste0(colnames(r1annot), "_R1")
rownames(r1annot) <- gsub("_R1$", "", rownames(r1annot))
r2annot <- read.table(r2multi, sep="\t", row.names = 1, header=TRUE)
colnames(r2annot) <- paste0(colnames(r2annot), "_R2")
rownames(r2annot) <- gsub("_R2$", "", rownames(r2annot))
if(any(rownames(r1annot)!=rownames(r2annot))){
stop("malformed multiqcdata")
}
matlist <- list()
for (i in c("featureCounts", "fpkm", "fpkmlog", "tpm", "tpmlog", "stats")){
message(i)
if(i == "featureCounts"){
name <- "counts"
} else {
name <- i
}
for (j in rownames(r1annot)){
message(j)
infile <- list.files(path = matdir, pattern=paste0(j,"\\.",i,"$"))
currfile <- read.table(file.path(matdir, infile), header=F, row.names = 1, sep="\t")
colnames(currfile) <- j
if(is.null(matlist[[name]])){
matlist[[name]] <- currfile
} else {
matlist[[name]] <- cbind(matlist[[name]], currfile)
}
}
}
fullannot <- cbind(r1annot, r2annot, t(matlist[["stats"]]))
outdata <- createSCE(assayFile = matlist[["counts"]], annotFile = fullannot, inputDataFrames = TRUE, createLogCounts = TRUE)
for (i in names(matlist)[!(names(matlist) %in% c("counts", "stats"))]){
assay(outdata, i) <- as.matrix(matlist[[i]])
}
return(outdata)
}
latent_capetown_2018_SCE <- createSCTKE_from_Rsubread_and_multiqc(
matdir = "~/Downloads/t/",
r1multi = "~/Downloads/latent_capetown_2018_r1_multiqc_report_data/multiqc_fastqc.txt",
r2multi = "~/Downloads/latent_capetown_2018_r2_multiqc_report_data/multiqc_fastqc.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment