changeset 0:6d6dc275b107 draft

planemo upload commit 0fca33c3b7285bd31f6c7380393d08bbdad4e4d6
author stevecassidy
date Mon, 15 Aug 2016 23:48:20 -0400
parents
children dbcf9bc275e3
files get_fm_at_midpoint.R get_fm_at_midpoint.xml r_wrapper.sh
diffstat 3 files changed, 128 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/get_fm_at_midpoint.R	Mon Aug 15 23:48:20 2016 -0400
@@ -0,0 +1,60 @@
+
+library(wrassp)
+
+get_fm_at_midpoint <- function(segments, wavmap) {
+    midpoint_fm <- function(row) {
+        start = as.numeric(row[1])
+        end = as.numeric(row[2])
+        identifier = row[5]
+        fn = wavmap[identifier]
+        if (is.na(fn)) {
+            cat("Can't find wav file for ", identifier, "\n")
+            return(c(0,0,0,0))
+        } else {
+            res = forest(fn, beginTime=start, endTime=end, toFile=FALSE)
+            return(res$fm[nrow(res$fm)/2,])
+        }
+    }
+
+    print(wavmap)
+
+    fm = t(apply(segments, 1, midpoint_fm))
+    fm = data.frame(fm=fm, labels=segments$label, identifier=segments$identifier)
+
+    return(fm)
+}
+
+args = commandArgs(TRUE)
+# args will be like
+# qresult.dat outfile.dat --wavfile a,b,c --identifier A,B,C
+# need to split out wavfile and identifier args on ,
+
+if (length(args) != 6) {
+    print("Wrong number of arguments!")
+    exit(1)
+}
+
+segmentfile = args[1]
+wavfiles = args[4]
+identifiers = args[6]
+outfile = args[2]
+
+# split on comma
+wavfiles = strsplit(wavfiles, ",")[[1]]
+identifiers = strsplit(identifiers, ",")[[1]]
+
+if( length(wavfiles) != length(identifiers)) {
+    print("Lengths of wavfiles and identifiers don't match.")
+    exit(1)
+}
+cat("\nWAVMAP\n")
+wavmap = NULL
+for(i in 1:length(wavfiles)) {
+    wavmap[identifiers[i]] = wavfiles[i]
+}
+
+segments = read.table(segmentfile, header=TRUE)
+
+result = get_fm_at_midpoint(segments, wavmap)
+
+write.table(result, file=outfile, sep="\t", quote=F, row.names=F)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/get_fm_at_midpoint.xml	Mon Aug 15 23:48:20 2016 -0400
@@ -0,0 +1,45 @@
+<tool id="get_fm_at_midpoint" name="Get Formants at segment midpoint" version="0.01" force_history_refresh="True">
+    <description>using wrassp formant tracker</description>
+
+    <requirements>
+        <requirement type="package" version="3.2.1">R</requirement>
+        <requirement type="package" version="0.1.4">r-wrassp</requirement>
+    </requirements>
+
+    <command interpreter="bash">
+        r_wrapper.sh $__tool_directory__/get_fm_at_midpoint.R --args ${segments} ${output} --wavfile "${",".join(map(str, $wavfile))}" --identifier "${",".join(map(str, [w.element_identifier for w in $wavfile]))}"
+    </command>
+
+    <inputs>
+        <param name="segments" type="data" format="tabular" label="Segment List" help=""/>
+        <param name="wavfile" type="data" multiple="true" format="wav" label="Audio File(s)" help="Audio file(s) in WAV format"/>
+    </inputs>
+
+    <outputs>
+        <data format_source="segments" name="output" label="Formants" />
+    </outputs>
+
+
+    <tests>
+        <test>
+            <param name="segments" value="qresult.dat"/>
+            <param name="wavfile" value="wavs/1_1308_1_2_034-ch6-speaker16.wav#wav"/>
+            <output name="output" file="formants_mid.dat"/>
+        </test>
+    </tests>
+
+    <help>Calculate the formant tracks for segments of some audio files
+    and extract the value at the midpoint. Tabulate these values in the result.</help>
+
+    <citations>
+        <citation type='bibtex'>
+            @Manual{,
+              title = {wrassp: an R wrapper to the ASSP Library},
+              author = {Lasse Bombien and Raphael Winkelmann and Michel
+                Scheffers},
+              year = {2016},
+              note = {R package version 0.1.4},
+            }
+        </citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/r_wrapper.sh	Mon Aug 15 23:48:20 2016 -0400
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+### Run R providing the R script in $1 as standard input and passing 
+### the remaining arguments on the command line
+
+# Function that writes a message to stderr and exits
+fail()
+{
+    echo "$@" >&2
+    exit 1
+}
+
+# Ensure R executable is found
+which R > /dev/null || fail "'R' is required by this tool but was not found on path" 
+
+# Extract first argument
+infile=$1; shift
+
+# Ensure the file exists
+test -f $infile || fail "R input file '$infile' does not exist"
+
+# Invoke R passing file named by first argument to stdin
+R --vanilla --slave $* < $infile