Browse code

script.R - v3 - Structure updated and save plot and table func added

Fred authored on24/05/2015 23:12:44
Showing1 changed files
... ...
@@ -1,81 +1,96 @@
1
-#!/usr/bin/R
1
+#!/usr/bin/env Rscript
2 2
 # Title:
3 3
 # Version: 
4
-# Author: Frédéric CHEVALIER
5
-# Created in:
4
+# Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5
+# Created in: 2014-0
6 6
 # Modified in:
7 7
 
8 8
 
9 9
 
10
-#------#
11
-# Aims #
12
-#------#
10
+#==========#
11
+# Comments #
12
+#==========#
13 13
 
14 14
 
15 15
 
16 16
 
17 17
 
18
-#-----------------#
19
-# Library loading #
20
-#-----------------#
18
+#===================#
19
+# Packages required #
20
+#===================#
21 21
 
22
+# library()
22 23
 
23 24
 
24 25
 
25
-#-----------#
26
-# Variables #
27
-#-----------#
26
+#===========#
27
+# Functions #
28
+#===========#
28 29
 
29
-# Remove all variables from the memory
30
-rm(list = ls())
30
+#------------------------#
31
+# Function to save plots #
32
+#------------------------#
31 33
 
32
-# Data file
33
-file <- ""
34
+save.myplot <- function (filename, width=8, height=8) {
35
+	# Folder creation for graphic output (if does not exist)
36
+	if (file.exists("Graphs/") == FALSE) {dir.create("Graphs")}
37
+
38
+	# Graphic saving (png and eps formats)
39
+	dev.copy(png,paste("Graphs/",filename,".png",sep=""), width=width*72, height=height*72, bg="white")
40
+	dev.off()
41
+	dev.copy2pdf(file=paste("Graphs/",filename,".pdf",sep=""), width=width, height=height)
42
+}
34 43
 
35
-data <- read.csv(file, header=T, sep=";")
36 44
 
37
-# Object containing the name of the data file
38
-name <- strsplit(file,".csv")
45
+#-------------------------#
46
+# Function to save tables #
47
+#-------------------------#
39 48
 
49
+save.mytable <- function (x, filename, ext=".tsv", sep="\t", col.names=FALSE, row.names=FALSE, append=FALSE){
50
+	# Folder creation for table output (if does not exist)
51
+	if (file.exists("Results/") == FALSE) {dir.create("Results")}
52
+	
53
+	# Data export
54
+	write.table(x, file=paste("Results/",filename, ext, sep=""), col.names=col.names, row.names=row.names, append=append, sep=sep)
55
+}
40 56
 
41 57
 
42
-#-----------------#
43
-# Data Processing #
44
-#-----------------#
45 58
 
59
+#===========#
60
+# Variables #
61
+#===========#
62
+
63
+# Data file
64
+myfile <- ""
65
+mydata <- read.csv(myfile, header=TRUE, sep=";")
46 66
 
67
+# Object contaning the input file name
68
+filename <- strsplit(myfile,".csv")
47 69
 
48
-# Result export in folder
49
-if (file.exists("Results/") == FALSE) {dir.create("Results")}
50
-write.table(x, file=paste("Résultats/x",file, sep=""), col.names = NA, row.names = TRUE, sep=";") # x = object to save
51 70
 
52 71
 
72
+#=================#
73
+# Data processing #
74
+#=================#
53 75
 
54
-#--------------------#
55
-# Graphical commands #
56
-#--------------------#
57 76
 
58 77
 
59 78
 
60 79
 
61
-#------#
62
-# Plot #
63
-#------#
80
+#========#
81
+# Curves #
82
+#========#
64 83
 
65 84
 
66 85
 
67 86
 
87
+#=========#
88
+# Figures #
89
+#=========#
68 90
 
69
-# Create the graph folder if it do not already exist
70
-if (file.exists("Graphs/") == FALSE) {dir.create("Graphs")}
71 91
 
72
-postscript(file=paste("Graphs/", name, ".ps", sep="")
73 92
 
74
-# Draw graph here
75 93
 
76
-dev.off()
77 94
 
78 95
 
79
-## Save the graph in png format
80
-#savePlot(paste("Graphs/",name,".png", sep=""))
81 96
 
Browse code

script.R - v2.1 - Strucutre and plot saving updated

Fred authored on24/05/2015 23:07:04
Showing1 changed files
... ...
@@ -1,23 +1,23 @@
1 1
 #!/usr/bin/R
2
-# title :
3
-# version : 
4
-# author : Fédéric CHEVALIER
5
-# created in:
6
-# modified in:
2
+# Title:
3
+# Version: 
4
+# Author: Frédéric CHEVALIER
5
+# Created in:
6
+# Modified in:
7 7
 
8 8
 
9 9
 
10
-#----------#
11
-# Comments #
12
-#----------#
10
+#------#
11
+# Aims #
12
+#------#
13 13
 
14 14
 
15 15
 
16 16
 
17 17
 
18
-#-------------------#
19
-# Packages required #
20
-#-------------------#
18
+#-----------------#
19
+# Library loading #
20
+#-----------------#
21 21
 
22 22
 
23 23
 
... ...
@@ -26,7 +26,7 @@
26 26
 # Variables #
27 27
 #-----------#
28 28
 
29
-# Removing of all existing variables from the memory
29
+# Remove all variables from the memory
30 30
 rm(list = ls())
31 31
 
32 32
 # Data file
... ...
@@ -34,41 +34,48 @@ file <- ""
34 34
 
35 35
 data <- read.csv(file, header=T, sep=";")
36 36
 
37
-# Object contaning the input file name
37
+# Object containing the name of the data file
38 38
 name <- strsplit(file,".csv")
39 39
 
40 40
 
41 41
 
42 42
 #-----------------#
43
-# Data processing #
43
+# Data Processing #
44 44
 #-----------------#
45 45
 
46 46
 
47 47
 
48 48
 # Result export in folder
49 49
 if (file.exists("Results/") == FALSE) {dir.create("Results")}
50
-write.table(x, file=paste("Rsults/x",file, sep=""), col.names = NA, row.names = TRUE, sep=";") # x = object to sauve
50
+write.table(x, file=paste("Résultats/x",file, sep=""), col.names = NA, row.names = TRUE, sep=";") # x = object to save
51 51
 
52 52
 
53 53
 
54
-#--------#
55
-# Curves #
56
-#--------#
54
+#--------------------#
55
+# Graphical commands #
56
+#--------------------#
57 57
 
58 58
 
59 59
 
60 60
 
61
-#---------#
62
-# Figures #
63
-#---------#
61
+#------#
62
+# Plot #
63
+#------#
64 64
 
65 65
 
66 66
 
67 67
 
68 68
 
69
-# Folder creation for graphic output (if does not exist)
69
+# Create the graph folder if it do not already exist
70 70
 if (file.exists("Graphs/") == FALSE) {dir.create("Graphs")}
71 71
 
72
-# Graphic saving (png format)
73
-savePlot(paste("Graphs/",name,".png", sep=""))
72
+postscript(file=paste("Graphs/", name, ".ps", sep="")
73
+
74
+# Draw graph here
75
+
76
+dev.off()
77
+
78
+
79
+## Save the graph in png format
80
+#savePlot(paste("Graphs/",name,".png", sep=""))
74 81
 
Browse code

script.R - v2 - Switch to English version

Fred authored on24/05/2015 23:03:28
Showing1 changed files
... ...
@@ -1,22 +1,22 @@
1 1
 #!/usr/bin/R
2
-#titre :
3
-#version : 
4
-#auteur : Fédéric CHEVALIER
5
-#date de création :
6
-#date de modification :
2
+# title :
3
+# version : 
4
+# author : Fédéric CHEVALIER
5
+# created in:
6
+# modified in:
7 7
 
8 8
 
9 9
 
10
-#--------------#
11
-# Commentaires #
12
-#--------------#
10
+#----------#
11
+# Comments #
12
+#----------#
13 13
 
14 14
 
15 15
 
16 16
 
17 17
 
18 18
 #-------------------#
19
-# Paquets à charger #
19
+# Packages required #
20 20
 #-------------------#
21 21
 
22 22
 
... ...
@@ -26,34 +26,34 @@
26 26
 # Variables #
27 27
 #-----------#
28 28
 
29
-# Effacer de la mémoire toutes les variables présentes
29
+# Removing of all existing variables from the memory
30 30
 rm(list = ls())
31 31
 
32
-# Fichier contenant les données
32
+# Data file
33 33
 file <- ""
34 34
 
35 35
 data <- read.csv(file, header=T, sep=";")
36 36
 
37
-# Objet contenant le nom du fichier traité
37
+# Object contaning the input file name
38 38
 name <- strsplit(file,".csv")
39 39
 
40 40
 
41 41
 
42
-#-------------------------#
43
-# Traitements des données #
44
-#-------------------------#
42
+#-----------------#
43
+# Data processing #
44
+#-----------------#
45 45
 
46 46
 
47 47
 
48
-# Export des résultats dans un dossier
49
-if (file.exists("Résultats/") == FALSE) {dir.create("Résultats")}
50
-write.table(x, file=paste("Résultats/x",file, sep=""), col.names = NA, row.names = TRUE, sep=";") # x = objet à sauver
48
+# Result export in folder
49
+if (file.exists("Results/") == FALSE) {dir.create("Results")}
50
+write.table(x, file=paste("Rsults/x",file, sep=""), col.names = NA, row.names = TRUE, sep=";") # x = object to sauve
51 51
 
52 52
 
53 53
 
54
-#---------#
55
-# Courbes #
56
-#---------#
54
+#--------#
55
+# Curves #
56
+#--------#
57 57
 
58 58
 
59 59
 
... ...
@@ -66,9 +66,9 @@ write.table(x, file=paste("Résultats/x",file, sep=""), col.names = NA, row.name
66 66
 
67 67
 
68 68
 
69
-# Création du dossier des sorties graphiques s'il n'existe pas encore
70
-if (file.exists("Graphes/") == FALSE) {dir.create("Graphes")}
69
+# Folder creation for graphic output (if does not exist)
70
+if (file.exists("Graphs/") == FALSE) {dir.create("Graphs")}
71 71
 
72
-# Enregistrement du graphique au format png
73
-savePlot(paste("Graphes/",name,".png", sep=""))
72
+# Graphic saving (png format)
73
+savePlot(paste("Graphs/",name,".png", sep=""))
74 74
 
Browse code

scriptR - v1.1 - Structure improvement

Fred authored on24/05/2015 22:59:34
Showing1 changed files
... ...
@@ -7,24 +7,24 @@
7 7
 
8 8
 
9 9
 
10
-#--------------
11
-# Commentaires
12
-#--------------
10
+#--------------#
11
+# Commentaires #
12
+#--------------#
13 13
 
14 14
 
15 15
 
16 16
 
17 17
 
18
-#-------------------
19
-# Paquets à charger
20
-#-------------------
18
+#-------------------#
19
+# Paquets à charger #
20
+#-------------------#
21 21
 
22 22
 
23 23
 
24 24
 
25
-#-----------
26
-# Variables
27
-#-----------
25
+#-----------#
26
+# Variables #
27
+#-----------#
28 28
 
29 29
 # Effacer de la mémoire toutes les variables présentes
30 30
 rm(list = ls())
... ...
@@ -39,9 +39,9 @@ name <- strsplit(file,".csv")
39 39
 
40 40
 
41 41
 
42
-#-------------------------
43
-# Traitements des données
44
-#-------------------------
42
+#-------------------------#
43
+# Traitements des données #
44
+#-------------------------#
45 45
 
46 46
 
47 47
 
... ...
@@ -51,16 +51,16 @@ write.table(x, file=paste("Résultats/x",file, sep=""), col.names = NA, row.name
51 51
 
52 52
 
53 53
 
54
-#---------
55
-# Courbes
56
-#---------
54
+#---------#
55
+# Courbes #
56
+#---------#
57 57
 
58 58
 
59 59
 
60 60
 
61
-#---------
62
-# Figures
63
-#---------
61
+#---------#
62
+# Figures #
63
+#---------#
64 64
 
65 65
 
66 66
 
Browse code

script.R - v1

Fred authored on24/05/2015 22:48:29
Showing1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,74 @@
1
+#!/usr/bin/R
2
+#titre :
3
+#version : 
4
+#auteur : Fédéric CHEVALIER
5
+#date de création :
6
+#date de modification :
7
+
8
+
9
+
10
+#--------------
11
+# Commentaires
12
+#--------------
13
+
14
+
15
+
16
+
17
+
18
+#-------------------
19
+# Paquets à charger
20
+#-------------------
21
+
22
+
23
+
24
+
25
+#-----------
26
+# Variables
27
+#-----------
28
+
29
+# Effacer de la mémoire toutes les variables présentes
30
+rm(list = ls())
31
+
32
+# Fichier contenant les données
33
+file <- ""
34
+
35
+data <- read.csv(file, header=T, sep=";")
36
+
37
+# Objet contenant le nom du fichier traité
38
+name <- strsplit(file,".csv")
39
+
40
+
41
+
42
+#-------------------------
43
+# Traitements des données
44
+#-------------------------
45
+
46
+
47
+
48
+# Export des résultats dans un dossier
49
+if (file.exists("Résultats/") == FALSE) {dir.create("Résultats")}
50
+write.table(x, file=paste("Résultats/x",file, sep=""), col.names = NA, row.names = TRUE, sep=";") # x = objet à sauver
51
+
52
+
53
+
54
+#---------
55
+# Courbes
56
+#---------
57
+
58
+
59
+
60
+
61
+#---------
62
+# Figures
63
+#---------
64
+
65
+
66
+
67
+
68
+
69
+# Création du dossier des sorties graphiques s'il n'existe pas encore
70
+if (file.exists("Graphes/") == FALSE) {dir.create("Graphes")}
71
+
72
+# Enregistrement du graphique au format png
73
+savePlot(paste("Graphes/",name,".png", sep=""))
74
+