Gene homology Part 2 – creating directed networks with igraph

[This article was first published on Shirin's playgRound, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In my last post I created a gene homology network for human genes. In this post I want to extend the network to include edges for other species.

First, I am loading biomaRt and extract a list of all available datasets.

<span class="n">library</span><span class="p">(</span><span class="n">biomaRt</span><span class="p">)</span><span class="w">
</span><span class="n">ensembl</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">useMart</span><span class="p">(</span><span class="s2">"ensembl"</span><span class="p">)</span><span class="w">
</span><span class="n">datasets</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">listDatasets</span><span class="p">(</span><span class="n">ensembl</span><span class="p">)</span><span class="w">
</span>

For this network I don’t want to include all species with available information in Biomart because it would get way too messy. So, I am only picking the 11 species below: Human, fruitfly, mouse, C. elegans, dog, zebrafish, chicken, chimp, rat, yeast and pig. For all of these species, I am going to use their respective org.db database to extract gene information.

In order to loop over all species’ org.dbs for installation and loading, I create a new column with the name of the library.

<span class="n">datasets</span><span class="o">$</span><span class="n">orgDb</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="kc">NA</span><span class="w">

</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"hsapiens"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Hs.eg.db"</span><span class="w">
</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"dmel"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Dm.eg.db"</span><span class="w">
</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"mmus"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Mm.eg.db"</span><span class="w">
</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"celegans"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Ce.eg.db"</span><span class="w">
</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"cfam"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Cf.eg.db"</span><span class="w">
</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"drerio"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Dr.eg.db"</span><span class="w">
</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"ggallus"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Gg.eg.db"</span><span class="w">
</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"ptrog"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Pt.eg.db"</span><span class="w">
</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"rnor"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Rn.eg.db"</span><span class="w">
</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"scer"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Sc.sgd.db"</span><span class="w">
</span><span class="n">datasets</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"sscrofa"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="s2">"orgDb"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"org.Ss.eg.db"</span><span class="w">

</span><span class="n">datasets</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="p">[</span><span class="o">!</span><span class="nf">is.na</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">orgDb</span><span class="p">),</span><span class="w"> </span><span class="p">]</span><span class="w">
</span><span class="n">datasets</span><span class="w">
</span>
##                       dataset                              description
## 9    rnorvegicus_gene_ensembl                     Rat genes (Rnor_6.0)
## 13   scerevisiae_gene_ensembl Saccharomyces cerevisiae genes (R64-1-1)
## 14      celegans_gene_ensembl  Caenorhabditis elegans genes (WBcel235)
## 22  ptroglodytes_gene_ensembl            Chimpanzee genes (CHIMP2.1.4)
## 26       sscrofa_gene_ensembl                  Pig genes (Sscrofa10.2)
## 32      hsapiens_gene_ensembl                  Human genes (GRCh38.p7)
## 36       ggallus_gene_ensembl        Chicken genes (Gallus_gallus-5.0)
## 41        drerio_gene_ensembl                 Zebrafish genes (GRCz10)
## 53 dmelanogaster_gene_ensembl                   Fruitfly genes (BDGP6)
## 61     mmusculus_gene_ensembl                  Mouse genes (GRCm38.p5)
## 69   cfamiliaris_gene_ensembl                    Dog genes (CanFam3.1)
##              version         orgDb
## 9           Rnor_6.0  org.Rn.eg.db
## 13           R64-1-1 org.Sc.sgd.db
## 14          WBcel235  org.Ce.eg.db
## 22        CHIMP2.1.4  org.Pt.eg.db
## 26       Sscrofa10.2  org.Ss.eg.db
## 32         GRCh38.p7  org.Hs.eg.db
## 36 Gallus_gallus-5.0  org.Gg.eg.db
## 41            GRCz10  org.Dr.eg.db
## 53             BDGP6  org.Dm.eg.db
## 61         GRCm38.p5  org.Mm.eg.db
## 69         CanFam3.1  org.Cf.eg.db

Now I can load the Ensembl mart for each species.

<span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="m">1</span><span class="o">:</span><span class="n">nrow</span><span class="p">(</span><span class="n">datasets</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="n">ensembl</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">]</span><span class="w">
  </span><span class="n">assign</span><span class="p">(</span><span class="n">paste0</span><span class="p">(</span><span class="n">ensembl</span><span class="p">),</span><span class="w"> </span><span class="n">useMart</span><span class="p">(</span><span class="s2">"ensembl"</span><span class="p">,</span><span class="w"> </span><span class="n">dataset</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">paste0</span><span class="p">(</span><span class="n">ensembl</span><span class="p">)))</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">specieslist</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="w">
</span>

And install all org.db libraries, if necessary.

<span class="n">library</span><span class="p">(</span><span class="n">AnnotationDbi</span><span class="p">)</span><span class="w">

</span><span class="n">load_orgDb</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">orgDb</span><span class="p">){</span><span class="w">
  </span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">orgDb</span><span class="w"> </span><span class="o">%in%</span><span class="w"> </span><span class="n">installed.packages</span><span class="p">()[,</span><span class="s2">"Package"</span><span class="p">]){</span><span class="w">
    </span><span class="n">source</span><span class="p">(</span><span class="s2">"https://bioconductor.org/biocLite.R"</span><span class="p">)</span><span class="w">
    </span><span class="n">biocLite</span><span class="p">(</span><span class="n">orgDb</span><span class="p">)</span><span class="w">
  </span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">sapply</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">orgDb</span><span class="p">,</span><span class="w"> </span><span class="n">load_orgDb</span><span class="p">,</span><span class="w"> </span><span class="n">simplify</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">,</span><span class="w"> </span><span class="n">USE.NAMES</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">)</span><span class="w">
</span>

Once they are all installed, I can load the libraries.

<span class="n">lapply</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">orgDb</span><span class="p">,</span><span class="w"> </span><span class="n">require</span><span class="p">,</span><span class="w"> </span><span class="n">character.only</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">)</span><span class="w">
</span>

Because I want to exctract and compare information on homologus genes for all possible combinations of species, they need to have a common identifier. To find them, I first produce a list with all available keytypes and then ask for common elements using rlist’s list.common() function.

<span class="n">keytypes_list</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">lapply</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">orgDb</span><span class="p">,</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="kc">NULL</span><span class="p">)</span><span class="w">
</span><span class="nf">names</span><span class="p">(</span><span class="n">keytypes_list</span><span class="p">)</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">paste</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">orgDb</span><span class="p">)</span><span class="w">

</span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">orgDb</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">orgDb</span><span class="p">){</span><span class="w">
  </span><span class="n">keytypes_list</span><span class="p">[[</span><span class="n">orgDb</span><span class="p">]]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">keytypes</span><span class="p">(</span><span class="n">get</span><span class="p">(</span><span class="n">orgDb</span><span class="p">))</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">library</span><span class="p">(</span><span class="n">rlist</span><span class="p">)</span><span class="w">
</span><span class="n">list.common</span><span class="p">(</span><span class="n">keytypes_list</span><span class="p">)</span><span class="w">
</span>
##  [1] "ENTREZID"    "ENZYME"      "EVIDENCE"    "EVIDENCEALL" "GENENAME"   
##  [6] "GO"          "GOALL"       "ONTOLOGY"    "ONTOLOGYALL" "PATH"       
## [11] "PMID"        "REFSEQ"      "UNIPROT"

Entrez IDs are available for all species, so these are the keys I am using as gene identifiers. I am first creating a table of homologous genes for each species with all other species separately by looping over the datasets table.

<span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="m">1</span><span class="o">:</span><span class="n">nrow</span><span class="p">(</span><span class="n">datasets</span><span class="p">)){</span><span class="w">
  </span><span class="n">orgDbs</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">orgDb</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w">
  </span><span class="n">values</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">keys</span><span class="p">(</span><span class="n">get</span><span class="p">(</span><span class="n">orgDbs</span><span class="p">),</span><span class="w"> </span><span class="n">keytype</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"ENTREZID"</span><span class="p">)</span><span class="w">

  </span><span class="n">ds</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w">
  </span><span class="n">mart</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">useMart</span><span class="p">(</span><span class="s2">"ensembl"</span><span class="p">,</span><span class="w"> </span><span class="n">dataset</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">paste</span><span class="p">(</span><span class="n">ds</span><span class="p">))</span><span class="w">
  </span><span class="n">print</span><span class="p">(</span><span class="n">mart</span><span class="p">)</span><span class="w">

  </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="o">!</span><span class="nf">is.na</span><span class="p">(</span><span class="n">listFilters</span><span class="p">(</span><span class="n">mart</span><span class="p">)</span><span class="o">$</span><span class="n">name</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"^entrezgene$"</span><span class="p">,</span><span class="w"> </span><span class="n">listFilters</span><span class="p">(</span><span class="n">mart</span><span class="p">)</span><span class="o">$</span><span class="n">name</span><span class="p">)])){</span><span class="w">
    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="o">!</span><span class="nf">is.na</span><span class="p">(</span><span class="n">listAttributes</span><span class="p">(</span><span class="n">mart</span><span class="p">)</span><span class="o">$</span><span class="n">name</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"^entrezgene$"</span><span class="p">,</span><span class="w"> </span><span class="n">listAttributes</span><span class="p">(</span><span class="n">mart</span><span class="p">)</span><span class="o">$</span><span class="n">name</span><span class="p">)])){</span><span class="w">
    </span><span class="n">print</span><span class="p">(</span><span class="s2">"TRUE"</span><span class="p">)</span><span class="w">
    </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">species</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">specieslist</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
      </span><span class="n">print</span><span class="p">(</span><span class="n">species</span><span class="p">)</span><span class="w">
      </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">species</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">ds</span><span class="p">){</span><span class="w">
        </span><span class="n">assign</span><span class="p">(</span><span class="n">paste</span><span class="p">(</span><span class="s2">"homologs"</span><span class="p">,</span><span class="w"> </span><span class="n">orgDbs</span><span class="p">,</span><span class="w"> </span><span class="n">species</span><span class="p">,</span><span class="w"> </span><span class="n">sep</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"_"</span><span class="p">),</span><span class="w"> </span><span class="n">getLDS</span><span class="p">(</span><span class="n">attributes</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"entrezgene"</span><span class="p">),</span><span class="w">
                                                                     </span><span class="n">filters</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"entrezgene"</span><span class="p">,</span><span class="w">
                                                                     </span><span class="n">values</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">values</span><span class="p">,</span><span class="w">
                                                                     </span><span class="n">mart</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mart</span><span class="p">,</span><span class="w">
                                                                     </span><span class="n">attributesL</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"entrezgene"</span><span class="p">),</span><span class="w">
                                                                     </span><span class="n">martL</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">get</span><span class="p">(</span><span class="n">species</span><span class="p">)))</span><span class="w">
      </span><span class="p">}</span><span class="w">
    </span><span class="p">}</span><span class="w">
  </span><span class="p">}</span><span class="w">
  </span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">
</span>

Now I sort and combine these tables into one big table and remove duplicate entries.

<span class="n">library</span><span class="p">(</span><span class="n">dplyr</span><span class="p">)</span><span class="w">

</span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="m">1</span><span class="o">:</span><span class="n">nrow</span><span class="p">(</span><span class="n">datasets</span><span class="p">)){</span><span class="w">
  </span><span class="n">orgDbs</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">orgDb</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w">
  </span><span class="n">values</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">data.frame</span><span class="p">(</span><span class="n">GeneID</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">keys</span><span class="p">(</span><span class="n">get</span><span class="p">(</span><span class="n">orgDbs</span><span class="p">),</span><span class="w"> </span><span class="n">keytype</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"ENTREZID"</span><span class="p">))</span><span class="w">
  </span><span class="n">values</span><span class="o">$</span><span class="n">GeneID</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">as.character</span><span class="p">(</span><span class="n">values</span><span class="o">$</span><span class="n">GeneID</span><span class="p">)</span><span class="w">
  </span><span class="n">ds</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w">

  </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">j</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="m">1</span><span class="o">:</span><span class="nf">length</span><span class="p">(</span><span class="n">specieslist</span><span class="p">)){</span><span class="w">
    </span><span class="n">species</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">specieslist</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="w">

    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">j</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">1</span><span class="p">){</span><span class="w">
      </span><span class="n">homologs_table</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">values</span><span class="w">
    </span><span class="p">}</span><span class="w">

    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">species</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">ds</span><span class="p">){</span><span class="w">
      </span><span class="n">homologs_species</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">get</span><span class="p">(</span><span class="n">paste</span><span class="p">(</span><span class="s2">"homologs"</span><span class="p">,</span><span class="w"> </span><span class="n">orgDbs</span><span class="p">,</span><span class="w"> </span><span class="n">species</span><span class="p">,</span><span class="w"> </span><span class="n">sep</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"_"</span><span class="p">))</span><span class="w">
      </span><span class="n">homologs_species</span><span class="o">$</span><span class="n">EntrezGene.ID</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">as.character</span><span class="p">(</span><span class="n">homologs_species</span><span class="o">$</span><span class="n">EntrezGene.ID</span><span class="p">)</span><span class="w">

      </span><span class="n">homologs</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">left_join</span><span class="p">(</span><span class="n">values</span><span class="p">,</span><span class="w"> </span><span class="n">homologs_species</span><span class="p">,</span><span class="w"> </span><span class="n">by</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"GeneID"</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"EntrezGene.ID"</span><span class="p">))</span><span class="w">
      </span><span class="n">homologs</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">homologs</span><span class="p">[</span><span class="o">!</span><span class="n">duplicated</span><span class="p">(</span><span class="n">homologs</span><span class="o">$</span><span class="n">GeneID</span><span class="p">),</span><span class="w"> </span><span class="p">]</span><span class="w">
      </span><span class="n">colnames</span><span class="p">(</span><span class="n">homologs</span><span class="p">)[</span><span class="m">2</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">paste</span><span class="p">(</span><span class="n">species</span><span class="p">)</span><span class="w">

      </span><span class="n">homologs_table</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">left_join</span><span class="p">(</span><span class="n">homologs_table</span><span class="p">,</span><span class="w"> </span><span class="n">homologs</span><span class="p">,</span><span class="w"> </span><span class="n">by</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"GeneID"</span><span class="p">)</span><span class="w">
  </span><span class="p">}</span><span class="w">
  </span><span class="p">}</span><span class="w">

  </span><span class="n">colnames</span><span class="p">(</span><span class="n">homologs_table</span><span class="p">)[</span><span class="m">1</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">paste</span><span class="p">(</span><span class="n">ds</span><span class="p">)</span><span class="w">

  </span><span class="n">assign</span><span class="p">(</span><span class="n">paste</span><span class="p">(</span><span class="s2">"homologs_table"</span><span class="p">,</span><span class="w"> </span><span class="n">ds</span><span class="p">,</span><span class="w"> </span><span class="n">sep</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"_"</span><span class="p">),</span><span class="w"> </span><span class="n">homologs_table</span><span class="p">)</span><span class="w">
</span><span class="p">}</span><span class="w">


</span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="m">1</span><span class="o">:</span><span class="n">nrow</span><span class="p">(</span><span class="n">datasets</span><span class="p">)){</span><span class="w">
  </span><span class="n">ds</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w">

  </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">1</span><span class="p">){</span><span class="w">
    </span><span class="n">homologs_table_combined</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">get</span><span class="p">(</span><span class="n">paste</span><span class="p">(</span><span class="s2">"homologs_table"</span><span class="p">,</span><span class="w"> </span><span class="n">ds</span><span class="p">,</span><span class="w"> </span><span class="n">sep</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"_"</span><span class="p">))</span><span class="w">
    </span><span class="n">homologs_table_combined</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">homologs_table_combined</span><span class="p">[,</span><span class="w"> </span><span class="n">order</span><span class="p">(</span><span class="n">colnames</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">))]</span><span class="w">
  </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w">
    </span><span class="n">homologs_table_species</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">get</span><span class="p">(</span><span class="n">paste</span><span class="p">(</span><span class="s2">"homologs_table"</span><span class="p">,</span><span class="w"> </span><span class="n">ds</span><span class="p">,</span><span class="w"> </span><span class="n">sep</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"_"</span><span class="p">))</span><span class="w">
    </span><span class="n">homologs_table_species</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">homologs_table_species</span><span class="p">[,</span><span class="w"> </span><span class="n">order</span><span class="p">(</span><span class="n">colnames</span><span class="p">(</span><span class="n">homologs_table_species</span><span class="p">))]</span><span class="w">

    </span><span class="n">homologs_table_combined</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">rbind</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">,</span><span class="w"> </span><span class="n">homologs_table_species</span><span class="p">)</span><span class="w">
  </span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">homologs_table_combined</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">homologs_table_combined</span><span class="p">[</span><span class="o">!</span><span class="n">duplicated</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">),</span><span class="w"> </span><span class="p">]</span><span class="w">
</span>

Now each row in the table shows one gene and its homologs in all of the 11 species. Some genes have multiple homologs in other species (e.g. gene 44071 of the fruitfly has two homologs in zebrafish).

<span class="n">head</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">)</span><span class="w">
</span>
##   celegans_gene_ensembl cfamiliaris_gene_ensembl
## 1                    NA                       NA
## 2                    NA                   477699
## 3                    NA                   477023
## 4                173979                   490207
## 5                179795                   607852
## 6                177055                       NA
##   dmelanogaster_gene_ensembl drerio_gene_ensembl ggallus_gene_ensembl
## 1                         NA                  NA                   NA
## 2                      44071                  NA                   NA
## 3                         NA              431754               770094
## 4                      38864              406283                   NA
## 5                      36760              794259               395373
## 6                    3772179              541489               421909
##   hsapiens_gene_ensembl mmusculus_gene_ensembl ptroglodytes_gene_ensembl
## 1                    NA                     NA                        NA
## 2                     2                 232345                    465372
## 3                    30                 235674                    460268
## 4                    34                  11364                    469356
## 5                    47                 104112                    454672
## 6                    52                  11431                    458990
##   rnorvegicus_gene_ensembl scerevisiae_gene_ensembl sscrofa_gene_ensembl
## 1                    24152                       NA                   NA
## 2                    24153                       NA               403166
## 3                    24157                   854646            100515577
## 4                    24158                       NA               397104
## 5                    24159                   854310                   NA
## 6                    24161                   856187            100737301

In order to create the cooccurrence matrix, I am converting gene names to “1” and NAs to “0” and multiply the matrix with its transposed self. This is now the basis for igraph’s graph_from_adjacency_matrix() function with which I’m creating a directed network. Before plotting the network, I am removing multiple entries and loops.

<span class="n">homologs_table_combined_matrix</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">as.matrix</span><span class="p">(</span><span class="n">ifelse</span><span class="p">(</span><span class="nf">is.na</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">),</span><span class="w"> </span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">))</span><span class="w">

</span><span class="n">co_occurrence</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">t</span><span class="p">(</span><span class="n">as.matrix</span><span class="p">(</span><span class="n">homologs_table_combined_matrix</span><span class="p">))</span><span class="w"> </span><span class="o">%*%</span><span class="w"> </span><span class="n">as.matrix</span><span class="p">(</span><span class="n">homologs_table_combined_matrix</span><span class="p">)</span><span class="w">

</span><span class="n">library</span><span class="p">(</span><span class="n">igraph</span><span class="p">)</span><span class="w">
</span><span class="n">g</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">graph_from_adjacency_matrix</span><span class="p">(</span><span class="n">co_occurrence</span><span class="p">,</span><span class="w">
                                 </span><span class="n">weighted</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">,</span><span class="w">
                                 </span><span class="n">diag</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">FALSE</span><span class="p">,</span><span class="w">
                                 </span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"directed"</span><span class="p">)</span><span class="w">

</span><span class="n">g</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">simplify</span><span class="p">(</span><span class="n">g</span><span class="p">,</span><span class="w"> </span><span class="n">remove.multiple</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">,</span><span class="w"> </span><span class="n">remove.loops</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">)</span><span class="w">
</span>

I am also preparing a node annotation table with colors for each species group and the count of unique gene identifiers for species.

<span class="n">datasets</span><span class="p">[,</span><span class="w"> </span><span class="m">2</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">gsub</span><span class="p">(</span><span class="s2">"(.*)( genes (.*))"</span><span class="p">,</span><span class="w"> </span><span class="s2">"\\1"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="p">[,</span><span class="w"> </span><span class="m">2</span><span class="p">])</span><span class="w">
</span><span class="n">datasets</span><span class="o">$</span><span class="n">description</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"Saccharomyces"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">description</span><span class="p">)]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"Yeast"</span><span class="w">
</span><span class="n">datasets</span><span class="o">$</span><span class="n">description</span><span class="p">[</span><span class="n">grep</span><span class="p">(</span><span class="s2">"elegans"</span><span class="p">,</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">description</span><span class="p">)]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"C. elegans"</span><span class="w">

</span><span class="n">datasets</span><span class="o">$</span><span class="n">group</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">ifelse</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">description</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"Yeast"</span><span class="p">,</span><span class="w"> </span><span class="s2">"fungus"</span><span class="p">,</span><span class="w">
                         </span><span class="n">ifelse</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">description</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"C. elegans"</span><span class="p">,</span><span class="w"> </span><span class="s2">"roundworm"</span><span class="p">,</span><span class="w">
                                </span><span class="n">ifelse</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">description</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"Chicken"</span><span class="p">,</span><span class="w"> </span><span class="s2">"bird"</span><span class="p">,</span><span class="w">
                                       </span><span class="n">ifelse</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"Zebrafish"</span><span class="p">,</span><span class="w"> </span><span class="s2">"fish"</span><span class="p">,</span><span class="w">
                                              </span><span class="n">ifelse</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">description</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"Fruitfly"</span><span class="p">,</span><span class="w"> </span><span class="s2">"insect"</span><span class="p">,</span><span class="w"> </span><span class="s2">"mammal"</span><span class="p">)))))</span><span class="w">

</span><span class="n">list</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">as.character</span><span class="p">(</span><span class="n">unique</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">))</span><span class="w">

</span><span class="n">library</span><span class="p">(</span><span class="n">RColorBrewer</span><span class="p">)</span><span class="w">
</span><span class="n">set3</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">brewer.pal</span><span class="p">(</span><span class="nf">length</span><span class="p">(</span><span class="n">list</span><span class="p">),</span><span class="w"> </span><span class="s2">"Set3"</span><span class="p">)</span><span class="w">

</span><span class="n">datasets</span><span class="o">$</span><span class="n">col</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="kc">NA</span><span class="w">
</span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="m">1</span><span class="o">:</span><span class="nf">length</span><span class="p">(</span><span class="n">list</span><span class="p">)){</span><span class="w">
  </span><span class="n">datasets</span><span class="p">[</span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">list</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="w"> </span><span class="s2">"col"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">set3</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">no_genes</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">as.data.frame</span><span class="p">(</span><span class="n">apply</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">,</span><span class="w"> </span><span class="m">2</span><span class="p">,</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="nf">length</span><span class="p">(</span><span class="n">unique</span><span class="p">(</span><span class="n">x</span><span class="p">))))</span><span class="w">
</span><span class="n">no_genes</span><span class="o">$</span><span class="n">dataset</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">rownames</span><span class="p">(</span><span class="n">no_genes</span><span class="p">)</span><span class="w">
</span><span class="n">colnames</span><span class="p">(</span><span class="n">no_genes</span><span class="p">)[</span><span class="m">1</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"no_genes"</span><span class="w">

</span><span class="n">library</span><span class="p">(</span><span class="n">dplyr</span><span class="p">)</span><span class="w">
</span><span class="n">datasets</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">left_join</span><span class="p">(</span><span class="n">datasets</span><span class="p">,</span><span class="w"> </span><span class="n">no_genes</span><span class="p">,</span><span class="w"> </span><span class="n">by</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"dataset"</span><span class="p">)</span><span class="w">

</span><span class="n">datasets</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="p">[</span><span class="n">order</span><span class="p">(</span><span class="n">datasets</span><span class="o">$</span><span class="n">dataset</span><span class="p">),</span><span class="w"> </span><span class="p">]</span><span class="w">
</span>

I also want to have the proportion of genes that have homologs in each of the respective other species as edge attributes. I am preparing an extra table for this of all possible combinations of nodes.

<span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="m">1</span><span class="o">:</span><span class="n">ncol</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">)){</span><span class="w">
  </span><span class="n">input</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">unique</span><span class="p">(</span><span class="n">na.omit</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">[,</span><span class="w"> </span><span class="n">i</span><span class="p">]))</span><span class="w">
  </span><span class="n">homologs_table_combined_subset</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">homologs_table_combined</span><span class="p">[</span><span class="o">!</span><span class="nf">is.na</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">[,</span><span class="w"> </span><span class="n">i</span><span class="p">]),</span><span class="w"> </span><span class="p">]</span><span class="w">

  </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">j</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="m">1</span><span class="o">:</span><span class="n">ncol</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">)){</span><span class="w">
    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">j</span><span class="p">){</span><span class="w">
      </span><span class="n">output</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">unique</span><span class="p">(</span><span class="n">na.omit</span><span class="p">(</span><span class="n">homologs_table_combined_subset</span><span class="p">[,</span><span class="w"> </span><span class="n">j</span><span class="p">]))</span><span class="w">
      
      </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">1</span><span class="w"> </span><span class="o">&</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">2</span><span class="p">){</span><span class="w">
        </span><span class="n">edge_table</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">data.frame</span><span class="p">(</span><span class="n">source</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">colnames</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">)[</span><span class="n">i</span><span class="p">],</span><span class="w"> 
                                 </span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">colnames</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">)[</span><span class="n">j</span><span class="p">],</span><span class="w"> 
                                 </span><span class="n">weight</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">length</span><span class="p">(</span><span class="n">output</span><span class="p">)</span><span class="o">/</span><span class="nf">length</span><span class="p">(</span><span class="n">input</span><span class="p">))</span><span class="w">
      </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w">
        </span><span class="n">table</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">data.frame</span><span class="p">(</span><span class="n">source</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">colnames</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">)[</span><span class="n">i</span><span class="p">],</span><span class="w"> 
                            </span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">colnames</span><span class="p">(</span><span class="n">homologs_table_combined</span><span class="p">)[</span><span class="n">j</span><span class="p">],</span><span class="w"> 
                            </span><span class="n">weight</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">length</span><span class="p">(</span><span class="n">output</span><span class="p">)</span><span class="o">/</span><span class="nf">length</span><span class="p">(</span><span class="n">input</span><span class="p">))</span><span class="w">
        </span><span class="n">edge_table</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">rbind</span><span class="p">(</span><span class="n">edge_table</span><span class="p">,</span><span class="w"> </span><span class="n">table</span><span class="p">)</span><span class="w">
      </span><span class="p">}</span><span class="w">
    </span><span class="p">}</span><span class="w">
  </span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="n">list</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">as.character</span><span class="p">(</span><span class="n">unique</span><span class="p">(</span><span class="n">edge_table</span><span class="o">$</span><span class="n">source</span><span class="p">))</span><span class="w">

</span><span class="n">edge_table</span><span class="o">$</span><span class="n">col</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="kc">NA</span><span class="w">
</span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="m">1</span><span class="o">:</span><span class="nf">length</span><span class="p">(</span><span class="n">list</span><span class="p">)){</span><span class="w">
  </span><span class="n">edge_table</span><span class="p">[</span><span class="n">edge_table</span><span class="o">$</span><span class="n">source</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">list</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="w"> </span><span class="s2">"col"</span><span class="p">]</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">set3</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w">
</span><span class="p">}</span><span class="w">
</span>

And finally I can produce the plot:

<span class="n">V</span><span class="p">(</span><span class="n">g</span><span class="p">)</span><span class="o">$</span><span class="n">color</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">col</span><span class="w">
</span><span class="n">V</span><span class="p">(</span><span class="n">g</span><span class="p">)</span><span class="o">$</span><span class="n">label</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">description</span><span class="w">
</span><span class="n">V</span><span class="p">(</span><span class="n">g</span><span class="p">)</span><span class="o">$</span><span class="n">size</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">datasets</span><span class="o">$</span><span class="n">no_genes</span><span class="o">/</span><span class="m">2000</span><span class="w">
</span><span class="n">E</span><span class="p">(</span><span class="n">g</span><span class="p">)</span><span class="o">$</span><span class="n">arrow.size</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="m">3</span><span class="w">
</span><span class="n">E</span><span class="p">(</span><span class="n">g</span><span class="p">)</span><span class="o">$</span><span class="n">width</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">edge_table</span><span class="o">$</span><span class="n">weight</span><span class="o">*</span><span class="m">25</span><span class="w">

</span><span class="n">plot</span><span class="p">(</span><span class="n">g</span><span class="p">,</span><span class="w">
     </span><span class="n">vertex.label.font</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w">
     </span><span class="n">vertex.shape</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"sphere"</span><span class="p">,</span><span class="w">
     </span><span class="n">vertex.label.cex</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">3</span><span class="p">,</span><span class="w">
     </span><span class="n">vertex.label.color</span><span class="w"> </span><span class="o"&g...

To leave a comment for the author, please follow the link and comment on their blog: Shirin's playgRound.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)