changeset 0:10212598b005 draft

Uploaded
author mnhn65mo
date Tue, 07 Aug 2018 06:02:29 -0400
parents
children 5184899fd06e
files rdata_extractor.R rdata_extractor.xml rdata_reader.R rdata_reader.xml
diffstat 4 files changed, 177 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rdata_extractor.R	Tue Aug 07 06:02:29 2018 -0400
@@ -0,0 +1,79 @@
+#!/usr/bin/env Rscript
+#Use a Rdata file and attributes to extract
+#Get every argument and write a file with its values(s)
+
+
+#get the rdata file
+args = commandArgs(trailingOnly=TRUE)
+rdata<-load(args[1])
+rdata<-get(rdata)
+sum<-summary(rdata) 
+
+#get the selected attributes to explore
+attributes_selected <- commandArgs(trailingOnly=TRUE)[2]
+attributes<-strsplit(attributes_selected, ",") #List of elements
+
+write.table(sum,file = "summary.tabular",sep='\t',row.names=FALSE)
+len<-length(attributes[[1]])-1
+bind<-tail(args,n=1)
+
+#file type definition
+file_ext<-function(ext){
+	file<-paste(attributes[[1]][i],ext,sep="") #Filename definition
+        file<-paste("outputs/",file,sep="")
+	return(file)
+}
+
+for (i in 1:len){
+	attribute<-attributes[[1]][i] #Get the attribute i 
+	if(! any(names(rdata)==attribute)){
+		error<-paste(attribute, " doesn't exist in the RData. Check the inputs files")
+		write(error, stderr())
+	}
+
+	attribute_val<-eval(parse(text=paste("rdata$",attribute,sep=""))) #Extract the value(s)
+
+	if(is.null(attribute_val)){ #Galaxy can't produce output if NULL
+		file<-file_ext(".txt")
+		write("Return NULL value",file=file)
+		next #Exit loop
+	}
+
+	if (typeof(attribute_val)=="list"){ #Need to be corrected, fail in galaxy but not in R
+		if(length(attribute_val)=="0"){
+			file<-file_ext(".txt")
+			sink(file=file)
+			print("Empty list :") #If the list is empty without element, file is empty and an error occur in galaxy
+			print(attribute_val)
+			sink()
+			next
+		}else{
+			attribute_val<-as.data.frame(do.call(rbind, attribute_val))
+			file<-file_ext(".tabular")
+			write.table(attribute_val,file=file,row.names=FALSE)
+			next
+		}
+	}else if (typeof(attribute_val)=="language"){ #OK
+		attribute_val<-toString(attribute_val,width = NULL)
+		file<-file_ext(".txt")
+		write(attribute_val,file=file)
+		next
+	}
+        file<-file_ext(".tabular")
+        dataframe<-as.data.frame(attribute_val)
+        names(dataframe)<-attribute
+        if(bind=="nobind"){
+            write.table(dataframe,file=file,row.names=FALSE,sep="    ")
+        }else{
+            if(!exists("alldataframe")){
+                alldataframe<-dataframe
+            }else{
+    	        alldataframe<-cbind(alldataframe, dataframe)
+            }
+        }
+}
+
+if(exists("alldataframe")&&bind=="bind"){
+    write.table(alldataframe,file=file,row.names=FALSE,sep="	")
+}
+q('no')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rdata_extractor.xml	Tue Aug 07 06:02:29 2018 -0400
@@ -0,0 +1,57 @@
+<tool id="Rdata_exctract" name="Rdata parser" version="0.1">
+    <requirements>
+        <requirement type="package" version="1.20.0">r-getopt</requirement>
+        <requirement type="package" version="7.0">readline</requirement>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+        mkdir outputs &&
+	Rscript '$__tool_directory__/rdata_extractor.R' '$rdata' $selectedattributes '$summary' '$other' '$bind_dataframe'
+]]>
+    </command>
+    <inputs>
+        <param name="rdata" type="data" label="Rdata file to explore" format="rdata"/>
+        <param name="rdata_attributes" type="data" label="File with .Rdata content details" format="tabular"/>
+
+        <param name="selectedattributes" label="Select which attribute(s) you want to extract" type="select" display="checkboxes" multiple="true">
+            <options from_dataset="rdata_attributes">
+                <column name="value" index="0"/>
+            </options>
+        </param>
+        <param name="bind_dataframe" label="Bind variables in a single tabular when its possible" type="boolean" truevalue="bind" falsevalue="nobind" checked="true"/>
+    </inputs>
+    <outputs>
+        <data name="summary" from_work_dir="summary.tabular" format="tabular" label="Summary"/>
+        <data name="other">
+            <discover_datasets pattern="__designation_and_ext__" visible="true" directory="outputs"/>
+        </data>
+    </outputs>
+    <help><![CDATA[
+
+.. class:: infomark 
+
+==========================
+Rdata parser
+==========================
+**What it does**        
+
+
+The Rdata parser tool allows to extract informations from a binary R file in .RData format. 
+
+
+It produces a summary file and extract the selected dimensions. 
+	   
+More informations concerning R Data format and save / load functions can be found here:  http://www.sthda.com/english/wiki/saving-data-into-r-data-format-rds-and-rdata&gt.
+
+More informations concerning R Data format and save / load functions can be found here:  http://www.sthda.com/english/wiki/saving-data-into-r-data-format-rds-and-rdata&gt.
+
+
+|
+
+**How to use it**
+
+First use the Rdata reader tool to get the list of dimensions available in the binary file.
+
+Use the reader tool output to select the dimension(s) you want to extract.
+
+    ]]></help>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rdata_reader.R	Tue Aug 07 06:02:29 2018 -0400
@@ -0,0 +1,8 @@
+#!/usr/bin/env Rscript
+#Return list of attributes from a Rdata file
+
+args = commandArgs(trailingOnly=TRUE)
+rda<-load(args[1]) #Load the rdata
+rdata<-get(rda)
+names<-names(rdata) #Get the attributes
+write(names, file = "rdata_list_attr")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rdata_reader.xml	Tue Aug 07 06:02:29 2018 -0400
@@ -0,0 +1,33 @@
+<tool id="Rdata_reader" name="Rdata binary file reader" version="0.1">
+    <requirements>
+        <requirement type="package" version="1.20.0">r-getopt</requirement>
+        <requirement type="package" version="7.0">readline</requirement>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+        Rscript '$__tool_directory__/rdata_reader.R' '$input1' '$rdata_list_attr' ]]>
+    </command>
+    <inputs>
+        <param format="rdata" name="input1" type="data" label="Rdata binary file to explore"/>
+    </inputs>
+    <outputs>
+        <data format="tabular" name="rdata_list_attr" from_work_dir="rdata_list_attr" />
+    </outputs>
+    <help>
+==========================
+Rdata reader
+==========================
+**What it does**
+
+The Rdata reader tool give information on the content of a binary R file.
+
+It produces a list of the available dimensions in the Rdata (tabular output file).
+
+Use this tool before considering use "Rdata parser".
+
+|
+
+**How to use it**
+
+Select a file in the Rdata format and execute the tool.
+    </help>
+</tool>