Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstructNetwork() Error in apply(scoreAll[modGenes[candidates], ], 1, which.max) : dim(X) must have a positive length #346

Open
QWDxxx opened this issue Dec 26, 2024 · 0 comments
Labels
question Further information is requested

Comments

@QWDxxx
Copy link

QWDxxx commented Dec 26, 2024

hi,
I encountered an error when running the ConstructNetwork() function:
Error in apply(scoreAll[modGenes[candidates], ], 1, which.max) : dim(X) must have a positive length
Could it be because modGenes[candidates] is empty in my data? How should I adjust the previous data processing steps to make it run successfully? Although my Seurat object was converted from a Python AnnData object, I have completed the necessary preprocessing steps, including normalization. Additionally, my Seurat object already contains clustering results.

# preprocessing
mtx=readMM(".../sparse_matrix.mtx") 
cl=fread(".../cellinfo.csv",header = T,data.table = F )  
rl=fread(".../imm_geneinfo.csv",header = T,data.table = F)  
rownames(mtx)=rl$V1
colnames(mtx)=cl$index #paste0('c',cl$V2)
meta=cl
rownames(meta)=cl$index
identical(rownames(meta),colnames(mtx))
seurat_obj=CreateSeuratObject(counts = mtx  , 
                             meta.data = meta)
seurat_obj <- NormalizeData(seurat_obj, normalization.method = "LogNormalize", scale.factor = 10000)
seurat_obj <- FindVariableFeatures(seurat_obj, selection.method = "vst", nfeatures = 2000)
all.genes <- rownames(seurat_obj)
seurat_obj <- ScaleData(seurat_obj, features = all.genes)
seurat_obj <- RunPCA(seurat_obj, features = VariableFeatures(object = seurat_obj), npcs = 100)
seurat_obj <- RunHarmony(
  object = seurat_obj,
  group.by.vars = "sample",  
  reduction.use = "pca",      
  reduction.save = "harmony",
  dims = 1:100              
)
seurat_obj <- FindNeighbors(seurat_obj, reduction = 'harmony', dims = 1:90)
seurat_obj <- FindClusters(seurat_obj, resolution = 1.0)
seurat_obj <- RunUMAP(seurat_obj, dims = 1:90,reduction = 'harmony')

# step1
seurat_obj <- SetupForWGCNA(
  seurat_obj,
  gene_select = "fraction", 
  fraction = 0.05,         
  wgcna_name = "SPP1"     
)

# step2
seurat_obj <- MetacellsByGroups(
  seurat_obj = seurat_obj,
  group.by = c("imm_cell_type", "sample"), 
  reduction = 'harmony',              
  k = 25,                              
  max_shared = 10,                     
  ident.group = 'imm_cell_type'   
)

# step3
seurat_obj <- NormalizeMetacells(seurat_obj)

# step4
seurat_obj <- SetDatExpr(
  seurat_obj,
  group_name = "SPP1+Macrophage",    
  group.by = 'imm_cell_type', 
  assay = 'RNA',          
  slot = 'data'          
)

# step5
seurat_obj <- TestSoftPowers(
  seurat_obj,
  networkType = 'signed' 
) 

# step6
seurat_obj <- ConstructNetwork(
  seurat_obj,
  tom_name = 'SPP1_TOM', 
  soft_power = 6,
  setDatExpr=FALSE
)

Error in apply(scoreAll[modGenes[candidates], ], 1, which.max) : dim(X) must have a positive length
Looking forward to your advice; it will be of great help to me.
Thank you so much!

@QWDxxx QWDxxx added the question Further information is requested label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant