# Changeset 5138

Ignore:
Timestamp:
Oct 16, 2009, 2:27:01 PM (13 years ago)
Message:

References #1385 and #1386. Plot functions in experiment explorer

Both types of plots can now be generated and I think the percentile values are correctly calculated.

Location:
trunk
Files:
3 edited

Unmodified
Removed
• ## trunk/src/clients/web/net/sf/basedb/clients/web/servlet/ExperimentExplorerPlotServlet.java

• median = BAWI.getMedian()
• 5th percentile = BAWI.getMinRegularValue()
• 25th percentile = BAWI.getQ1()
• 75th percentile = BAWI.getQ3()
• 95th percentile = BAWI.getMaxRegularValue()
The mean and outlier values are currently not calculated (may change in the future). @param values The list of values which must be sorted in ascending order @return A BoxAndWhiskerItem object */ public BoxAndWhiskerItem calculateBoxAndWhiskerStatistics(List values) { float median = getPercentile(values, 50); float p5 = getPercentile(values, 5); float p25 = getPercentile(values, 25); float p75 = getPercentile(values, 75); float p95 = getPercentile(values, 95); return new BoxAndWhiskerItem(Float.NaN, median, p25, p75, p5, p95, Float.NaN, Float.NaN, null); } /** Calculates the percentile values from a sorted list of values. If the percentile falls between two elements in the list the average of the two nearest elements are used. @param values The values which must be sorted @param percentile The percentile, a value between 0 and 100 @return The percentile value, or Float.NaN if it could not be calculated */ public float getPercentile(List values, int percentile) { int size = values.size(); if (size == 0) return Float.NaN; if (size == 1) return values.get(0).floatValue(); int width = size + 1; int pos = width * percentile / 100; if (pos == 0) { // Overflow to the left -- return first value return values.get(0).floatValue(); } else if (pos >= size) { // Overflow to the right -- return last value return values.get(size-1).floatValue(); } if (width * percentile % 100 == 0) { // Exact hit -- return one value return values.get(pos-1).floatValue(); } else { // Hit between two values -- return the average return (values.get(pos-1).floatValue() + values.get(pos).floatValue())/2; } } /** Uses as a column key in the plots. This allows us to separate the displayed label from the identity of the column. Eg. there is no need to make sure that the label strings are unique since we can use some internal id for this purpose.

Additionally, this class allows us to map annotations to colors that are used to draw small colored boxes below each column label. */ public static class ColumnKey implements Comparable { private final Comparable id; private final String title; private final Map annotations; public ColumnKey(Comparable id, String title) { this.id = id; this.title = title; this.annotations = new HashMap(); } /* From the Comparable interface ----------------------------- */ /** The ID of the key determines equality. */ @SuppressWarnings("unchecked") @Override public int compareTo(ColumnKey o) { return id.compareTo(o.id); } // ------------------------------- /* From the Object class ------------------------------- */ @Override public String toString() { return title; } @Override public boolean equals(Object o) { if (o == null) return false; if (this == o) return true; if (o.getClass() != getClass()) return false; ColumnKey ck = (ColumnKey)o; return id.equals(ck.id); } @Override public int hashCode() { return id.hashCode(); } // ------------------------------------ public void setColor(String annotation, Color color) { annotations.put(annotation, color); } public Color getColor(String annotation) { return annotations.get(annotation); } } }

• ## trunk/www/views/experiments/explorer/view/plotter.jsp

 r5114 final int reporterIndex = Values.getInt(request.getParameter("reporterIndex")); final int positionIndex = Values.getInt(request.getParameter("positionIndex")); final String plotType = Values.getString(request.getParameter("type"), "line"); final int annotationTypeId = Values.getInt(request.getParameter("annotationTypeId")); final boolean needAverageMethod = positionIndex == ExperimentExplorer.SPOT_AVG; BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId); RawDataType rdt = bas.getRawDataType(); Experiment experiment = bas.getExperiment(); int maxRawMappings = bas.getMaxRawMappingsForSpot(); IntensityTransform transform = bas.getIntensityTransform(); final BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId); final RawDataType rdt = bas.getRawDataType(); final Experiment experiment = bas.getExperiment(); final int maxRawMappings = bas.getMaxRawMappingsForSpot(); final IntensityTransform transform = bas.getIntensityTransform(); final ExperimentExplorer explorer = ExperimentExplorer.getExplorer(bas); final List annotationTypes = explorer.getAnnotationTypes(dc, true); List formulas = new LinkedList(); { var plotType = getPlotType(); if (plotType == 'scatter') { return validateScatterPlot(); if (plotType == 'line') { return validateLinePlot(); } else if (plotType == 'box') { return validateBoxPlot(); } return false; } function validateScatterPlot() { var frm = document.forms['scatter']; function validateLinePlot() { var frm = document.forms['line']; if (Main.trimString(frm.yFormula.value) == '') { } var plotType = 'scatter'; function validateBoxPlot() { var frm = document.forms['box']; if (Main.trimString(frm.yFormula.value) == '') { alert("You must enter an expression for the Y axis"); frm.yFormula.focus(); return false; } return true; } var plotType = '<%=plotType%>'; function getPlotType() { function switchTab(tabControlId, tabId) { if (tabId == 'scatter' || tabId == 'histogram') if (tabId == 'line' || tabId == 'box') { plotType = tabId; { var index = list.selectedIndex; var frm = document.forms['scatter']; var frm = list.form; if (frm.averageMethod) { url += '&height='+plotFrm.height.value; } var plotType = getPlotType(); if (plotType == 'scatter') { var frm = document.forms['scatter']; url += '&type=scatter'; if (plotType == 'line') { var frm = document.forms['line']; url += '&type=line'; url += '&y='+Main.encodeURI(frm.yFormula.value); url += '&yLog='+(frm.yLog.checked ? 1 : 0); url += '&averageMethod=' + frm.averageMethod[frm.averageMethod.selectedIndex].value; } } else if (plotType == 'box') { var frm = document.forms['box']; url += '&type=box'; url += '&y='+Main.encodeURI(frm.yFormula.value); url += '&yLog='+(frm.yLog.checked ? 1 : 0); url += '&yLabel='+Main.encodeURI(frm.yLabel.value); url += '&annotationTypeId=' + frm.annotationTypeId[frm.annotationTypeId.selectedIndex].value; } url += '&' + new Date().getTime(); style="<%="width: "+(int)(scale*340)+"px;"%>" contentstyle="<%="height: "+(int)(scale*340)+"px;"%>" active="<%=plotType%>" remember="false" switch="switchTab">
image="expression_builder.gif" tooltip="Use the Expression builder" onclick="openExpressionBuilder('Y-axis expression', 'scatter', 'yFormula', 'COLUMN_EXPRESSION')" onclick="openExpressionBuilder('Y-axis expression', 'line', 'yFormula', 'COLUMN_EXPRESSION')" />
<% if (positionIndex == ExperimentExplorer.SPOT_AVG) { %> <% } %>
Y-axis
Presets
Expression
Label
Log scale
Average
X-axis
Annotation
• ## trunk/www/views/experiments/explorer/view/view.jsp

 r5137 function plotSpotData() { var url = 'plotter.jsp?ID=<%=ID%>'; var url = 'plotter.jsp?ID=<%=ID%>&type=line'; url += '&bioAssaySetId=<%=bioAssaySetId%>'; url += '&reporterIndex=<%=reporterIndex%>'; url += '&positionIndex=<%=positionIndex%>'; Main.openPopup(url, 'SpotPlot', 1100, 700); } function boxPlot(annotationType) { var url = 'plotter.jsp?ID=<%=ID%>&type=box'; url += '&bioAssaySetId=<%=bioAssaySetId%>'; url += '&reporterIndex=<%=reporterIndex%>'; url += '&positionIndex=<%=positionIndex%>'; url += '&annotationTypeId=' + annotationType; Main.openPopup(url, 'BoxPlot', 1100, 700); } <% for (AnnotationGroup ag : summary.getAnnotationGroups()) %> Mean ch <%=ch%> int. <% for (AnnotationGroup ag : summary.getAnnotationGroups()) %> <% for (AnnotationGroup ag : summary.getAnnotationGroups()) <% for (AnnotationGroup ag : summary.getAnnotationGroups()) <% for (AnnotationGroup ag : summary.getAnnotationGroups())
<%=Base.getLinkedName(ID, at, false, true)%> " tooltip="Box plot for selected spot data per annotation group" />
Mean ch <%=ch%> int.
G. mean ratio G. mean ratio
log2ratio SD log2ratio SD
Count Count
Note: See TracChangeset for help on using the changeset viewer.