edroaldo / cellrouter

Reconstruction of complex single-cell trajectories using CellRouter
45 stars 21 forks source link

Error in processTrajectories #25

Open cjpark85 opened 5 years ago

cjpark85 commented 5 years ago

Hi, I'm following the tutorials and issues in github to make trajectory using Seurat object. I got this error from processTrajectories.

filename <- "results/paths/cell_edge_weighted_network.txt" write.table(cellrouter@graph$edges, file=filename, sep='\t', row.names=FALSE, col.names = FALSE, quote=FALSE)

Select cluster 11

sources <- c('11') targets <- setdiff(as.vector(cellrouter@sampTab$seurat_clusters), sources) methods <- c("euclidean", "maximum", "manhattan","canberra","binary", 'graph') #graph for distances in KNN

Identify trajectories

cellrouter <- findPaths(cellrouter, column='seurat_clusters', libdir, paste(getwd(), 'results/paths', sep='/'), method="graph") -------------------Transition: 11.0 ----------------------- -------------------Transition: 11.2 ----------------------- -------------------Transition: 11.3 ----------------------- -------------------Transition: 11.4 ----------------------- -------------------Transition: 11.5 ----------------------- -------------------Transition: 11.6 ----------------------- cellrouter <- processTrajectories(cellrouter, rownames(cellrouter@ndata), path.rank=ranks[3], num.cells = 3, neighs = 3, column.ann = 'seurat_clusters', column.color = 'seurat_clusters_colors') [1] "parsing trajectory information" Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") :

edroaldo commented 5 years ago

Sorry for my delayed response. When you use plotKNN, is your cluster 11 connected to the other clusters? You issue is in the findPaths function actually, as it does not seem to find a path between cluster 11 and any others. You can try to increase K in the function buildKNN to make sure you will have a connetced kNN graph.

Please, let me know how it goes.

Thanks!

On Wed, May 8, 2019 at 2:09 PM cjpark85 notifications@github.com wrote:

Hi, I'm following the tutorials and issues in github to make trajectory using Seurat object. I got this error from processTrajectories.

filename <- "results/paths/cell_edge_weighted_network.txt" write.table(cellrouter@graph$edges, file=filename, sep='\t', row.names=FALSE, col.names = FALSE, quote=FALSE)

Select cluster 11

sources <- c('11') targets <- setdiff(as.vector(cellrouter@sampTab$seurat_clusters), sources) methods <- c("euclidean", "maximum", "manhattan","canberra","binary", 'graph') #graph for distances in KNN

Identify trajectories

cellrouter <- findPaths(cellrouter, column='seurat_clusters', libdir, paste(getwd(), 'results/paths', sep='/'), method="graph") -------------------Transition: 11.0 ----------------------- -------------------Transition: 11.2 ----------------------- -------------------Transition: 11.3 ----------------------- -------------------Transition: 11.4 ----------------------- -------------------Transition: 11.5 ----------------------- -------------------Transition: 11.6 ----------------------- cellrouter <- processTrajectories(cellrouter, rownames(cellrouter@ndata),

-

                             path.rank=ranks[3], num.cells = 3, neighs = 3,

-

                             column.ann = 'seurat_clusters', column.color = 'seurat_clusters_colors')

[1] "parsing trajectory information" Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") :

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edroaldo/cellrouter/issues/25, or mute the thread https://github.com/notifications/unsubscribe-auth/ACNJIRZVI3KHJQU4TSHQSBDPUMJLZANCNFSM4HLT7FGQ .

-- Edroaldo

cjpark85 commented 5 years ago

I attached my script as below. I increased K in buildKNN, but it doesn't work.

data_total <- as.data.frame(as.matrix(GetAssayData(object =combined, slot = "counts"))) cellrouter <- CellRouter(rawdata=as.data.frame(data_total), min.cells=0, min.genes=0) [1] "Initializing CellRouter object" metadata_total <- combined@meta.data cellrouter <- addInfo(cellrouter, metadata = metadata_total, colname = 'seurat_clusters', metadata.column='integrated_snn_res.0.5') cellrouter <- addInfo(cellrouter, metadata=metadata_total, colname = 'seurat_clusters', metadata.column = 'integrated_snn_res.0.5') cellrouter <- addInfo(cellrouter, metadata=metadata_total, colname = 'res.0.5', metadata.column = 'integrated_snn_res.0.5') cellrouter <- addInfo(cellrouter, metadata=metadata_total, colname = 'group', metadata.column = 'geno') class(cellrouter@ndata) [1] "data.frame" cellrouter <- Normalize(cellrouter) cellrouter <- scaleData(cellrouter) cellrouter <- computePCA(cellrouter, genes.use=rownames(cellrouter@ndata), num.pcs = 50, seed=42) plot(cellrouter@pca$sdev, xlab='PC', ylab='Standard deviation of PC') cellrouter <- computeTSNE(cellrouter, num.pcs = 12, seed=42, max_iter = 1000) cellrouter <- customSpace(cellrouter, cellrouter@tsne$cell.embeddings) dim(cellrouter@rawdata) [1] 0 0 dim(cellrouter@ndata) [1] 21355 6078 dim(cellrouter@sampTab) [1] 6078 10 cellrouter@ndata[1:5,1:5] AAACCCAAGGATACCG_1 AAACCCACAGAGTTGG_1 AAACCCAGTATGCAAA_1 AAACCCAGTCTTTCAT_1 AAACCCATCGCTCTCA_1 Xkr4 0 0 0 0.000000 0 Gm37686 0 0 0 0.000000 0 Gm38148 0 0 0 0.000000 0 Gm19938 0 0 0 0.000000 0 Sox17 0 0 0 1.231911 0

plotReducedDimension(cellrouter, reduction.type = 'tsne', dims.use = c(1,2), annotation = "seurat_clusters", annotation.color = 'seurat_clusters_color', showlabels = TRUE, 4.5, 3.5, filename='D:/Single-cell_ovary_hCG/6h_050719/tSNE_total1.pdf') cellrouter <- computeTSNE(cellrouter, num.pcs = 20, seed=42, max_iter = 1000) cellrouter <- customSpace(cellrouter, cellrouter@tsne$cell.embeddings) slotNames(cellrouter@ndata) [1] ".Data" "names" "row.names" ".S3Class" cellrouter@sampTab[1:5,] sample_id nGene nUMI conditions seurat_clusters seurat_clusters_color res.0.5 res.0.5_color group group_color AAACCCAAGGATACCG_1 AAACCCAAGGATACCG_1 5057 21978 AAACCCAAGGATACCG_1 8 #A6CEE3 8 #A6CEE3 WT #A6CEE3 AAACCCACAGAGTTGG_1 AAACCCACAGAGTTGG_1 6783 57925 AAACCCACAGAGTTGG_1 10 #A6CEE3 10 #A6CEE3 WT #A6CEE3 AAACCCAGTATGCAAA_1 AAACCCAGTATGCAAA_1 2825 6567 AAACCCAGTATGCAAA_1 3 #A6CEE3 3 #A6CEE3 WT #A6CEE3 AAACCCAGTCTTTCAT_1 AAACCCAGTCTTTCAT_1 3789 12357 AAACCCAGTCTTTCAT_1 7 #A6CEE3 7 #A6CEE3 WT #A6CEE3 AAACCCATCGCTCTCA_1 AAACCCATCGCTCTCA_1 5880 29607 AAACCCATCGCTCTCA_1 3 #A6CEE3 3 #A6CEE3 WT #A6CEE3

markers <- findSignatures(cellrouter, column = "seurat_clusters", pos.only = TRUE, fc.threshold = 0.5) Calculating fold changes... [1] "discovering subpopulation-specific gene signatures" cluster 8 [1] 136 cluster 10 [1] 159 cluster 3 [1] 161 cluster 7 [1] 296 cluster 5 [1] 158 cluster 0 [1] 211 cluster 4 [1] 84 cluster 6 [1] 14 cluster 2 [1] 63 cluster 9 [1] 188 cluster 16 [1] 346 cluster 1 [1] 155 cluster 14 [1] 142 cluster 15 [1] 216 cluster 11 [1] 98 cluster 13 [1] 176 cluster 12 [1] 258 cluster 17 [1] 312 [1] "finding subpopulation markers" top10 <- markers %>% group_by(population) %>% top_n(10, fc) filename <- 'results/path/heatmap_top_10_genes_sorted_populations_total.png' plotSignaturesHeatmap(cellrouter, markers = top10, column.ann = 'seurat_clusters', column.color = 'seurat_clusters_color', threshold = 2, width = 7, height = 7, filename=filename) [1] "here"

0 1 10 11 12 13 14 15 16 17 2 3 4 5 6 7 8 9 1031 737 214 195 151 150 94 72 42 21 681 573 503 398 394 331 264 227 used (Mb) gc trigger (Mb) max used (Mb) Ncells 3408012 182.1 9299112 496.7 9299112 496.7 Vcells 1346928212 10276.3 2434345478 18572.6 2434345363 18572.6

Identification of Trajectories between clusters

cellrouter <- buildKNN(cellrouter, k = 10, column.ann = 'seurat_clusters', num.pcs = 20, sim.type = 'jaccard') [1] "building k-nearest neighbors graph" [1] "updating CellRouter object" Warning message: In write.graph.gml(graph, file, ...) : At foreign.c:2616 :A boolean graph attribute was converted to numeric plotKNN(cellrouter, reduction.type = 'tsne', column.ann = 'seurat_clusters', column.color = 'seurat_clusters_color', width = 5, height = 4, filename='results/path/knn_tsne_original_clusters_total.pdf') Loading required package: sna Loading required package: statnet.common

Attaching package: ‘statnet.common’

The following object is masked from ‘package:bit64’:

order

The following object is masked from ‘package:BiocGenerics’:

order

The following object is masked from ‘package:base’:

order

Loading required package: network network: Classes for Relational Data Version 1.15 created on 2019-04-01. copyright (c) 2005, Carter T. Butts, University of California-Irvine Mark S. Handcock, University of California -- Los Angeles David R. Hunter, Penn State University Martina Morris, University of Washington Skye Bender-deMoll, University of Washington For citation information, type citation("network"). Type help("network-package") to get started.

Attaching package: ‘network’

The following objects are masked from ‘package:igraph’:

%c%, %s%, add.edges, add.vertices, delete.edges, delete.vertices, get.edge.attribute, get.edges, get.vertex.attribute, is.bipartite,
is.directed, list.edge.attributes, list.vertex.attributes, set.edge.attribute, set.vertex.attribute

The following object is masked from ‘package:plyr’:

is.discrete

sna: Tools for Social Network Analysis Version 2.4 created on 2016-07-23. copyright (c) 2005, Carter T. Butts, University of California-Irvine For citation information, type citation("sna"). Type help(package="sna") to get started.

Attaching package: ‘sna’

The following object is masked from ‘package:graph’:

degree

The following objects are masked from ‘package:igraph’:

betweenness, bonpow, closeness, components, degree, dyad.census, evcent, hierarchy, is.connected, neighborhood, triad.census

The following object is masked from ‘package:bit’:

nties

Warning messages: 1: package ‘sna’ was built under R version 3.5.3 2: package ‘statnet.common’ was built under R version 3.5.3 3: package ‘network’ was built under R version 3.5.3

cellrouter <- buildKNN(cellrouter, k = 10, column.ann = 'population', num.pcs = 20, sim.type = 'jaccard') Show Traceback

Rerun with Debug Error in base::order(..., na.last = na.last, decreasing = decreasing) : argument 1 is not a vector

filename <- "results/paths/cell_edge_weighted_network.txt" write.table(cellrouter@graph$edges, file=filename, sep='\t', row.names=FALSE, col.names = FALSE, quote=FALSE) sources <- c('0') targets <- setdiff(as.vector(cellrouter@sampTab$seurat_clusters), sources) methods <- c("euclidean", "maximum", "manhattan","canberra","binary", 'graph') #graph for distances in KNN cellrouter <- findPaths(cellrouter, column='seurat_clusters', libdir, paste(getwd(), 'results/paths', sep='/'), method="graph") -------------------Transition: 0.8 ----------------------- -------------------Transition: 0.10 ----------------------- -------------------Transition: 0.3 ----------------------- -------------------Transition: 0.7 ----------------------- -------------------Transition: 0.5 ----------------------- -------------------Transition: 0.4 ----------------------- -------------------Transition: 0.6 ----------------------- -------------------Transition: 0.2 ----------------------- -------------------Transition: 0.9 ----------------------- -------------------Transition: 0.16 ----------------------- -------------------Transition: 0.1 ----------------------- -------------------Transition: 0.14 ----------------------- -------------------Transition: 0.15 ----------------------- -------------------Transition: 0.11 ----------------------- -------------------Transition: 0.13 ----------------------- -------------------Transition: 0.12 ----------------------- -------------------Transition: 0.17 ----------------------- ranks <- c('path_cost', 'path_flow', 'rank', 'length') cellrouter <- processTrajectories(cellrouter, rownames(cellrouter@ndata), path.rank=ranks[3], num.cells = 3, neighs = 3, column.ann = 'seurat_clusters', column.color = 'seurat_clusters_colors') [1] "parsing trajectory information" Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") :

cellrouter <- buildKNN(cellrouter, k = 20, column.ann = 'seurat_clusters', num.pcs = 20, sim.type = 'jaccard') [1] "building k-nearest neighbors graph" [1] "updating CellRouter object" Warning message: In write.graph.gml(graph, file, ...) : At foreign.c:2616 :A boolean graph attribute was converted to numeric plotKNN(cellrouter, reduction.type = 'tsne', column.ann = 'seurat_clusters', column.color = 'seurat_clusters_color', width = 5, height = 4, filename='D:/results/paths/knn_tsne_original_clusters_total1.pdf')

cellrouter <- buildKNN(cellrouter, k = 20, column.ann = 'population', num.pcs = 20, sim.type = 'jaccard') Show Traceback

Rerun with Debug Error in base::order(..., na.last = na.last, decreasing = decreasing) : argument 1 is not a vector > plotKNN(cellrouter, reduction.type = 'tsne', column.ann = 'population', column.color = 'colors', width = 5, height = 4, filename='results/paths/knn_tsne_CellRouter_clusters1.pdf') Show Traceback

Rerun with Debug Error: Insufficient values in manual scale. 18 needed but only 0 provided.

filename <- "results/paths/cell_edge_weighted_network.txt" write.table(cellrouter@graph$edges, file=filename, sep='\t', row.names=FALSE, col.names = FALSE, quote=FALSE) sources <- c('0') targets <- setdiff(as.vector(cellrouter@sampTab$seurat_clusters), sources) methods <- c("euclidean", "maximum", "manhattan","canberra","binary", 'graph') #graph for distances in KNN

Identify trajectories

cellrouter <- findPaths(cellrouter, column='seurat_clusters', libdir, paste(getwd(), 'results/paths', sep='/'), method="graph") -------------------Transition: 0.8 ----------------------- -------------------Transition: 0.10 ----------------------- -------------------Transition: 0.3 ----------------------- -------------------Transition: 0.7 ----------------------- -------------------Transition: 0.5 ----------------------- -------------------Transition: 0.4 ----------------------- -------------------Transition: 0.6 ----------------------- -------------------Transition: 0.2 ----------------------- -------------------Transition: 0.9 ----------------------- -------------------Transition: 0.16 ----------------------- -------------------Transition: 0.1 ----------------------- -------------------Transition: 0.14 ----------------------- -------------------Transition: 0.15 ----------------------- -------------------Transition: 0.11 ----------------------- -------------------Transition: 0.13 ----------------------- -------------------Transition: 0.12 ----------------------- -------------------Transition: 0.17 -----------------------

ranks <- c('path_cost', 'path_flow', 'rank', 'length') cellrouter <- processTrajectories(cellrouter, rownames(cellrouter@ndata), path.rank=ranks[3], num.cells = 3, neighs = 3, column.ann = 'seurat_clusters', column.color = 'seurat_clusters_colors') [1] "parsing trajectory information" Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") :

cjpark85 commented 5 years ago

Hi,

Today, I tried again and got this error msg. I don't know what is 'file(file, "rt")'. Also, I checked '~/results/path/8.2/' directory, but I couldn't find 'Cells_FlowNetwork_all_paths.txt' file. Is this generated by 'processTrajectories' function? How can I solve this problem?

cellrouter <- processTrajectories(cellrouter, rownames(cellrouter@ndata), path.rank=ranks[3], num.cells = 3, neighs = 3, column.ann = 'seurat_clusters', column.color = 'seurat_clusters_colors') [1] "parsing trajectory information" Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file '~/results/paths/8.2/Cells_FlowNetwork_all_paths.txt': No such file or directory

edroaldo commented 5 years ago

I still did not have a chance to go through your script. My apologies but I should able to so only by Friday.

Thanks for your patience.

On Mon, May 13, 2019, 7:08 PM cjpark85 notifications@github.com wrote:

Hi,

Today, I tried again and got this error msg. I don't know what is 'file(file, "rt")'. Also, I checked '~/results/path/8.2/' directory, but I couldn't find 'Cells_FlowNetwork_all_paths.txt' file. Is this generated by 'processTrajectories' function? How can I solve this problem?

cellrouter <- processTrajectories(cellrouter, rownames(cellrouter@ndata), path.rank=ranks[3], num.cells = 3, neighs = 3, column.ann = 'seurat_clusters', column.color = 'seurat_clusters_colors') [1] "parsing trajectory information" Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file '~/results/paths/8.2/Cells_FlowNetwork_all_paths.txt': No such file or directory

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/edroaldo/cellrouter/issues/25?email_source=notifications&email_token=ACNJIR2ZIQZQ5CFUGS5OBN3PVHRF7A5CNFSM4HLT7FG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVJWOEQ#issuecomment-492005138, or mute the thread https://github.com/notifications/unsubscribe-auth/ACNJIR5HD3PPQMKV3QYF6QTPVHRF7ANCNFSM4HLT7FGQ .

cjpark85 commented 5 years ago

In the meantime, I'll keep trying. Thank you for your reply.

cjpark85 commented 5 years ago

Hello edroaldo, I'm still struggling with this issue. I'm sorry. I need some help.

edroaldo commented 5 years ago

So sorry for the delay. There is something strange with your script as you call buidKNN several times with different parameters for column.ann. Sometimes, column.ann='population', some other times column.ann='seurat_clusters'.

You have to keep it consistent. Please, try to use only seurat_clusters instead. buildKNN, plotKNN, findPaths, they all should use "seurat_clusters":

libdir <- '/home/edroaldo/CellRouter/' cellrouter <- buildKNN(cellrouter, k = 15, column.ann = 'seurat_clusters', num.pcs = 25, sim.type = 'jaccard') ### double-check this.... plotKNN(cellrouter, reduction.type = 'tsne', column.ann = 'seurat_clusters', column.color = 'seurat_clusters_colors', filename='results/knn_tsne.pdf') #increase legend size filename <- "results/paths/cell_edge_weighted_network.txt" write.table(cellrouter@graph$edges, file=filename, sep='\t', row.names=FALSE, col.names = FALSE, quote=FALSE) #input network

change sources and targets for your situation...

sources <- c('2', '4') targets <- c('3', '7') methods <- c("euclidean", "maximum", "manhattan","canberra","binary", 'graph') #graph for distances in KNN cellrouter <- findPaths(cellrouter,sources=sources, targets=targets, column='seurat_clusters', libdir, paste(getwd(), 'results/paths', sep='/'), method="graph")

Thanks!

On Wed, Jun 5, 2019 at 11:02 AM cjpark85 notifications@github.com wrote:

Hello edroaldo, I'm still struggling with this issue. I'm sorry. I need some help.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/edroaldo/cellrouter/issues/25?email_source=notifications&email_token=ACNJIRZB5UIGZUIIA23RHATPY7IIRA5CNFSM4HLT7FG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODW77WLQ#issuecomment-499120942, or mute the thread https://github.com/notifications/unsubscribe-auth/ACNJIR7ICFP62ZT7S43J77DPY7IIRANCNFSM4HLT7FGQ .

-- Edroaldo

cjpark85 commented 5 years ago

Thank you for reviewing this script. I ran again according to your suggestion, but I can see same error. I'm sorry to keep bothering you. Actually, I can't find the file 'Cells_FlowNetwork_all_paths.txt'.

> # Identification of Trajectories between clusters 
> cellrouter <- buildKNN(cellrouter, k = 15, column.ann = 'seurat_clusters', num.pcs = 25, sim.type = 'jaccard')
[1] "building k-nearest neighbors graph"
[1] "updating CellRouter object"
Warning message:
In write.graph.gml(graph, file, ...) :
  At foreign.c:2616 :A boolean graph attribute was converted to numeric
> plotKNN(cellrouter, reduction.type = 'tsne', column.ann = 'seurat_clusters', 
+         column.color = 'seurat_clusters_color', width = 5, height = 4, 
+         filename='D:/cellrouter-master/CellRouter/results/knn_tsne_original_clusters.pdf')
> 
> setwd("D:/cellrouter-master/CellRouter")
> filename <- "results/paths/cell_edge_weighted_network.txt"
> write.table(cellrouter@graph$edges, file=filename, sep='\t', row.names=FALSE, col.names = FALSE, quote=FALSE)
> sources <- c('2', '4')
> targets <- c('3', '7')
> methods <- c("euclidean", "maximum", "manhattan","canberra","binary", 'graph')
> ##Identify trajectories
> cellrouter <- findPaths(cellrouter, column='seurat_clusters', libdir, paste(getwd(), 'results/paths', sep='/'), method="graph")
-------------------Transition: 2.3  -----------------------
-------------------Transition: 2.7  -----------------------
-------------------Transition: 4.3  -----------------------
-------------------Transition: 4.7  -----------------------
> 
> ranks <- c('path_cost', 'path_flow', 'rank', 'length')
> cellrouter <- processTrajectories(cellrouter, rownames(cellrouter@ndata), 
+                                   path.rank=ranks[3], num.cells = 3, neighs = 3,
+                                   column.ann = 'seurat_clusters', column.color = 'seurat_clusters_colors')
[1] "parsing trajectory information"
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
  cannot open file 'D:/cellrouter-master/CellRouter/results/paths/2.3/Cells_FlowNetwork_all_paths.txt': No such file or directory