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

plotPathHeatmap function "invalid 'row.names' length" #20

Open
hgb1111 opened this issue Feb 18, 2019 · 5 comments
Open

plotPathHeatmap function "invalid 'row.names' length" #20

hgb1111 opened this issue Feb 18, 2019 · 5 comments

Comments

@hgb1111
Copy link

hgb1111 commented Feb 18, 2019

When I run:

genelist <- c('Hspg2', 'Kdr', 'Plvap', 'Gja4')
plottrajectories(cellrouter, '8.9', genelist, rescale = TRUE, columns=1, width=5, height=2, filename='results/dynamics_curve.pdf')

the plottrajectories function runs just fine.

When I try to run plotPathHeatmap with the same genelist:

genelist <- c('Hspg2', 'Kdr', 'Plvap', 'Gja4')
plotPathHeatmap(cellrouter, '8.9', genelist, 2, 4, 2, dir = 'results/')

I get the error:

Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length 

How can I make a heatmap with the desired genes?

@edroaldo
Copy link
Owner

edroaldo commented Feb 18, 2019 via email

@hgb1111
Copy link
Author

hgb1111 commented Feb 18, 2019

Thanks for the quick response! Here is the source code of the plotPathHeatmap function I am using. Downloaded Dec. 14th 2018

setGeneric("plotPathHeatmap", function(object, paths, genelist, threshold=2, width, height, dir) standardGeneric("plotPathHeatmap"))
setMethod("plotPathHeatmap",
          signature="CellRouter",
          definition=function(object, paths, genelist, threshold, width, height, dir){

            #plotPathHeatmap <- function(corsPaths, pathsInfo, graph, num_genes, width, height, dir){
            corsPaths <- object@correlation
            pathsInfo <- object@pathsinfo
            sampTab <- object@sampTab

            for(path in paths){
              genelist2 <- intersect(genelist, rownames(pathsInfo$distr[[path]]))
              tmpexpr <- pathsInfo$distr[[path]][genelist2,]
              tmpexpr <- center_with_threshold(tmpexpr, 1.5) #double check this....
              #andf <- data.frame(sampTab[pathsInfo$path[[path]], 'community',])
              andf <- data.frame(sampTab[pathsInfo$path[[path]], 'population',])
              rownames(andf) <- pathsInfo$path[[path]]
              colnames(andf) <- c('subpopulation')

              target_colors <- unique(sampTab[pathsInfo$path[[path]], 'colors',])
              names(target_colors) <- unique(andf$subpopulation)
              ann_colors = list(
                subpopulation = target_colors
              )
              from <- sapply(strsplit(path, split='.', fixed=TRUE), function(x){x[1]})
              to <- sapply(strsplit(path, split='.', fixed=TRUE), function(x){x[2]})
              title <- paste('Transition ', from, ' ', to, sep='')
              file <- paste(dir, 'heatmap_top_', path, '.pdf', sep='')
              labels <- sapply(strsplit(rownames(tmpexpr), split='__', fixed=TRUE), function(x){x[1]})
              #pheatmap(center_with_threshold(tmpexpr, threshold), cluster_rows = FALSE,
              #pheatmap(tmpexpr, cluster_rows = TRUE,
              pheatmap(tmpexpr, cluster_rows = FALSE,
                       cluster_cols = FALSE,
                       annotation_col = andf, annotation_colors=ann_colors,
                       show_colnames = FALSE, border=FALSE, main=title, filename = file,
                       width = width, height=height, labels_row = labels)

              #to show plot in the report
              pheatmap(tmpexpr, cluster_rows = FALSE,
                       cluster_cols = FALSE,
                       annotation_col = andf, annotation_colors=ann_colors,
                       show_colnames = FALSE, border=FALSE, main=title, labels_row = labels)

            }
          }
)

@edroaldo
Copy link
Owner

edroaldo commented Feb 19, 2019 via email

@hgb1111
Copy link
Author

hgb1111 commented Feb 25, 2019

Okay so I found the source of the error:
it boils down to the fact that this function assumes your different cell types are annotated in the SampTab as 'population' which is buried in the line of code below:

andf <- data.frame(sampTab[pathsInfo$path[[path]], 'population',])

Unlike other functions in cell router, which allow you to write in your column annotation, this function assumes that the column is named 'population.' The problem can be fixed by changing either 1) the name of your cell identities column to "population" or 2) going ahead and changing it in the source code to whatever the name of your column is, mine was "SrtClust" as I was working from clusters annotated in Seurat

If you're lazy and change it in the source code like I did, you will also need to change the command that chooses where to get the colors from - I changed 'colors' to 'SrtClust_color' as it was named in the SampTab

target_colors <- unique(sampTab[pathsInfo$path[[path]], 'colors',])

@edroaldo
Copy link
Owner

edroaldo commented Feb 26, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants