Changeset 2131
- Timestamp:
- Mar 30, 2006, 12:12:16 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/servlet/PlotServlet.java
r2116 r2131 26 26 27 27 import net.sf.basedb.core.Application; 28 import net.sf.basedb.core.BaseException; 28 29 import net.sf.basedb.core.BioAssay; 29 30 import net.sf.basedb.core.BioAssaySet; … … 34 35 import net.sf.basedb.core.SessionControl; 35 36 import net.sf.basedb.core.DbControl; 37 import net.sf.basedb.core.VirtualColumn; 38 import net.sf.basedb.core.query.Dynamic; 36 39 import net.sf.basedb.core.query.Expression; 37 40 import net.sf.basedb.core.query.Expressions; 38 41 import net.sf.basedb.core.query.JoinType; 42 import net.sf.basedb.core.query.Orders; 39 43 import net.sf.basedb.core.query.Selects; 44 import net.sf.basedb.core.query.SqlResult; 45 import net.sf.basedb.core.query.SqlResultIterator; 40 46 import net.sf.basedb.clients.web.util.HTML; 41 47 import net.sf.basedb.clients.web.util.Values; … … 62 68 import java.io.OutputStream; 63 69 import java.io.IOException; 70 import java.sql.SQLException; 71 import java.util.List; 64 72 65 73 /** … … 144 152 try 145 153 { 146 // Functions for parsing ch(n) and raw(property)147 JepFunction ch = new ChannelFunction();148 JepFunction raw = new RawFunction();149 150 // Convert formulas to Expression:s151 Expression[] x = xFormulas == null ? null : new Expression[xFormulas.length];152 Expression[] y = yFormulas == null ? null : new Expression[yFormulas.length];153 if (xFormulas != null)154 {155 for (int i = 0; i < xFormulas.length; ++i)156 {157 x[i] = Jep.formulaToExpression(xFormulas[i], ch, raw);158 if (xLog) x[i] = Expressions.log2(x[i]);159 }160 }161 if (yFormulas != null)162 {163 for (int i = 0; i < yFormulas.length; ++i)164 {165 y[i] = Jep.formulaToExpression(yFormulas[i], ch, raw);166 if (yLog) y[i] = Expressions.log2(y[i]);167 }168 }169 170 // Get the query171 154 final SessionControl sc = Application.getSessionControl(ID, request.getRemoteAddr()); 172 155 dc = sc.newDbControl(); 173 156 BioAssay ba = bioAssayId == 0 ? null : BioAssay.getById(dc, bioAssayId); 174 157 BioAssaySet bas = ba == null ? BioAssaySet.getById(dc, bioAssaySetId) : ba.getBioAssaySet(); 175 176 DynamicSpotQuery query = ba != null ? ba.getSpotData() : bas.getSpotData(); 177 158 178 159 JFreeChart chart = null; 179 if ("scatter".equals(type)) 180 { 181 ScatterPlot plot = new ScatterPlot(xLabel, yLabel); 182 for (int i = 0; i < x.length; ++i) 183 { 184 query.reset(); 185 query.joinRawData(JoinType.INNER); // TODO - only join if used in query 186 query.select(Selects.expression(x[i], "x")); 187 query.select(Selects.expression(y[i], "y")); 188 plot.addData(query.iterate(dc), Integer.toString(i)); 189 } 190 chart = plot.getChart(); 160 if ("cfplot".equals(type)) 161 { 162 chart = generateCFPlot(ba, xLabel, yLabel); 191 163 } 192 164 else 193 165 { 194 HistogramPlot plot = new HistogramPlot(xLabel, yLabel); 195 query.setReturnTotalCount(true); 196 for (int i = 0; i < x.length; ++i) 197 { 198 query.reset(); 199 query.joinRawData(JoinType.INNER); // TODO - only join if used in query 200 query.select(Selects.expression(x[i], "x")); 201 if (!isCount) query.select(Selects.expression(y[i], "y")); 202 plot.addData(query.iterate(dc), Integer.toString(i), binSize, 203 HistogramPlot.YAggregate.valueOf(yAggregate.toUpperCase())); 204 } 205 chart = plot.getChart(); 206 } 166 // Functions for parsing ch(n) and raw(property) 167 JepFunction ch = new ChannelFunction(); 168 JepFunction raw = new RawFunction(); 169 170 // Convert formulas to Expression:s 171 Expression[] x = xFormulas == null ? null : new Expression[xFormulas.length]; 172 Expression[] y = yFormulas == null ? null : new Expression[yFormulas.length]; 173 if (xFormulas != null) 174 { 175 for (int i = 0; i < xFormulas.length; ++i) 176 { 177 x[i] = Jep.formulaToExpression(xFormulas[i], ch, raw); 178 if (xLog) x[i] = Expressions.log2(x[i]); 179 } 180 } 181 if (yFormulas != null) 182 { 183 for (int i = 0; i < yFormulas.length; ++i) 184 { 185 y[i] = Jep.formulaToExpression(yFormulas[i], ch, raw); 186 if (yLog) y[i] = Expressions.log2(y[i]); 187 } 188 } 189 190 // Get the query 191 DynamicSpotQuery query = ba != null ? ba.getSpotData() : bas.getSpotData(); 192 193 if ("scatter".equals(type)) 194 { 195 ScatterPlot plot = new ScatterPlot(xLabel, yLabel); 196 for (int i = 0; i < x.length; ++i) 197 { 198 query.reset(); 199 query.joinRawData(JoinType.INNER); // TODO - only join if used in query 200 query.select(Selects.expression(x[i], "x")); 201 query.select(Selects.expression(y[i], "y")); 202 plot.addData(query.iterate(dc), Integer.toString(i)); 203 } 204 chart = plot.getChart(); 205 } 206 else 207 { 208 HistogramPlot plot = new HistogramPlot(xLabel, yLabel); 209 query.setReturnTotalCount(true); 210 for (int i = 0; i < x.length; ++i) 211 { 212 query.reset(); 213 query.joinRawData(JoinType.INNER); // TODO - only join if used in query 214 query.select(Selects.expression(x[i], "x")); 215 if (!isCount) query.select(Selects.expression(y[i], "y")); 216 plot.addData(query.iterate(dc), Integer.toString(i), binSize, 217 HistogramPlot.YAggregate.valueOf(yAggregate.toUpperCase())); 218 } 219 chart = plot.getChart(); 220 } 221 } 222 207 223 if (title != null) chart.setTitle(title); 208 224 chart.removeLegend(); … … 301 317 doGet(request, response); 302 318 } 319 320 321 private JFreeChart generateCFPlot(BioAssay ba, String xLabel, String yLabel) 322 throws Exception 323 { 324 DbControl dc = ba.getDbControl(); 325 // Get parent bioassay 326 List<BioAssay> parents = ba.getParents().list(dc); 327 328 if (parents.size() != 1) 329 { 330 throw new BaseException("A bioassay must have exactly one parent to generate a correction factor plot"); 331 } 332 333 BioAssay parent = parents.get(0); 334 335 // Generate MA-data for it 336 JepFunction ch = new ChannelFunction(); 337 JepFunction raw = new RawFunction(); 338 339 Expression m = Jep.formulaToExpression("log2(ch(1) / ch(2))", ch); 340 Expression a = Jep.formulaToExpression("log(ch(1) * ch(2)) / 2", ch); 341 Expression position = Dynamic.column(VirtualColumn.POSITION); 342 343 DynamicSpotQuery parentQuery = parent.getSpotData(); 344 parentQuery.select(Selects.expression(position, "pos")); 345 parentQuery.select(Selects.expression(m, "m")); 346 parentQuery.select(Selects.expression(a, "a")); 347 parentQuery.order(Orders.asc(position)); 348 349 DynamicSpotQuery query = ba.getSpotData(); 350 query.select(Selects.expression(position, "pos")); 351 query.select(Selects.expression(m, "m")); 352 query.order(Orders.asc(position)); 353 354 // Add CF-data to the plot 355 356 SqlResultIterator cf = new CFResultIterator(parentQuery.iterate(dc), query.iterate(dc)); 357 358 ScatterPlot plot = new ScatterPlot(xLabel, yLabel); 359 plot.addData(cf, "ma", "cf"); 360 return plot.getChart(); 361 } 362 363 364 private static class CFResultIterator 365 implements SqlResultIterator 366 { 367 368 private final SqlResultIterator parent; 369 private final SqlResultIterator child; 370 private final CFSqlResult next; 371 372 CFResultIterator(SqlResultIterator parent, SqlResultIterator child) 373 { 374 this.parent = parent; 375 this.child = child; 376 this.next = new CFSqlResult(); 377 } 378 379 /* 380 From the Iterator interface 381 ------------------------------------------- 382 */ 383 public boolean hasNext() 384 { 385 return child.hasNext(); 386 } 387 public SqlResult next() 388 { 389 try 390 { 391 SqlResult nextChild = child.next(); 392 while (parent.hasNext()) 393 { 394 SqlResult nextParent = parent.next(); 395 if (nextChild.getInt(1) == nextParent.getInt(1)) 396 { 397 next.setResult(nextParent, nextChild); 398 return next; 399 } 400 } 401 } 402 catch (SQLException ex) 403 { 404 throw new BaseException(ex); 405 } 406 return null; 407 } 408 /** 409 Not supported. 410 @throws UnsupportedOperationException Always 411 */ 412 public void remove() 413 { 414 throw new UnsupportedOperationException("remove"); 415 } 416 // ------------------------------------------- 417 418 /* 419 From the QueryResult interface 420 ------------------------------------------- 421 */ 422 public int getTotalCount() 423 { 424 return child.getTotalCount(); 425 } 426 // ------------------------------------------- 427 428 /* 429 From the ResultIterator interface 430 ------------------------------------------- 431 */ 432 public void close() 433 { 434 parent.close(); 435 child.close(); 436 } 437 public boolean isClosed() 438 { 439 return child.isClosed(); 440 } 441 // ------------------------------------------- 442 443 /* 444 From the SqlResultIterator interface 445 ------------------------------------------- 446 */ 447 public int getIndex(String name) 448 throws SQLException 449 { 450 if ("a".equals(name)) 451 { 452 return 1; 453 } 454 else if ("m".equals(name)) 455 { 456 return 2; 457 } 458 else if ("cf".equals(name)) 459 { 460 return 3; 461 } 462 throw new SQLException("Unknown column name: " + name); 463 } 464 // ------------------------------------------- 465 466 } 467 468 private static class CFSqlResult 469 implements SqlResult 470 { 471 472 private SqlResult parent; 473 private SqlResult child; 474 475 CFSqlResult() 476 {} 477 478 void setResult(SqlResult parent, SqlResult child) 479 { 480 this.parent = parent; 481 this.child = child; 482 } 483 484 public float getFloat(int index) 485 throws SQLException 486 { 487 switch (index) 488 { 489 case 1: 490 return parent.getFloat(3); 491 case 2: 492 return parent.getFloat(2); 493 case 3: 494 return parent.getFloat(2) - child.getFloat(2); 495 default: 496 throw new ArrayIndexOutOfBoundsException(index); 497 } 498 } 499 public int getInt(int index) 500 throws SQLException 501 { 502 return (int)getFloat(index); 503 } 504 public Object getObject(int index) 505 throws SQLException 506 { 507 return getFloat(index); 508 } 509 public short getShort(int index) 510 throws SQLException 511 { 512 return (short)getFloat(index); 513 } 514 public String getString(int index) 515 throws SQLException 516 { 517 return String.valueOf(getFloat(index)); 518 } 519 520 } 303 521 } -
trunk/src/core/net/sf/basedb/util/plot/HistogramPlot.java
r2116 r2131 25 25 package net.sf.basedb.util.plot; 26 26 27 import net.sf.basedb.core.DynamicResultIterator;28 27 import net.sf.basedb.core.query.SqlResult; 28 import net.sf.basedb.core.query.SqlResultIterator; 29 29 30 30 import org.jfree.chart.JFreeChart; … … 70 70 } 71 71 72 public void addData( DynamicResultIterator data, String name, float binSize, YAggregate yAggregate)72 public void addData(SqlResultIterator data, String name, float binSize, YAggregate yAggregate) 73 73 throws SQLException 74 74 { -
trunk/src/core/net/sf/basedb/util/plot/ScatterPlot.java
r2087 r2131 25 25 package net.sf.basedb.util.plot; 26 26 27 import net.sf.basedb.core.DynamicResultIterator;28 27 import net.sf.basedb.core.query.SqlResult; 28 import net.sf.basedb.core.query.SqlResultIterator; 29 29 30 30 import org.jfree.chart.JFreeChart; 31 31 import org.jfree.chart.axis.NumberAxis; 32 import org.jfree.chart.plot.SeriesRenderingOrder; 32 33 import org.jfree.chart.plot.XYPlot; 33 34 import org.jfree.chart.renderer.xy.XYDotRenderer; … … 61 62 62 63 plot = new XYPlot(allSeries, domainAxis, rangeAxis, new XYDotRenderer()); 64 plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); 63 65 chart = new JFreeChart(plot); 64 66 chart.setAntiAlias(false); 65 67 } 66 68 67 public void addData( DynamicResultIterator data, String name)69 public void addData(SqlResultIterator data, String... names) 68 70 throws SQLException 69 71 { 70 XYSeries series = new XYSeries(name); 72 XYSeries[] series = new XYSeries[names.length]; 73 for (int i = 0; i < names.length; ++i) 74 { 75 series[i] = new XYSeries(names[i]); 76 } 71 77 while (data.hasNext()) 72 78 { 73 79 SqlResult r = data.next(); 74 series.add(r.getFloat(1), r.getFloat(2)); 80 float x = r.getFloat(1); 81 for (int i = 0; i < series.length; ++i) 82 { 83 series[i].add(x, r.getFloat(2+i)); 84 } 75 85 } 76 allSeries.addSeries(series); 86 for (int i = 0; i < series.length; ++i) 87 { 88 allSeries.addSeries(series[i]); 89 } 77 90 } 78 91 -
trunk/src/web.xml.in
r2113 r2131 96 96 </servlet-mapping> 97 97 98 <!-- The PlotServlet used to generate overiew and correction factor plots -->99 <servlet>100 <servlet-name>jfreeplot</servlet-name>101 <servlet-class>102 net.sf.basedb.clients.web.servlet.JFreePlotServlet103 </servlet-class>104 </servlet>105 <servlet-mapping>106 <servlet-name>jfreeplot</servlet-name>107 <url-pattern>/views/experiments/plotter/jfreeplot/*</url-pattern>108 </servlet-mapping>109 110 98 <!-- The Generic PlotServlet for the HTML plot tool --> 111 99 <servlet> -
trunk/www/include/scripts/tabcontrol.js
r2111 r2131 90 90 } 91 91 } 92 93 this.isActive = function(tabControlId, tabId) 94 { 95 var realTabId = tabControlId+'.'+tabId; 96 var tabControl = document.getElementById(tabControlId); 97 var tab = document.getElementById(realTabId); 98 return tabControl.activeTab == tab; 99 } 92 100 93 101 this.mouseEnter = function(tabControlId, tabId) -
trunk/www/views/experiments/bioassaysets/view_bioassayset.jsp
r2102 r2131 150 150 function switchTab(tabControlId, tabId) 151 151 { 152 if (TabControl.isActive(tabControlId, tabId)) return; 152 153 if (tabId == 'bioassays') 153 154 { … … 369 370 370 371 <t:tab id="overviewplots" title="Overview plots" 372 tooltip="MA-plots of each bioassay in this bioassay set" 371 373 visible="<%=rawDataType.getChannels() == 2%>"> 372 374 <% 373 375 if ("overviewplots".equals(tabId)) 374 376 { 375 /*376 TODO - replace jfreeplot with generic plot servlet377 377 String M = HTML.urlEncode("log2(ch(1) / ch(2))"); 378 378 String A = HTML.urlEncode("log(ch(1) * ch(2)) / 2"); 379 String xName = HTML.urlEncode("A, log10(ch1 * ch2) / 2"); 380 String yName = HTML.urlEncode("M, log2(ch1 / ch2)"); 381 */ 379 String xLabel = HTML.urlEncode("A, log10(ch1 * ch2) / 2"); 380 String yLabel = HTML.urlEncode("M, log2(ch1 / ch2)"); 382 381 ItemQuery<BioAssay> bioAssayQuery = bioAssaySet.getBioAssays(); 383 382 bioAssayQuery.order(Orders.asc(Hql.property("name"))); 384 383 for (BioAssay bioAssay : bioAssayQuery.list(dc)) 385 384 { 386 /*387 385 String url = "../plotter/plot?ID="+ID+"&bioassay_id="+bioAssay.getId(); 388 386 url += "&type=scatter&width=400&height=300"; 389 url += "&x="+A+"&y="+M+"&xaxis="+xName+"&yaxis="+yName; 390 */ 391 String url = "../plotter/jfreeplot/"+ID+"/"+bioAssaySet.getId()+"/"+bioAssay.getId()+"/overviewPlot"; 387 url += "&x="+A+"&y="+M+"&xLabel="+xLabel+"&yLabel="+yLabel; 388 url += "&title="+HTML.urlEncode(bioAssay.getName()); 392 389 %> 393 <img src="<%=url%>"> 390 <img src="<%=url%>" width="400" height="300" 391 title="MA-plot for bioassay <%=HTML.encodeTags(bioAssay.getName())%>"> 394 392 <% 395 393 } … … 399 397 400 398 <t:tab id="cfplots" title="Correction factor plots" 399 tooltip="MA-plot of the parent bioassays together with a correction factor for each spot in the current bioassayset." 401 400 visible="<%=rawDataType.getChannels() == 2 && bioAssaySet.getTransformation().getSource() != null %>"> 402 401 <% … … 405 404 ItemQuery<BioAssay> bioAssayQuery = bioAssaySet.getBioAssays(); 406 405 bioAssayQuery.order(Orders.asc(Hql.property("name"))); 406 String xLabel = HTML.urlEncode("A, log10(ch1 * ch2) / 2"); 407 String yLabel = HTML.urlEncode("M, log2(ch1 / ch2)"); 407 408 for (BioAssay bioAssay : bioAssayQuery.list(dc)) 408 409 { 409 String url = "../plotter/jfreeplot/"+ID+"/"+bioAssaySet.getId()+"/"+bioAssay.getId()+"/correctionFactorPlot"; 410 String url = "../plotter/plot?ID="+ID+"&bioassay_id="+bioAssay.getId(); 411 url += "&type=cfplot&width=400&height=300"; 412 url += "&xLabel="+xLabel+"&yLabel="+yLabel; 413 url += "&title="+HTML.urlEncode(bioAssay.getName()); 410 414 %> 411 <img src="<%=url%>"> 415 <img src="<%=url%>" width="400" height="300" 416 title="Correction factor plot for bioassay <%=HTML.encodeTags(bioAssay.getName())%>"> 412 417 <% 413 418 }
Note: See TracChangeset
for help on using the changeset viewer.