Hello,
I have created a heatmap for the top 100 differentially expressed transcripts with EnsembIDs and three samples (RNA-seq -> kallisto -> sleuth) .
>heatmap.2(log(tmp_df+1), trace="none", density.info="none", scale="row")
Now I am interested to add gene names in the heatmap for e.g. EnsemblD_genename. For this purpose, I have proceeded as follows:
1) Created "ext_gene" column in tmp_df
>tmp_df["ext_gene"] <- NA
2) Matched target_id from tmp_df with target_id of top_100new (containing ext_gene)
>tmp_df$ext_gene <- top_100new$ext_gene[match(tmp_df$target_id, top_100new$target_id)]
3) Merged target_id and ext_gene columns in tmp_df (target_id__ext_gene column in place of target_id and ext_gene columns)
>unite <- unite(tmp_df, target_id__ext_gene, target_id, ext_gene, sep='_')
4) I was unable to convert "unite" to numeric matrix because one column "target_id__ext_gene" has NA in some rows for e.g. ENSEMBL00001_NA, so I tried to replace NA with NONE.
>unite$target_id__ext_gene <- gsub ('NA', 'NONE', unite$target_id__ext_gene)
5) But, still I am unable to convert "unite" into numeric matrix because column "target_id__ext_gene" has character class. I have tried to use
>unite$target_id__ext_gene <- as.numeric(as.character(unite$target_id__ext_gene))
but, it converts all rows of column "target_id__ext_gene" into NA.
Any help in this regard will be greatly appreciated.
Thank you!
Several things are unclear from the code you posted. One is that you use
unite
both as a function and as a data.frame/list (maybe you meanpaste
?). At any rate, remember one thing: In R, a matrix is of a single type, either numeric or character (or other). A data.frame can have multiple types, but the object you must pass to heatmap.2 has to be numeric. So this:tmp_df["ext_gene"]
is not a good idea. Maybe you need to set the rownames or pass the vector of names to some parameter in heatmap.2 (not very familiar with this function).Thanks for the reply.
I have used
tmp_df["ext_gene"] <- NA
to create new column only so that I can later copy its values from other data.frame (top_100new
). Regardingunite
function, I have used it to merge two columns and renamed the final data.frame asunite
. I know that numeric object can be passed toheatmap.2
and there only I am stuck because of one character column and hence posted my query for a possible guidance. :)Hello gbioinfo!
It appears that your post has been cross-posted to another site: http://stackoverflow.com/q/41238772/680068
This is typically not recommended as it runs the risk of annoying people in both communities.
Hello zx8754, I did not get any helpful reply here and hence posted there. I was not aware that both are inter-connected and under same moderation. Thanks for pointing out!
No problem. They are not connected, but users overlap on both sides, it is good to have it linked in case you get an answer from either of the sites. You will get more attention and solutions very quickly on SO/biostar if you provide minimal reproducible data.