{"id":501,"date":"2022-05-18T17:09:49","date_gmt":"2022-05-18T09:09:49","guid":{"rendered":"https:\/\/linguopeng.top\/?p=501"},"modified":"2022-05-18T18:54:39","modified_gmt":"2022-05-18T10:54:39","slug":"tsne%ef%bc%8cmantel","status":"publish","type":"post","link":"https:\/\/linguopeng.top\/?p=501","title":{"rendered":"tSNE\uff0cmantel"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code># Huang WC, Liu Y, Zhang X, Zhang CJ, Zou D, Zheng S, Xu W, Luo Z, Liu F, Li M. \n#Comparative genomic analysis reveals metabolic flexibility of Woesearchaeota. \n#Nat Commun. 2021 Sep 6;12(1):5281. doi: 10.1038\/s41467-021-25565-9\nlibrary(ggplot2)\nlibrary(ggmap)\nlibrary(sp)\nlibrary(maptools)\nlibrary(maps)\nwoese&lt;-read.table('Data4.tsv',sep='\\t',row.names=1,header=T,check.name=FALSE)\ncolors&lt;-c('#d6274a','#4ea94a','#f6d534','#4862ab','#ea7a3a','#7e3a8e','#75c7d0','#b0569c','#f5bbbe','#b9cf39','#955f25')\n#ncol&lt;-c('#b0569c','#ea7a3a','#75c7d0','#b9cf39','#7e3a8e','#4ea94a','#f6d534','#4862ab','#955f25','#f5bbbe','#d6274a')\nnames(colors)&lt;-unique(woese$biotope)\nmp&lt;-NULL\nmapworld&lt;-borders(\"world\",colour = \"gray50\",fill=\"white\") #\nmp2&lt;-mp+geom_jitter(data=woese,aes(x=longitude_deg,y=latitude_deg,size=woese$`relative abundance of Woesearchaeota (%)`,color=woese$biotope)) +\n  scale_color_manual(values=colors) +\n  xlab('longitude') +\n  ylab('latitude')\nmp2\nmp2&lt;-mp2+theme(legend.position='bottom')\nmp2\nlibrary(Rtsne)\nlibrary(vegan)\nwunifrac&lt;-read.table('unweighted_unifrac_otu_woese_beta.tsv',sep='\\t',header=T,row.names = 1)\nwunifrac&#91;,ncol(wunifrac)]\nwunifrac.m&lt;-as.matrix(wunifrac)\ntsne_model&lt;-Rtsne(wunifrac.m,num_threads = 38,check_duplicates = F)\ndf_tsne&lt;-as.data.frame(tsne_model$Y)\nrownames(df_tsne)&lt;-rownames(wunifrac)\np&lt;-ggplot(df_tsne,aes(x=V1,y=V2))+geom_point()\nmeta&lt;-woese\np\nsalinity&lt;-meta&#91;which(rownames(meta)==rownames(df_tsne)),'empo_2']\nsalinity&lt;-meta&#91;rownames(df_tsne),'empo_2']\nbiotope&lt;-meta&#91;which(rownames(meta)==rownames(df_tsne)),'biotope']\nbiotope&lt;-meta&#91;rownames(df_tsne),'biotope']\ndf_tsne$saline&lt;-salinity\ndf_tsne$biotope&lt;-biotope\n\n##\n##PERMANOVA on unifrac using empo_2 and biotope\n\nempo_2&lt;-adonis(wunifrac.m~salinity)\n\nbiotope_test&lt;-adonis(wunifrac.m~biotope)\n\nlibrary(grid)\ngrob2 &lt;- grobTree(textGrob(\"p-value=0.001\\nR^2=0.325\", x=0.75,  y=0.95, hjust=0,\n                           gp=gpar(col=\"black\", fontface=\"italic\")))\ngrob1&lt;-grobTree(textGrob(\"p-value=0.001\\nR^2=0.138\", x=0.75,  y=0.95, hjust=0,\n                         gp=gpar(col=\"black\", fontface=\"italic\")))\n\np&lt;-ggplot(df_tsne,aes(x=V1,y=V2,color=saline))+geom_point()+xlab('tSNE 1')+ylab('tSNE 2')+annotation_custom(grob1)\n#p&lt;-p+theme(legend.position='none')\np1&lt;-ggplot(df_tsne,aes(x=V1,y=V2,color=biotope))+geom_point()+scale_color_manual(values = colors)+xlab('tSNE 1')+ylab('tSNE 2')+annotation_custom(grob2)\n#p1&lt;-p1+theme(legend.position='none')\n\n##alpha diversity\nalpha_div&lt;-read.table('alpha_div_pd_whole_tree.txt',sep='\\t',header=T,row.names = 1)\nalpha_div$biotope&lt;-meta&#91;rownames(alpha_div),'biotope']\np0&lt;-ggplot(alpha_div,aes(x=biotope,y=PD_whole_tree,fill=biotope))+\n  geom_boxplot()+\n  scale_fill_manual(values = colors)+\n  guides(fill=FALSE)+\n  theme(axis.text.x=element_text(angle=45,hjust = 1,vjust=1))\n## Show data points if n less than and equal 10\nsaline_env_alpha&lt;-alpha_div&#91;which(alpha_div$biotope=='saline environment'),]\nmarine_water_alpha&lt;-alpha_div&#91;which(alpha_div$biotope=='marine water'),]\nsaltmarshes_alpha&lt;-alpha_div&#91;which(alpha_div$biotope=='Saltmarshes'),]\np0&lt;-p0+\n  geom_point(data=saline_env_alpha,aes(x=biotope,y=PD_whole_tree))+\n  geom_point(data=marine_water_alpha,aes(x=biotope,y=PD_whole_tree))+\n  geom_point(data=saltmarshes_alpha,aes(x=biotope,y=PD_whole_tree))\n\nlibrary(gridExtra)\nlay1 &lt;- rbind(\n  c(1,1),\n  c(2,3))\nplots&lt;-list(p0,p,p1)\nfinal_plot&lt;-grid.arrange(grobs=plots,layout_matrix=lay1)\n#ggsave('G:\/woese_revision\/fig1\/fig1_revised.pdf',final_plot,height =10 ,width=14,dpi=300,useDingbats=FALSE)\n#ggsave('G:\/woese_revision\/fig1\/fig1c.pdf',p,height =5 ,width=5,dpi=300,useDingbats=FALSE)\n\n###Post hoc test\na&lt;-aov(PD_whole_tree~biotope,data=alpha_div)\ntk&lt;-TukeyHSD(a)\n###Post hoc abudance test\nabu_t&lt;-aov(woese$`relative abundance of Woesearchaeota (%)`~biotope,data=woese)\ntK_abu_t&lt;-TukeyHSD(abu_t)\n\n##Mantel \nsimple_cor&lt;-meta&#91;8:15]\nsimple_cor$Woesearchaeota&lt;-meta&#91;17]\nsimple_cor&lt;-simple_cor&#91;rownames(alpha_div),]\nmantel_f&lt;-function(otu,env){\n  library(vegan)\n  library(dplyr)\n  vars&lt;-colnames(env)\n  models&lt;-list()\n  for (i in seq_along(vars)){\n    if (vars&#91;i]!='Woesearchaeota'){\n      env_sub&lt;-na.omit(env&#91;vars&#91;i]])\n      otu_sub&lt;-otu&#91;rownames(env_sub),rownames(env_sub)]\n      otu_dist&lt;-as.matrix(otu_sub)\n      dis&lt;-vegdist(env_sub,method='euclidean')\n      model&lt;-vegan::mantel(otu_dist,dis,permutations = 999)\n      name&lt;-vars&#91;i]\n      num&lt;-length(rownames(env_sub))\n      statistic&lt;-model$statistic\n      signif&lt;-model$signif\n      models&#91;&#91;i]]&lt;-data.frame(name=name,statistic=statistic,signif=signif,number=num,row.names=NULL)\n    }\n  }\n  models %>% bind_rows()\n}\n\ninfo&lt;-mantel_f(wunifrac,simple_cor)\n\nlibrary(gridExtra)\nlay1 &lt;- rbind(\n  c(1,1),\n  c(2,2),\n  c(3,4))\nplots&lt;-list(mp2,p0,p,p1)\nfinal_plot&lt;-grid.arrange(grobs=plots,layout_matrix=lay1)\nggsave('fig1.pdf',final_plot,height =18,width=13,units = \"in\")<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2022\/05\/fig1-7-scaled.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1849\" height=\"2560\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2022\/05\/fig1-7-scaled.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-502\"  sizes=\"auto, (max-width: 1849px) 100vw, 1849px\" \/><\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-501","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=501"}],"version-history":[{"count":2,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/501\/revisions"}],"predecessor-version":[{"id":504,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/501\/revisions\/504"}],"wp:attachment":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}