Hi h.fushimi.x689,
When you write annotate genes, do you mean transcripts? (if so, there is a risk that you will have multiple transcripts that are encoded by the same gene)
This is a quick and dirty method that I have used to get a "quick" overview of my transcripts:
1) Extract the IDs for the transcripts represented in your heatmap (this is an example where the first column is the ID) and write them into a txt file (in R):
IDs <- as.data.frame(df[,1])
write.table(IDs, file="IDs.txt", row.names=FALSE, col.names=FALSE, quote=FALSE, sep",")
2) In the terminal (if you have not already done it), remove the "description" from your fasta file - and keep only the ID's (Trinity IDs in this case) sed -e 's/^\(>[^[:space:]]*\).*/\1/' my.fasta > mymodified.fasta
3) Extract sequences based on the ID's extracted from R:
sudo pip install pyfaidx
xargs faidx input.fasta < IDs.txt > output.fasta
4) Load the output fasta into the free version of Blast2Go: https://www.blast2go.com/
5) Copy paste the Transcript IDs and the annotation to each of them into a data frame (I used excel) and save it as csv (for example annotation.csv)
6) Load the annotation.csv into R and merge it with the data-frame containing your heatmap data (annotations = annotation.csv):
annotation <- merge(annotations, tmp_df, by="target_id")
#Set the target_id's as row names - Description in this case is the annotation description obtained from blast2go
rownames(annotation) <- annotation$Description
anno<-annotation[,-c(1:2)] # delete column 1 & 2 containing target id's and description not used as row_names
#Heatmap2
## Row clustering (adjust here distance/linkage methods to what you need!)
hp <- hclust(as.dist(1-cor(t(anno), method="pearson")), method="complete")
## Column clustering (adjust here distance/linkage methods to what you need!)
hs <- hclust(as.dist(1-cor(anno, method="pearson")), method="complete")
#Make a 6x8 inch image at 600dpi:
ppi <- 600
png("myheatmap.png", width=10*ppi, height=6*ppi, res=ppi)
heatmap.2(as.matrix(anno),
Rowv=as.dendrogram(hp),
Colv=as.dendrogram(hs),
scale="row",
density.info="none",
trace="none",
cexRow=0.7, cexCol = 0.8,
col=bluered(75),
margins = c(6,27),
keysize=1,
key.par = list(cex=0.7),
dendrogram="column")
dev.off()
Cheers, B
My guess is that these annotations are added manually. But there might be a package in R for it, which I am not aware of yet.
can you try this one (with links):