Mercurial > repos > ecology > stoc_filteringsp
comparison ExeFilteringRareLowabundSPGalaxy.r @ 0:2e45ae3b297a draft
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
author | ecology |
---|---|
date | Thu, 02 Apr 2020 03:34:37 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2e45ae3b297a |
---|---|
1 #!/usr/bin/env Rscript | |
2 | |
3 ##################################################################################################################### | |
4 ############## FILTERING RARE AND LOW-ABUNDANCE SPECIES function:filtreEspeceRare ############################## | |
5 ##################################################################################################################### | |
6 | |
7 #### Based on Romain Lorrillière R script | |
8 #### Modified by Alan Amosse and Benjamin Yguel for integrating within Galaxy-E | |
9 | |
10 | |
11 suppressMessages(library(reshape2)) | |
12 | |
13 | |
14 ########### | |
15 #delcaration des arguments et variables/ declaring some variables and load arguments | |
16 | |
17 args = commandArgs(trailingOnly=TRUE) | |
18 | |
19 if (length(args)==0) { | |
20 stop("At least one argument must be supplied, dataset transformed by make table function (.tabular).", call.=FALSE) #si pas d'arguments -> affiche erreur et quitte / if no args -> error and exit1 | |
21 } else { | |
22 Datatransformedforfiltering_trendanalysis<-args[1] ###### Nom du fichier peut provenir de la fonction "MakeTableAnalyse" / file name , may result from the function "MakeTableAnalys" | |
23 source(args[2])### chargement des fonctions / load the functions | |
24 } | |
25 | |
26 ##### Le tableau de données doit posséder 3 variables en colonne minimum avec 1 seule espèce et autant de colonne en plus que d'espèces en plus: les carrés ou sont réalisés les observatiosn ("carre"), la ou les années des observations ("annee"), 1 colonne par espèce renseignée avec les abondances correspondantes | |
27 ##### Data must be a dataframe with 3 variables in column: plots where observation where made ("carre"), year(s) of the different sampling ("annee"), and one column per species with its abundance | |
28 | |
29 | |
30 #Import des données / Import data | |
31 tab <- read.table(Datatransformedforfiltering_trendanalysis,sep="\t",dec=".",header=TRUE) # | |
32 | |
33 err_msg_tab="\nThe input dataset doesn't have the right format. It need to have the following 2 variables : \"carre\" and \"annee\" followed by at least one species" | |
34 if(ncol(tab)<3 || !("carre" %in% names(tab)) || !("annee" %in% names(tab))){ | |
35 stop(err_msg_tab,call.=FALSE) | |
36 } | |
37 | |
38 | |
39 | |
40 | |
41 #Do your analysis | |
42 tab_filtred1<-filter_absent_species(tab) | |
43 tab_filtred2<-filter_rare_species(tab) | |
44 | |
45 #save the data in a output file in a tabular format | |
46 filename <- "Datafilteredfortrendanalysis.tabular" | |
47 write.table(tab_filtred2, filename,row.names=FALSE,sep="\t",dec=".") | |
48 cat(paste("\nWrite table with data filtered for trend analysis. \n--> \"",filename,"\"\n")) | |
49 | |
50 |