0

リスト上の各サンプル ファイルを取得し、そのサンプルのマトリックスを作成してから、すべてのサンプル マトリックスの 1 つの大きなリストに格納する for ループがあります。

これが私がこれまでに行ったことです:

# load in data ------------------------------------------------------------------

filePaths = getGEOSuppFiles("GSE124395") 
tarF <- list.files(path = "./GSE124395/", pattern = "*.tar", full.names = TRUE) 
untar(tarF, exdir = "./GSE124395/") 
gzipF <- list.files(path = "./GSE124395/", pattern = "*.gz", full.names = TRUE) 
ldply(.data = gzipF, .fun = gunzip) 

#running test loop -------------------------------------------------------------

testlist <- c("./GSE124395//GSM3531672_P301_3_CRYOMIXED11.coutt.csv", 
 "./GSE124395//GSM3531673_P301_4_CRYOMIXED12.coutt.csv",
"./GSE124395//GSM3531674_P301_5_HEP1_1_5.coutt.csv")

LoopList_test <- list()

for (i in 1:length(testlist)){
  
  matrix_test <- read.delim(file =testlist[i])
  matrix_test <- data.frame(matrix_test[,-1], row.names=matrix_test[,1]) 
  matrix_test <- as.matrix(matrix_test) #<- makes the excel file into a matrix 
  
  colname_test <- read.delim(file =testlist[i])
  colname_test <- read.table(file = './GSE124395//GSE124395_celseq_barcodes.192.txt', header = FALSE, row.names = 1) 
  colname_test <- data.frame(colname_test[,-1], col=colname_test[,1]) 
  colname_test <- as.matrix(colname_test) 
  colnames(matrix_test) <- colname_test[,1] 
  
  LoopList_test[[i]]<-matrix_test
}

これは出力です: 1 つの大きなリストの出力の一部

ループが各反復の結果を独自の行列に格納するようにしたいので、それが理にかなっていれば、1 つの巨大な行列リストではなく複数の行列を使用します。この1つの巨大なリストをサブリストに分割するか、ループの結果をリストではなくマトリックス/配列/ベクトルに格納するか、何らかの方法で各反復をループ内の独自の変数に格納する必要があると思います. それらのいずれかを行う方法がわかりません。

読んでくれてありがとう!

アップデート:

したがって、これの要点は、マトリックスを作成して、それらを 1 つのマトリックスに結合することでした。次に、この 1 つのマトリックスを Seurat オブジェクトに変換し、クラスタリングを実行できるようにします。

これまでに行ったことは次のとおりです。基本的に、データセット内の各グループの複数のループを作成し、必要な情報を追加してから、リストを取得し、必要だと思う関数が実際にリストを取得するので、それは私にとって良いことです. 現時点で決定したコードは次のとおりです。

mylist<-list.files(path = "./GSE124395/", pattern = "\\.csv$",full.names = TRUE)

LoopList <- list()

for (i in 1:30){
  
  matrix_input <- read.delim(file =mylist[i])
  matrix_input <- data.frame(matrix_input[,-1], row.names=matrix_input[,1]) 
  matrix_input <- as.matrix(matrix_input) #<- makes the excel file into a matrix 
  
  colname_input <- read.delim(file =mylist[i])
  colname_input <- read.table(file = './GSE124395//GSE124395_celseq_barcodes.192.txt', header = FALSE, row.names = 1) 
  colname_input <- data.frame(colname_input[,-1], col=colname_input[,1]) 
  colname_input <- as.matrix(colname_input) 
  colnames(matrix_input) <- colname_input[,1] 
  
  colnames(matrix_input) <- paste(colnames(matrix_input), "Colorectal_Metastasis", sep = "_")
  P301_pdat <- data.frame("samples" = colnames(matrix_input), "treatment" = "Colorectal_Metastasis") 
  
  sobj <- CreateSeuratObject(counts = matrix_input, min.cells = 0, min.features = 1, 
                             project = "Patient301_Colorectal_Metastasis")
  
  LoopList[[i]]<-sobj
  #LoopList <- assign(paste0("Patient301", i), sobj )
}



# P304 loop ------------------------------------------------------------------------- 


for (i in 31:56){
  
  matrix_input <- read.delim(file =mylist[i])
  matrix_input <- data.frame(matrix_input[,-1], row.names=matrix_input[,1]) 
  matrix_input <- as.matrix(matrix_input) #<- makes the excel file into a matrix 
  
  colname_input <- read.delim(file =mylist[i])
  colname_input <- read.table(file = './GSE124395//GSE124395_celseq_barcodes.192.txt', header = FALSE, row.names = 1) 
  colname_input <- data.frame(colname_input[,-1], col=colname_input[,1]) 
  colname_input <- as.matrix(colname_input) 
  colnames(matrix_input) <- colname_input[,1] 
  
  colnames(matrix_input) <- paste(colnames(matrix_input), "Colorectal_Metastasis", sep = "_")
  P304_pdat <- data.frame("samples" = colnames(matrix_input), "treatment" = "Colorectal_Metastasis") 
  
  sobj <- CreateSeuratObject(counts = matrix_input, min.cells = 0, min.features = 1, 
                             project = "Patient304_Colorectal_Metastasis")
  
  LoopList[[i]]<-sobj
  
}

等々。次に、https://satijalab.org/seurat/articles/integration_large_datasets.htmlに従ってください

sobj.list <- SplitObject(LoopList, split.by = "orig.ident")
joined <- lapply(X = LoopList, FUN = function(x) {
  x <- NormalizeData(x, verbose = FALSE)
  x <- FindVariableFeatures(x, verbose = FALSE)
})


features <- SelectIntegrationFeatures(object.list = joined)
joined <- lapply(X = joined, FUN = function(x) {
  x <- ScaleData(x, features = features, verbose = FALSE)
  x <- RunPCA(x, features = features, verbose = FALSE)
})


anchors <- FindIntegrationAnchors(object.list = joined, reduction = "rpca", 
                                  dims = 1:50)
joined.integrated <- IntegrateData(anchorset = anchors, dims = 1:50)

joined.integrated <- ScaleData(joined.integrated, verbose = FALSE)
joined.integrated <- RunPCA(joined.integrated, verbose = FALSE)
joined.integrated <- RunUMAP(joined.integrated, dims = 1:50)

DimPlot(joined.integrated, group.by = "orig.ident")
DimPlot(joined.integrated, reduction = "umap", split.by = "treatment")

これが確実に機能するかどうかはわかりませんが、これまでに学んだことを反映するためにこの質問を更新すると思いました! 私が学んだ教訓は、リストを入力として受け取る関数を見つけることができるかどうかを確認することだと思います。

4

0 に答える 0