Mercurial > repos > ecology > phylogenetic_occupancy_matcher
comparison PhylOccuMatcher.R @ 0:e260f1a598da draft default tip
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
| author | ecology |
|---|---|
| date | Tue, 20 May 2025 09:53:38 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:e260f1a598da |
|---|---|
| 1 #!/bin/Rscript | |
| 2 # Matice Phylo/Commu | |
| 3 | |
| 4 args = commandArgs(trailingOnly=TRUE) | |
| 5 #args = c( "pycnogonida_tree_2024", "pycnogonida_occ_2024.csv") | |
| 6 | |
| 7 library(phyloregion) | |
| 8 library(ape) | |
| 9 library(Matrix) | |
| 10 library(SparseArray) | |
| 11 | |
| 12 #install.packages("remotes") | |
| 13 #remotes::install_github("Bioconductor/SparseArray") | |
| 14 | |
| 15 save_as_tabular_fun <- function(){ | |
| 16 #writeMM(obj = comm_matrix, file = "output.mtx") | |
| 17 writeSparseCSV(comm_matrix, out_grid, sep="\t", transpose=FALSE, write.zeros=FALSE) | |
| 18 } | |
| 19 | |
| 20 | |
| 21 save_as_tree_fun <- function(){ | |
| 22 write.tree(comm_tree, file = out_tree) | |
| 23 } | |
| 24 | |
| 25 | |
| 26 if (length(args)<4){stop('Usage : input_tree_file input_grid_file output_tree_file output_grid_file') | |
| 27 }else{ | |
| 28 tree <- read.tree(args[1]) | |
| 29 grid <- read.csv2(args[2], dec = ".", sep = "\t", header = T, na.strings = "") | |
| 30 out_tree <- args[3] | |
| 31 out_grid <- args[4] | |
| 32 | |
| 33 sparse_grid <- long2sparse(grid, grid = "grids", species = "newscientificname") | |
| 34 | |
| 35 com.data <- match_phylo_comm(tree, sparse_grid, delete_empty_rows = F) | |
| 36 | |
| 37 comm_matrix <- com.data$comm | |
| 38 #test | |
| 39 #sum_matrix <- summary(comm_matrix) | |
| 40 | |
| 41 comm_tree <- com.data$phy | |
| 42 | |
| 43 save_as_tabular_fun() | |
| 44 save_as_tree_fun() | |
| 45 } | |
| 46 | |
| 47 #comm_matrix_recup <- readSparseCSV("output") | |
| 48 #comm_matrix_recup <- as(comm_matrix_recup,"dgCMatrix") |
