annotate PhyloIndex.R @ 1:1d73a4af71f5 draft default tip

planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit ce74877d21915627f36eae4d2eb3851a6a858aae
author ecology
date Thu, 22 May 2025 16:43:58 +0000
parents 71a46f890035
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
1 #!/bin/Rscript
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
2 # Indice de phylodiversite
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
3
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
4
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
5 # args
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
6 args = commandArgs(trailingOnly=TRUE)
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
7 #args = c("comm_matrix", "comm_tree.txt")
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
8
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
9 # library
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
10 library(Matrix)
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
11 library(ape)
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
12 library(phyloregion)
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
13 library(SparseArray)
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
14
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
15 # functions
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
16 write_results <- function(){
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
17 write.table(ses_PD, output_file, sep = "\t", row.names=FALSE)
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
18 }
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
19
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
20 # verif args
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
21 if (length(args)<5){stop('Usage : input_tree_file input_matrix_file random_seed clustering_model output_file')
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
22 }else{
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
23 # read enter file
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
24 comm_tree <- read.tree(args[1])
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
25
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
26 comm_matrix <- readSparseCSV(args[2] , sep="\t")
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
27 comm_matrix <- as(comm_matrix,"dgCMatrix")
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
28
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
29 seed <- args[3]
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
30
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
31 model <- args[4]
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
32
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
33 output_file <- args[5]
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
34
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
35 # rdm + compute
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
36 set.seed(seed)
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
37 ses_PD <- PD_ses(comm_matrix, comm_tree, model = model, reps = 999)
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
38
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
39 # write res
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
40 write_results()
71a46f890035 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
ecology
parents:
diff changeset
41 }