# HG changeset patch # User stevecassidy # Date 1471319300 14400 # Node ID 6d6dc275b10722e73123defc2a0d238660eae6c4 planemo upload commit 0fca33c3b7285bd31f6c7380393d08bbdad4e4d6 diff -r 000000000000 -r 6d6dc275b107 get_fm_at_midpoint.R --- /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) diff -r 000000000000 -r 6d6dc275b107 get_fm_at_midpoint.xml --- /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 @@ + + using wrassp formant tracker + + + R + r-wrassp + + + + 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]))}" + + + + + + + + + + + + + + + + + + + + + Calculate the formant tracks for segments of some audio files + and extract the value at the midpoint. Tabulate these values in the result. + + + + @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}, + } + + + diff -r 000000000000 -r 6d6dc275b107 r_wrapper.sh --- /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