Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# dependencies
library("moduleColor")
library("dynamicTreeCut")
library("RColorBrewer")
# import data
canna.z = read.csv("~/Downloads/canna-z.csv",header=T,row.names=1)
#https://github.com/mattsarrasin/canna-gen/blob/master/sample_description_list-2.txt
id2name = read.csv('~/Downloads/results-20200327-155748.csv')
# exponential scale-out for contrast
m = 400
canna.cor = cor(t(canna.z))
canna.cor[ canna.cor > 0 ] = log10(canna.cor[ canna.cor > 0 ] * m)
canna.cor[ canna.cor < 0 ] = -log10(canna.cor[ canna.cor < 0 ] * -m)
# identify modules
canna.cor.clust = hclust(dist(canna.cor))
canna.cor.clust.mod = cutreeDynamic(canna.cor.clust)
canna.cor.clust.mod.col = labels2colors(canna.cor.clust.mod)
# plot heatmap
#heatmap(canna.cor,scale="none",col=rev(brewer.pal(11,"RdBu")),cexRow=0.1,cexCol=0.1,main="C.sativa strains' genetic similarity",labRow=as.vector(apply(id2name[match(colnames(canna.cor), id2name[,1]),],1,function(x)paste(unlist(as.vector(x)),sep="::",collapse="--"))))
heatmap(canna.cor,scale="none",col=rev(brewer.pal(11,"RdBu")),cexRow=0.1,cexCol=0.1,main="C.sativa strains' genetic similarity",labRow=as.vector(apply(id2name[match(colnames(canna.cor), id2name[,1]),],1,function(x)paste(unlist(as.vector(x)),sep="::",collapse="--"))),ColSideColors=canna.cor.clust.mod.col)
cat ~/Downloads/bq-results-20200324-224807-nnfac6belb28.csv | grep -v ref | perl -e '%cc=();while(my $line=<>){chomp $line;my($ref,$bin,$sample,undef,undef,$z)=split/,/,$line;$bin/=1000;$ref=~s/chr//;$col=sprintf("%0.3f",$ref+$bin);$cc{$col}=1;$mat{$sample}{$col}=$z;}my $in=0;foreach my $row (sort keys %mat){if(!$in){$in++;print "sample";foreach $bin (sort keys %cc){print ",$bin"}print "\n";}print $row; foreach $col (sort keys %cc){print ",".($mat{$row}{$col}||0);}print "\n"}' > ~/Downloads/canna-z.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.