Created
September 24, 2021 07:15
-
-
Save TTTPOB/39ba42e0dbbedfbcc659a9330319fdea to your computer and use it in GitHub Desktop.
read matrix file generated by deeptools computeMatrix into R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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