Question: Character matrix to Numeric matrix for heatmap
1
gravatar for bioinfo8
3.5 years ago by
bioinfo8120
bioinfo8120 wrote:

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!

rna-seq next-gen sleuth R • 1.6k views
ADD COMMENTlink modified 3.5 years ago • written 3.5 years ago by bioinfo8120

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 mean paste?). 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).

ADD REPLYlink written 3.5 years ago by ddiez1.8k

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). Regarding unite function, I have used it to merge two columns and renamed the final data.frame as unite. I know that numeric object can be passed to heatmap.2 and there only I am stuck because of one character column and hence posted my query for a possible guidance. :)

ADD REPLYlink modified 3.5 years ago • written 3.5 years ago by bioinfo8120

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.

ADD REPLYlink written 3.5 years ago by zx87549.2k

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!

ADD REPLYlink written 3.5 years ago by bioinfo8120
1

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.

ADD REPLYlink written 3.5 years ago by zx87549.2k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1873 users visited in the last hour