Compute specific and intersection elements with R#
This is my first posts about R language, my first english post and my first R
package: venn.compute
, which
use case in bioinformatics is compare list of genes.
This R package is intended to compute specific elements in intersections of Venn diagram instead of plot.
Custom reader of files to create list of character arrays (such requiered for this package and VennDiagram).
Compute specific elements in intersections of Venn diagram in memory or write to files.
Plot with VennDiagram.
Example#
Use 3 files in tests
directory with names primes.txt
, even.txt
y
fibo.txt
whose content are primes, even and Fibonacci numbers until 20.
Install#
You can install from GitHub as:
devtools::install_github("cosmoscalibur/venn.compute")
Downloading GitHub repo cosmoscalibur/venn.compute@master
formatR (1.6 -> 1.7) [CRAN]
Installing 1 packages: formatR
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
✔ checking for file ‘/tmp/RtmpT7UVx3/remotes61d65fec5ae1/cosmoscalibur-venn.compute-6f4fb43/DESCRIPTION’ ...
─ preparing ‘venn.compute’:
✔ checking DESCRIPTION meta-information
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘venn.compute_1.1.0.tar.gz’
If an error about TAR executable is showed (common in Linux with Anaconda,
sh: 1: /bin/gtar: not found
), you need to setup your TAR path.
Sys.setenv(TAR = "/bin/tar")
How to use#
First, load the package.
library(venn.compute)
Lectura de archivos#
Read files#
This is a custom reader to include multiple files and associate its custom names, returned a named list of character arrays (each element is an element line of the file).
sets <- read.lists_from_files(c(file.path("tests", "primes.txt"),
file.path("tests", "even.txt"),
file.path("tests", "fibo.txt")),
c("primes", "even", "fibo"))
print(sets)
$primes
[1] "1" "2" "3" "5" "7" "11" "13" "17"
$even
[1] "0" "2" "4" "6" "8" "10" "12" "14" "16" "18"
$fibo
[1] "1" "2" "3" "5" "8" "13"
Compute intersections and specific elements#
Now you can compute specific elements of Venn diagram intersections.
venn.compute_specific(sets)
- $primes_even_fibo
- '2'
- $primes_even
- $primes_fibo
- '1'
- '3'
- '5'
- '13'
- $even_fibo
- '8'
- $primes
- '7'
- '11'
- '17'
- $even
- '0'
- '4'
- '6'
- '10'
- '12'
- '14'
- '16'
- '18'
- $fibo
If you need to write sets in files, add an output path. Files are written using convention of join sets name with underscore.
venn.compute_specific(sets, output_dir = file.path("tests", "output"))
We can verify written files.
dir(file.path("tests", "output"))
- 'even_fibo.txt'
- 'even.txt'
- 'fibo.txt'
- 'primes_even_fibo.txt'
- 'primes_even.txt'
- 'primes_fibo.txt'
- 'primes.txt'
Plot Venn diagram#
Finally, if you want to save plot, invoke this function with the same arguments
as before (internally using
VennDiagram
)
venn.compute_plot(sets, output_dir = file.path("tests", "output"))
Now, we have a primes_even_fibo.png
file.