Skip to content

Instantly share code, notes, and snippets.

@TTTPOB
Created September 24, 2021 07:15
Show Gist options
  • Save TTTPOB/39ba42e0dbbedfbcc659a9330319fdea to your computer and use it in GitHub Desktop.
Save TTTPOB/39ba42e0dbbedfbcc659a9330319fdea to your computer and use it in GitHub Desktop.
read matrix file generated by deeptools computeMatrix into R
readComputeMatrixResult<-function(dfPath,offset=6){
library(rjson)
library(tidyverse)
df<-read_tsv(file=dfPath,col_names=F,col_types=cols(),skip=1)
metadata<-readLines(gzfile(dfPath),1)%>%str_remove("^@")%>%fromJSON(json_str=.)
dfSplited<-list()
for(i in 1:length(metadata$sample_labels)){
dfSplited<-c(
dfSplited,
df[
(offset+1 + metadata$sample_boundaries[i]):
(offset + metadata$sample_boundaries[i+1])
]%>%list
)
}
names(dfSplited)<-metadata$sample_labels
return(dfSplited)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment