| ... | ... |
@@ -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 |
|