Skip to content

Commit

Permalink
Fix boxplot whiskers bug; Include outliers on chart
Browse files Browse the repository at this point in the history
  • Loading branch information
jmason-ebi committed Mar 10, 2020
1 parent 4fcbb0a commit c5ee8ab
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,39 @@ public ImpressBaseDTO getPipeline(String pipelineStableId)
SolrDocument doc = pipelineCore.query(query).getResults().get(0);

return new ImpressBaseDTO((Long)doc.getFirstValue(ImpressDTO.PIPELINE_ID),
Long.getLong(doc.getFirstValue(ImpressDTO.PIPELINE_STABLE_KEY).toString()),
(Long) doc.getFirstValue(ImpressDTO.PIPELINE_STABLE_KEY),
doc.getFirstValue(ImpressDTO.PIPELINE_STABLE_ID).toString(),
doc.getFirstValue(ImpressDTO.PIPELINE_NAME).toString());

}

public ProcedureDTO getProcedureByStableId(String pipelineStableId, String procedureStableId) {

ProcedureDTO procedure = new ProcedureDTO();
try {
SolrQuery query = new SolrQuery()
.setQuery(ImpressDTO.PROCEDURE_STABLE_ID + ":" + procedureStableId + " AND " + ImpressDTO.PIPELINE_STABLE_ID +":"+pipelineStableId)
.setFields(ImpressDTO.PROCEDURE_ID,
ImpressDTO.PROCEDURE_NAME,
ImpressDTO.PROCEDURE_STABLE_ID,
ImpressDTO.PROCEDURE_STABLE_KEY);

QueryResponse response = pipelineCore.query(query);

ImpressDTO imd = response.getBeans(ImpressDTO.class).get(0);

procedure.setStableId(imd.getProcedureStableId().toString());
procedure.setName(imd.getProcedureName().toString());
procedure.setStableKey(imd.getProcedureStableKey());
return procedure;

} catch (SolrServerException | IOException | IndexOutOfBoundsException e) {
e.printStackTrace();
}

return null;
}


public ProcedureDTO getProcedureByStableId(String procedureStableId) {

Expand Down Expand Up @@ -417,10 +444,16 @@ public Long getPipelineStableKey(String pipelineStableId) {
return null;
}

public String getProcedureUrlByStableKeyAndPipelineStableKey(Long procedureStableKey, Long pipelineStableKey) {

return String.format("%s/impress/ProcedureInfo?action=list&procID=%s&pipeID=%s",
cmsBaseUrl,
procedureStableKey,
pipelineStableKey);
}
public String getProcedureUrlByKey(String procedureStableKey) {

return cmsBaseUrl + "/impress/protocol/" + procedureStableKey;
return cmsBaseUrl + "/impress/ProcedureInfo?action=list&procID=" + procedureStableKey;
}


Expand Down Expand Up @@ -449,12 +482,8 @@ public String getAnchorForProcedure(String procedureName, String procedureStable
}


public String getPipelineUrlByStableId(String stableId){
Long pipelineKey = getPipelineStableKey(stableId);
if (pipelineKey != null ){
return cmsBaseUrl + "/impress/procedures/" + pipelineKey;
}
else return "#";
public String getPipelineUrlByStableKey(Long stableKey){
return cmsBaseUrl + "/impress/PipelineInfo?id=" + stableKey;
}


Expand Down Expand Up @@ -539,20 +568,71 @@ public ImpressDTO getParameterByStableIdSpecifyFields(String stableId, List<Stri


/**
* @author tudose
* @since 2015/08/20
* @param parameterStableId stable ID of the parameter in question
*/
public ParameterDTO getParameterByPipelineProcedureParameterStableKey(Long pipelineStableKey, Long procedureStableKey, String parameterStableId)
throws SolrServerException, IOException {

ParameterDTO param = new ParameterDTO();
SolrQuery query = new SolrQuery()
.setQuery(String.format("%s:%s AND %s:%S AND %s:%s",
ImpressDTO.PIPELINE_STABLE_KEY, pipelineStableKey,
ImpressDTO.PROCEDURE_STABLE_KEY, procedureStableKey,
ImpressDTO.PARAMETER_STABLE_ID, parameterStableId))
.setFields(ImpressDTO.PARAMETER_NAME,
ImpressDTO.PARAMETER_ID,
ImpressDTO.PARAMETER_STABLE_KEY,
ImpressDTO.PARAMETER_STABLE_ID,
ImpressDTO.OBSERVATION_TYPE,
ImpressDTO.CATEGORIES,
ImpressDTO.UNITX,
ImpressDTO.UNITY,
ImpressDTO.PROCEDURE_NAME)
.setRows(1);
QueryResponse response = pipelineCore.query(query);

List<ImpressDTO> dtoList = response.getBeans(ImpressDTO.class);
if ((dtoList == null) || (dtoList.isEmpty())) {
return null;
}

ImpressDTO dto = response.getBeans(ImpressDTO.class).get(0);
param.setId(dto.getParameterId());
param.setStableId(dto.getParameterStableId());
param.setStableKey(dto.getParameterStableKey());
param.setUnitX(dto.getUnitX());
param.setUnitY(dto.getUnitY());
param.setName(dto.getParameterName());
param.setObservationType(ObservationType.valueOf(dto.getObservationType()));
param.setCategories(dto.getCategories());
List<String> procedures = new ArrayList<String>();
procedures.add(dto.getProcedureName());
param.setProcedureNames(procedures);

return param;
}


/**
* @since 2015/08/20
* @param stableId
* @return
* @throws SolrServerException, IOException
*/
public ParameterDTO getParameterByStableId(String stableId)
throws SolrServerException, IOException {

ParameterDTO param = new ParameterDTO();
SolrQuery query = new SolrQuery()
.setQuery(ImpressDTO.PARAMETER_STABLE_ID + ":" + stableId )
.setFields(ImpressDTO.PARAMETER_NAME, ImpressDTO.PARAMETER_ID, ImpressDTO.PARAMETER_STABLE_KEY, ImpressDTO.PARAMETER_STABLE_ID, ImpressDTO.OBSERVATION_TYPE, ImpressDTO.CATEGORIES,
ImpressDTO.UNITX, ImpressDTO.UNITY, ImpressDTO.PROCEDURE_NAME )
.setFields(ImpressDTO.PARAMETER_NAME,
ImpressDTO.PARAMETER_ID,
ImpressDTO.PARAMETER_STABLE_KEY,
ImpressDTO.PARAMETER_STABLE_ID,
ImpressDTO.OBSERVATION_TYPE,
ImpressDTO.CATEGORIES,
ImpressDTO.UNITX,
ImpressDTO.UNITY,
ImpressDTO.PROCEDURE_NAME)
.setRows(1);
QueryResponse response = pipelineCore.query(query);

Expand Down Expand Up @@ -642,6 +722,6 @@ public static String getParameterUrl(Long parameterStableKey){

public String getParameterUrlByProcedureAndParameterKey(Long procedureKey,Long parameterKey) {

return cmsBaseUrl + "/impress/parameterontologies/"+parameterKey + "/"+procedureKey;
return cmsBaseUrl + "/impress/OntologyInfo?action=list&procID="+procedureKey+"#"+parameterKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,7 @@ public String toString() {
*/
public static Comparator<ImpressBaseDTO> getComparatorByName()
{
Comparator<ImpressBaseDTO> comp = new Comparator<ImpressBaseDTO>(){
@Override
public int compare(ImpressBaseDTO a, ImpressBaseDTO b)
{
return a.getName().compareTo(b.getName());
}
};
Comparator<ImpressBaseDTO> comp = Comparator.comparing(ImpressBaseDTO::getName);
return comp;
}

Expand All @@ -121,13 +115,7 @@ public int compare(ImpressBaseDTO a, ImpressBaseDTO b)
* @return Sort by stable id.
*/
public static Comparator<ImpressBaseDTO> getComparatorByStableId() {
Comparator<ImpressBaseDTO> comp = new Comparator<ImpressBaseDTO>(){
@Override
public int compare(ImpressBaseDTO a, ImpressBaseDTO b)
{
return a.getStableId().compareTo(b.getStableId());
}
};
Comparator<ImpressBaseDTO> comp = Comparator.comparing(ImpressBaseDTO::getStableId);
return comp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public enum ChartType {
, CATEGORICAL_STACKED_COLUMN
, TIME_SERIES_LINE
, PIE
, TIME_SERIES_LINE_BODYWEIGHT;
, TIME_SERIES_LINE_BODYWEIGHT
, TEXT;

public String getName() {
return this.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,84 +38,108 @@
//]
public class ChartsSeriesElement {

List<Float>originalData=new ArrayList<>();//to hold original data before being processsed to chart objects
private String name;
private String colorString;
private String chartTypeString;
private JSONArray boxPlotArray;
private JSONArray boxPlotOutliersArray;
private SexType sexType;
private ZygosityType zygosityType;

//to hold original data before being processsed to chart objects
List<Float> originalData = new ArrayList<>();

// to record the column of this data if say for boxplots we need this to determine how many other [] arrays to add before us
int column;

public List<Float> getOriginalData() {
return originalData;
}

public void setOriginalData(List<Float> originalData) {
this.originalData = originalData;
}
@Override
public String toString() {
return "ChartsSeriesElement [originalData=" + originalData
+ ", column=" + column + ", sexType=" + sexType
+ ", controlOrZygosity=" + zygosityType + ", name=" + name
+ ", colorString=" + colorString + ", chartTypeString="
+ chartTypeString + ", dataArray=" + boxPlotArray + "]\n";

public JSONArray getBoxPlotOutliersArray() {
return boxPlotOutliersArray;
}

public void setBoxPlotOutliersArray(JSONArray boxPlotOutliersArray) {
this.boxPlotOutliersArray = boxPlotOutliersArray;
}
int column;//to record the column of this data if say for boxplots we need this to determine how many other [] arrays to add before us
SexType sexType;
ZygosityType zygosityType;

/**
* if zygosity type is null then it must be wildtype
* @return
*/
public ZygosityType getZygosityType() {
return zygosityType;
}

public void setZygosityType(ZygosityType zygosityType) {
this.zygosityType = zygosityType;
}

String getControlOrZygosityString() {
if(zygosityType==null) {
if (zygosityType == null) {
return "WT";
}else {
} else {
return zygosityType.getShortName();
}

}

public int getColumn() {
return column;
}

public void setColumn(int column) {
this.column = column;
}

public SexType getSexType() {
return sexType;
}

public void setSexType(SexType sexType) {
this.sexType = sexType;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getColorString() {
return colorString;
}

public void setColorString(String colorString) {
this.colorString = colorString;
}

public String getChartTypeString() {
return chartTypeString;
}

public void setChartTypeString(String chartTypeString) {
this.chartTypeString = chartTypeString;
}

public JSONArray getBoxPlotArray() {
return boxPlotArray;
}

public void setBoxPlotArray(JSONArray dataArray) {
this.boxPlotArray = dataArray;
}
String name;
String colorString;
String chartTypeString;
JSONArray boxPlotArray;

@Override
public String toString() {
return "ChartsSeriesElement [originalData=" + originalData
+ ", column=" + column + ", sexType=" + sexType
+ ", controlOrZygosity=" + zygosityType + ", name=" + name
+ ", colorString=" + colorString + ", chartTypeString="
+ chartTypeString + ", dataArray=" + boxPlotArray + "]\n";
}

}
4 changes: 3 additions & 1 deletion web/src/main/java/uk/ac/ebi/phenotype/chart/GraphUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*******************************************************************************/
package uk.ac.ebi.phenotype.chart;

import org.apache.commons.lang3.StringUtils;
import org.apache.solr.client.solrj.SolrServerException;
import org.mousephenotype.cda.enumerations.ObservationType;
import org.mousephenotype.cda.solr.service.ExperimentService;
Expand Down Expand Up @@ -241,6 +240,9 @@ public static ChartType getDefaultChartType(ParameterDTO parameter) {
case time_series:
return ChartType.TIME_SERIES_LINE;

case text:
return ChartType.TEXT;

}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public String createScatter(ExperimentDTO experiment, Float min, Float max, Stri
}else if(parameter.getUnitX()!=null && !parameter.getUnitX().equals("")){
yTitle=parameter.getUnitX();
}

String yAxisLabel = parameter.getName() + " (" + yTitle + ")";
if (yTitle.trim().isEmpty()) {
yAxisLabel = parameter.getName();
}

String chartString=" $(function () { "
+ " chart71maleWTSI = new Highcharts.Chart({ "
+ " chart: {"
Expand All @@ -63,7 +69,7 @@ public String createScatter(ExperimentDTO experiment, Float min, Float max, Stri
+ " zoomType: 'xy'"

+ " },"
+ " title: { text: 'Scatterplot of the data' },"
+ " title: { useHTML:true, text: 'Scatterplot of the data <a href=\"/help/quick-guide-to-the-website/chart-page/\" target=\"_blank\"><i class=\"fa fa-question-circle\" style=\"color: #ce6211;\"></i></a>' },"
+ " xAxis: {"
+ " type: 'datetime',"
+ " labels: { "
Expand All @@ -82,7 +88,7 @@ public String createScatter(ExperimentDTO experiment, Float min, Float max, Stri
+ (max != null ? " max: " + max + ", " : "")
+ (min != null ? " min: " + min + ", " : "")
+ " title: { "
+ " text: '" + yTitle + "' "
+ " text: '" + yAxisLabel + "' "
+ " } "
+ " }, "
+ " credits: { "
Expand Down Expand Up @@ -115,7 +121,7 @@ public String createScatter(ExperimentDTO experiment, Float min, Float max, Stri
+ " }, "
+ " series: " +
series.toString()
+ " }); console.log('HERE');"
+ " });"
+ " }); ";

return chartString;
Expand Down
Loading

0 comments on commit c5ee8ab

Please sign in to comment.