1. 10x下机的三个文件名不符合下游分析的格式,如下
2. 需要整理成如下的格式
3. 脚本如下:
点击查看代码
allfile <- list.files(pattern = '.gz$')
for ( i in unique(substr(allfile, start = 1, stop = 10))){
project_dir=i
if(!file.exists(project_dir)){
dir.create(project_dir)
}
tobeCopy <- list.files('./', pattern=paste0(i,'_*'))
print(tobeCopy)
tarDir= project_dir
# #复制选中文件
sapply(tobeCopy,function(x){file.copy(paste('.',x,sep="/"),tarDir)})
# 修改文件名
files<-list.files(paste0('./',tarDir))
print(files)
for (f in files){
if (isTRUE(grepl('features',f))){
file.rename(paste0(tarDir,'/',f),paste0(tarDir,'/','features.tsv.gz'))
}else if(isTRUE(grepl('barcodes',f))){
file.rename(paste0(tarDir,'/',f),paste0(tarDir,'/','barcodes.tsv.gz'))
}else if(isTRUE(grepl('matrix',f))){
file.rename(paste0(tarDir,'/',f),paste0(tarDir,'/','matrix.mtx.gz'))
}
}
}