Mercurial > repos > ecology > stoc_filteringsp
annotate ExeFilteringRareLowabundSPGalaxy.r @ 1:fd0687e91bf6 draft default tip
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit d49a4da1ffac1f33a15fdb7ae98827d0034a7879"
author | ecology |
---|---|
date | Mon, 11 May 2020 17:44:48 -0400 |
parents | 2e45ae3b297a |
children |
rev | line source |
---|---|
0
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
1 #!/usr/bin/env Rscript |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
2 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
3 ##################################################################################################################### |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
4 ############## FILTERING RARE AND LOW-ABUNDANCE SPECIES function:filtreEspeceRare ############################## |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
5 ##################################################################################################################### |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
6 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
7 #### Based on Romain Lorrillière R script |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
8 #### Modified by Alan Amosse and Benjamin Yguel for integrating within Galaxy-E |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
9 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
10 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
11 suppressMessages(library(reshape2)) |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
12 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
13 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
14 ########### |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
15 #delcaration des arguments et variables/ declaring some variables and load arguments |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
16 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
17 args = commandArgs(trailingOnly=TRUE) |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
18 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
19 if (length(args)==0) { |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
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 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
21 } else { |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
22 Datatransformedforfiltering_trendanalysis<-args[1] ###### Nom du fichier peut provenir de la fonction "MakeTableAnalyse" / file name , may result from the function "MakeTableAnalys" |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
23 source(args[2])### chargement des fonctions / load the functions |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
24 } |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
25 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
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 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
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 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
28 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
29 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
30 #Import des données / Import data |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
31 tab <- read.table(Datatransformedforfiltering_trendanalysis,sep="\t",dec=".",header=TRUE) # |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
32 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
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" |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
34 if(ncol(tab)<3 || !("carre" %in% names(tab)) || !("annee" %in% names(tab))){ |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
35 stop(err_msg_tab,call.=FALSE) |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
36 } |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
37 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
38 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
39 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
40 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
41 #Do your analysis |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
42 tab_filtred1<-filter_absent_species(tab) |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
43 tab_filtred2<-filter_rare_species(tab) |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
44 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
45 #save the data in a output file in a tabular format |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
46 filename <- "Datafilteredfortrendanalysis.tabular" |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
47 write.table(tab_filtred2, filename,row.names=FALSE,sep="\t",dec=".") |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
48 cat(paste("\nWrite table with data filtered for trend analysis. \n--> \"",filename,"\"\n")) |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
49 |
2e45ae3b297a
"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff
changeset
|
50 |