This may not be the 'best' way, but it I've found it to be a workable solution. I'm running a Perl script that takes the tool-xml parameters, does some processing, and calls R to obtain a p-val calculation. The results are parsed and included in a formatted HTML page. It's all code based.
You can likely use something similar in a Python script:
# --- create the R command my $cmd=<<END; echo 'phyper($match, $listcount, $all, $qrycount, lower.tail = FALSE, log.p = FALSE)' > rcmd END system($cmd);
# --- run R in command line mode my $runR=<<END; R --slave -f rcmd > rpval END system($runR);
# --- open and parse results open my $fh, "<", "rpval"; my $line = <$fh>; close $fh; $line =~ / (.+)/;
hope you find this of use. -ray