Bug fixed in linear regression tool, and new option added to grouping tool.

This commit is contained in:
Guruprasad Anada
2009-04-21 10:53:34 -04:00
parent 8c2ec32e88
commit 54667b80e6
4 changed files with 52 additions and 22 deletions
+9 -4
View File
@@ -108,10 +108,15 @@ print >>fout, "Sigma\t%s" %(summary.get('sigma','NA'))
r.pdf( outfile2, 8, 8 )
if len(x_vals) == 1: #Simple linear regression case with 1 predictor variable
sub_title = "Slope = %s; Y-int = %s" %(slope,yintercept)
r.plot(x=x_vals[0], y=y_vals, xlab="X", ylab="Y", sub=sub_title, main="Scatterplot with regression")
r.abline(a=yintercept, b=slope, col="red")
try:
r.plot(x=x_vals[0], y=y_vals, xlab="X", ylab="Y", sub=sub_title, main="Scatterplot with regression")
r.abline(a=yintercept, b=slope, col="red")
except:
pass
else:
r.pairs(dat, main="Scatterplot Matrix", col="blue")
r.plot(linear_model)
try:
r.plot(linear_model)
except:
pass
r.dev_off()
+2 -2
View File
@@ -1,4 +1,4 @@
<tool id="LinearRegression1" name="Perform Linear Regression">
<tool id="LinearRegression1" name="Perform Linear Regression" version="1.0.1">
<description> </description>
<command interpreter="python">
linear_regression.py
@@ -48,7 +48,7 @@ This tool uses the 'lm' function from R statistical package to perform linear re
**Note**
- This tool currently treats all predictor and response variables as continuous variables.
- This tool currently treats all predictor and response variables as continuous variables. Running the tool on categorical variables might result in incorrect results.
- Rows containing non-numeric (or missing) data in any of the chosen columns will be skipped from the analysis.
+37 -13
View File
@@ -3,7 +3,7 @@
"""
This tool provides the SQL "group by" functionality.
"""
import sys, string, re, commands, tempfile, random
import sys, string, re, commands, tempfile, random, sets
from rpy import *
def stop_err(msg):
@@ -48,7 +48,7 @@ def main():
for k,col in enumerate(cols):
col = int(col)-1
if ops[k] not in ['c', 'length', 'unique', 'random']:
if ops[k] not in ['c', 'length', 'unique', 'random', 'cuniq']:
# We'll get here only if the user didn't choose 'Concatenate' or 'Count' or 'Count Distinct' or 'pick randmly', which are the
# only aggregation functions that can be used on columns containing strings.
try:
@@ -104,7 +104,7 @@ def main():
valid = True
# Before appending the current value, make sure it is numeric if the
# operation for the column requires it.
if ops[i] not in ['c','length', 'unique','random']:
if ops[i] not in ['c','length', 'unique','random','cuniq']:
try:
float( fields[col].strip())
except:
@@ -125,13 +125,18 @@ def main():
out_str = prev_item
for i, op in enumerate( ops ):
rfunc = "r." + op
if op not in ['c','length','unique','random']:
if op == 'cuniq':
rfunc = "r.c"
else:
rfunc = "r." + op
if op not in ['c','length','unique','random','cuniq']:
for j, elem in enumerate( prev_vals[i] ):
prev_vals[i][j] = float( elem )
rout = "%g" %( eval( rfunc )( prev_vals[i] ))
rout = eval( rfunc )( prev_vals[i] )
if rounds[i] == 'yes':
rout = int(round(float(rout)))
else:
rout = '%g' %(float(rout))
else:
if op != 'random':
rout = eval( rfunc )( prev_vals[i] )
@@ -142,8 +147,14 @@ def main():
if op == 'unique':
rfunc = "r.length"
rout = eval( rfunc )( rout )
out_str += "\t" + str(rout)
if op in ['c', 'cuniq']:
if op == 'c':
out_str += "\t" + ','.join(rout)
else:
out_str += "\t" + ','.join(list(set(rout)))
else:
out_str += "\t" + str(rout)
print >>fout, out_str
prev_item = item
@@ -175,14 +186,19 @@ def main():
out_str = prev_item
for i, op in enumerate(ops):
rfunc = "r." + op
if op == 'cuniq':
rfunc = "r.c"
else:
rfunc = "r." + op
try:
if op not in ['c','length','unique','random']:
if op not in ['c','length','unique','random','cuniq']:
for j, elem in enumerate( prev_vals[i] ):
prev_vals[i][j] = float( elem )
rout = '%g' %( eval( rfunc )( prev_vals[i] ))
rout = eval( rfunc )( prev_vals[i] )
if rounds[i] == 'yes':
rout = int(round(float(rout)))
else:
rout = '%g' %(float(rout))
else:
if op != 'random':
rout = eval( rfunc )( prev_vals[i] )
@@ -192,8 +208,14 @@ def main():
if op == 'unique':
rfunc = "r.length"
rout = eval( rfunc )( rout )
out_str += "\t" + str( rout )
rout = eval( rfunc )( rout )
if op in ['c','cuniq']:
if op == 'c':
out_str += "\t" + ','.join(rout)
else:
out_str += "\t" + ','.join(list(set(rout)))
else:
out_str += "\t" + str( rout )
except:
skipped_lines += 1
if not first_invalid_line:
@@ -212,6 +234,8 @@ def main():
op = 'count_distinct'
elif op == 'random':
op = 'randomly_pick'
elif op == 'cuniq':
op = 'concat_distinct'
msg += op + "[c" + cols[i] + "] "
if skipped_lines > 0:
msg+= "--skipped %d invalid lines starting with line %d. Value '%s' in column %d is not numeric." % ( skipped_lines, first_invalid_line, invalid_value, invalid_column )
+4 -3
View File
@@ -1,4 +1,4 @@
<tool id="Grouping1" name="Group" version="1.5.0">
<tool id="Grouping1" name="Group" version="1.6.0">
<description>data by a column and perform aggregate operation on other columns.</description>
<command interpreter="python">
grouping.py
@@ -23,6 +23,7 @@
<option value="length">Count</option>
<option value="unique">Count Distinct</option>
<option value="c">Concatenate</option>
<option value="cuniq">Concatenate Distinct</option>
<option value="random">Randomly pick</option>
</param>
<param name="opcol" label="On column" type="data_column" data_ref="input1" />
@@ -87,7 +88,7 @@ This tool allows you to group the input dataset by a particular column and perfo
- running this tool with **Group by column 1**, Operations **Mean on column 2** and **Concatenate on column 3** will return::
chr10 1700.00 ['NM_11', 'NM_10']
chr22 1533.33 ['NM_17', 'NM_19', 'NM_18']
chr10 1700.00 NM_11,NM_10
chr22 1533.33 NM_17,NM_19,NM_18
</help>
</tool>