From 81009ebc93e29c77b41c34149281a5873039b0a1 Mon Sep 17 00:00:00 2001 From: Charles Haynes Date: Tue, 20 Aug 2024 13:14:34 -0400 Subject: [PATCH] Update DataBinHelper to be util class --- .../columnar/util/CustomDataFilterUtil.java | 20 +---- .../ClinicalDataIntervalFilterApplier.java | 7 +- .../cbioportal/web/util/DataBinHelper.java | 83 ++++++++++--------- .../org/cbioportal/web/util/DataBinner.java | 38 ++++----- .../web/util/DiscreteDataBinner.java | 6 +- .../org/cbioportal/web/util/IdPopulator.java | 2 - .../cbioportal/web/util/LinearDataBinner.java | 10 +-- .../web/util/LogScaleDataBinner.java | 5 +- .../web/util/ScientificSmallDataBinner.java | 10 +-- .../MolecularProfileCountTest.java | 13 ++- .../web/util/ClinicalDataBinUtilTest.java | 5 +- .../cbioportal/web/util/DataBinnerTest.java | 4 - 12 files changed, 80 insertions(+), 123 deletions(-) diff --git a/src/main/java/org/cbioportal/web/columnar/util/CustomDataFilterUtil.java b/src/main/java/org/cbioportal/web/columnar/util/CustomDataFilterUtil.java index 4ffecd61316..44b4007ac43 100644 --- a/src/main/java/org/cbioportal/web/columnar/util/CustomDataFilterUtil.java +++ b/src/main/java/org/cbioportal/web/columnar/util/CustomDataFilterUtil.java @@ -3,10 +3,7 @@ import com.google.common.collect.Range; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.map.MultiKeyMap; -import org.cbioportal.model.Sample; -import org.cbioportal.persistence.StudyViewRepository; import org.cbioportal.service.CustomDataService; -import org.cbioportal.service.SampleService; import org.cbioportal.service.util.CustomDataSession; import org.cbioportal.web.parameter.*; import org.cbioportal.web.util.CustomDatatype; @@ -25,26 +22,15 @@ @Component public class CustomDataFilterUtil { - private final SampleService sampleService; private final StudyViewFilterUtil studyViewFilterUtil; private final CustomDataService customDataService; - private final DataBinHelper dataBinHelper; @Autowired - public CustomDataFilterUtil(StudyViewRepository studyViewRepository, SampleService sampleService, StudyViewFilterUtil studyViewFilterUtil, CustomDataService customDataService, DataBinHelper dataBinHelper) { - this.sampleService = sampleService; + public CustomDataFilterUtil(StudyViewFilterUtil studyViewFilterUtil, CustomDataService customDataService) { this.studyViewFilterUtil = studyViewFilterUtil; this.customDataService = customDataService; - this.dataBinHelper = dataBinHelper; } - Function sampleToSampleIdentifier = new Function() { - - public SampleIdentifier apply(Sample sample) { - return studyViewFilterUtil.buildSampleIdentifier(sample.getCancerStudyIdentifier(), sample.getStableId()); - } - }; - public List extractCustomDataSamples(final StudyViewFilter studyViewFilter) { if (studyViewFilter == null) { return null; @@ -207,7 +193,7 @@ else if (value.startsWith(gt)) { return null; } - return dataBinHelper.calcRange(min, startInclusive, max, endInclusive); + return DataBinHelper.calcRange(min, startInclusive, max, endInclusive); } private Range calculateRangeValueForFilter(DataFilterValue filterValue) { @@ -223,7 +209,7 @@ private Range calculateRangeValueForFilter(DataFilterValue filterVal startInclusive = true; } - return dataBinHelper.calcRange(start, startInclusive, end, endInclusive); + return DataBinHelper.calcRange(start, startInclusive, end, endInclusive); } private Boolean containsNA(ClinicalDataFilter filter) { diff --git a/src/main/java/org/cbioportal/web/util/ClinicalDataIntervalFilterApplier.java b/src/main/java/org/cbioportal/web/util/ClinicalDataIntervalFilterApplier.java index 0484f024bc7..66d310a2511 100644 --- a/src/main/java/org/cbioportal/web/util/ClinicalDataIntervalFilterApplier.java +++ b/src/main/java/org/cbioportal/web/util/ClinicalDataIntervalFilterApplier.java @@ -18,9 +18,6 @@ @Component public class ClinicalDataIntervalFilterApplier extends ClinicalDataFilterApplier { - @Autowired - private DataBinHelper dataBinHelper; - @Autowired public ClinicalDataIntervalFilterApplier(PatientService patientService, ClinicalDataService clinicalDataService, @@ -110,7 +107,7 @@ else if (value.startsWith(gt)) { return null; } - return dataBinHelper.calcRange(min, startInclusive, max, endInclusive); + return DataBinHelper.calcRange(min, startInclusive, max, endInclusive); } private Range calculateRangeValueForFilter(DataFilterValue filterValue) { @@ -126,7 +123,7 @@ private Range calculateRangeValueForFilter(DataFilterValue filterVal startInclusive = true; } - return dataBinHelper.calcRange(start, startInclusive, end, endInclusive); + return DataBinHelper.calcRange(start, startInclusive, end, endInclusive); } private Boolean containsNA(ClinicalDataFilter filter) { diff --git a/src/main/java/org/cbioportal/web/util/DataBinHelper.java b/src/main/java/org/cbioportal/web/util/DataBinHelper.java index 6e50f437f5d..9138aef2572 100644 --- a/src/main/java/org/cbioportal/web/util/DataBinHelper.java +++ b/src/main/java/org/cbioportal/web/util/DataBinHelper.java @@ -1,18 +1,21 @@ package org.cbioportal.web.util; import org.cbioportal.model.DataBin; -import org.springframework.stereotype.Component; import com.google.common.collect.Range; import java.math.BigDecimal; import java.math.RoundingMode; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import org.springframework.util.Assert; -@Component public class DataBinHelper { - public DataBin calcUpperOutlierBin(List gteValues, List gtValues) { + public static DataBin calcUpperOutlierBin(List gteValues, List gtValues) { BigDecimal gteMin = gteValues.size() > 0 ? Collections.min(gteValues) : null; BigDecimal gtMin = gtValues.size() > 0 ? Collections.min(gtValues) : null; BigDecimal min; @@ -39,7 +42,7 @@ public DataBin calcUpperOutlierBin(List gteValues, List return dataBin; } - public DataBin calcLowerOutlierBin(List lteValues, List ltValues) { + public static DataBin calcLowerOutlierBin(List lteValues, List ltValues) { BigDecimal lteMax = lteValues.size() > 0 ? Collections.max(lteValues) : null; BigDecimal ltMax = ltValues.size() > 0 ? Collections.max(ltValues) : null; BigDecimal max; @@ -65,7 +68,7 @@ public DataBin calcLowerOutlierBin(List lteValues, List return dataBin; } - public List calcQuartileBoundaries(List sortedValues) { + public static List calcQuartileBoundaries(List sortedValues) { // Edge case: some of Q1, Q2, and Q3 are the same value. // Solution: reduce bins to represent unique values only. // Note: cannot use stream.distinct() because BigDecimal does @@ -87,7 +90,7 @@ public List calcQuartileBoundaries(List sortedValues) { return boundaries; } - public Range calcBoxRange(List sortedValues) { + public static Range calcBoxRange(List sortedValues) { if (sortedValues == null || sortedValues.size() == 0) { return null; } @@ -139,7 +142,7 @@ public Range calcBoxRange(List sortedValues) { return Range.closed(minValue, maxValue); } - public Range calcInterquartileRangeApproximation(List sortedValues) { + public static Range calcInterquartileRangeApproximation(List sortedValues) { Range iqr = null; if (sortedValues.size() > 0) { @@ -150,7 +153,7 @@ public Range calcInterquartileRangeApproximation(List so // if iqr == 0 AND max == q3 then recursively try finding a non-zero iqr approximation. if (q1.compareTo(q3) == 0 && max.compareTo(q3) == 0) { // filter out max and try again - iqr = this.calcInterquartileRangeApproximation( + iqr = calcInterquartileRangeApproximation( sortedValues.stream().filter(d -> d.compareTo(max) < 0).collect(Collectors.toList())); } @@ -163,7 +166,7 @@ public Range calcInterquartileRangeApproximation(List so return iqr; } - public BigDecimal calcQ1(List sortedValues) { + public static BigDecimal calcQ1(List sortedValues) { if (sortedValues == null || sortedValues.isEmpty()) { return null; } @@ -172,12 +175,12 @@ public BigDecimal calcQ1(List sortedValues) { return calcMedian(sortedValues, 0, stopIndex); } - public BigDecimal calcMedian(List sortedValues) { + public static BigDecimal calcMedian(List sortedValues) { return (sortedValues == null || sortedValues.isEmpty()) ? null : calcMedian(sortedValues, 0, sortedValues.size() - 1); } - public BigDecimal calcQ3(List sortedValues) { + public static BigDecimal calcQ3(List sortedValues) { if (sortedValues == null || sortedValues.isEmpty()) { return null; } @@ -189,7 +192,7 @@ public BigDecimal calcQ3(List sortedValues) { return calcMedian(sortedValues, startIndex, sortedValues.size() - 1); } - private BigDecimal calcMedian(List sortedValues, int start, int stop) { + private static BigDecimal calcMedian(List sortedValues, int start, int stop) { if (sortedValues == null || sortedValues.isEmpty()) { return null; } @@ -204,24 +207,24 @@ private BigDecimal calcMedian(List sortedValues, int start, int stop } } - public BigDecimal valueCloseToQ1(List sortedValues) { + public static BigDecimal valueCloseToQ1(List sortedValues) { return (sortedValues == null || sortedValues.isEmpty()) ? null : sortedValues.get((int) (sortedValues.size() * 0.25)); } - public BigDecimal valueCloseToQ3(List sortedValues) { + public static BigDecimal valueCloseToQ3(List sortedValues) { return (sortedValues == null || sortedValues.isEmpty()) ? null : sortedValues.get((int) (sortedValues.size() * 0.75)); } - public List filterIntervals(List intervals, BigDecimal lowerOutlier, BigDecimal upperOutlier) { + public static List filterIntervals(List intervals, BigDecimal lowerOutlier, BigDecimal upperOutlier) { // remove values that fall outside the lower and upper outlier limits return intervals.stream() .filter(d -> (lowerOutlier == null || d.compareTo(lowerOutlier) > 0 ) && (upperOutlier == null || d.compareTo(upperOutlier) < 0)) .collect(Collectors.toList()); } - public List initDataBins(List values, + public static List initDataBins(List values, List intervals, BigDecimal lowerOutlier, BigDecimal upperOutlier) { @@ -229,7 +232,7 @@ public List initDataBins(List values, filterIntervals(intervals, lowerOutlier, upperOutlier)); } - public List initDataBins(List values, + public static List initDataBins(List values, List intervals) { List dataBins = initDataBins(intervals); @@ -238,7 +241,7 @@ public List initDataBins(List values, return dataBins; } - public List initDataBins(List intervalValues) { + public static List initDataBins(List intervalValues) { List dataBins = new ArrayList<>(); for (int i = 0; i < intervalValues.size() - 1; i++) { @@ -254,7 +257,7 @@ public List initDataBins(List intervalValues) { return dataBins; } - public List trim(List dataBins) { + public static List trim(List dataBins) { List toRemove = new ArrayList<>(); // find out leading empty bins @@ -285,8 +288,8 @@ public List trim(List dataBins) { return trimmed; } - public void calcCounts(List dataBins, List values) { - Map, DataBin> rangeMap = dataBins.stream().collect(Collectors.toMap(this::calcRange, b -> b)); + public static void calcCounts(List dataBins, List values) { + Map, DataBin> rangeMap = dataBins.stream().collect(Collectors.toMap(DataBinHelper::calcRange, b -> b)); // TODO complexity here is O(n x m), find a better way to do this for (Range range : rangeMap.keySet()) { @@ -300,7 +303,7 @@ public void calcCounts(List dataBins, List values) { } } - public Range calcRange(DataBin dataBin) { + public static Range calcRange(DataBin dataBin) { boolean startInclusive = ">=".equals(dataBin.getSpecialValue()); boolean endInclusive = !"<".equals(dataBin.getSpecialValue()); @@ -312,7 +315,7 @@ public Range calcRange(DataBin dataBin) { return calcRange(dataBin.getStart(), startInclusive, dataBin.getEnd(), endInclusive); } - public Range calcRange(String operator, BigDecimal value) { + public static Range calcRange(String operator, BigDecimal value) { boolean startInclusive = ">=".equals(operator); BigDecimal start = operator.contains(">") ? value : null; boolean endInclusive = !"<".equals(operator); @@ -321,19 +324,19 @@ public Range calcRange(String operator, BigDecimal value) { return calcRange(start, startInclusive, end, endInclusive); } - public boolean isNA(String value) { + public static boolean isNA(String value) { return value.equalsIgnoreCase("NA") || value.equalsIgnoreCase("NAN") || value.equalsIgnoreCase("N/A"); } - public boolean isSmallData(List sortedValues) { + public static boolean isSmallData(List sortedValues) { BigDecimal median = sortedValues.get((int) Math.ceil((sortedValues.size() * (1.0 / 2.0)))); return median.compareTo(new BigDecimal("0.001")) < 0 && median.compareTo(new BigDecimal("-0.001")) > 0 && median.compareTo(new BigDecimal("0")) != 0; } - public String extractOperator(String value) { + public static String extractOperator(String value) { int length = 0; if (value.trim().startsWith(">=") || value.trim().startsWith("<=")) { @@ -345,11 +348,11 @@ public String extractOperator(String value) { return value.trim().substring(0, length); } - public Integer calcExponent(BigDecimal value) { + public static Integer calcExponent(BigDecimal value) { return value.precision() - value.scale() - 1; } - public String stripOperator(String value) { + public static String stripOperator(String value) { int length = 0; if (value.trim().startsWith(">=") || value.trim().startsWith("<=")) { @@ -361,11 +364,11 @@ public String stripOperator(String value) { return value.trim().substring(length); } - public boolean isAgeAttribute(String attributeId) { + public static boolean isAgeAttribute(String attributeId) { return attributeId != null && attributeId.matches("(^AGE$)|(^AGE_.*)|(.*_AGE_.*)|(.*_AGE&)"); } - public Range calcRange(BigDecimal start, boolean startInclusive, BigDecimal end, boolean endInclusive) { + public static Range calcRange(BigDecimal start, boolean startInclusive, BigDecimal end, boolean endInclusive) { // check for invalid filter (no start or end provided) if (start == null && end == null) { return null; @@ -396,19 +399,19 @@ public Range calcRange(BigDecimal start, boolean startInclusive, Big } } - public Set findDistinctValues(DataBin numericalBin, List numericalValues) { + public static Set findDistinctValues(DataBin numericalBin, List numericalValues) { Range range = calcRange(numericalBin); return numericalValues.stream().filter(range::contains).collect(Collectors.toSet()); } - public Set> findDistinctSpecialRanges(DataBin numericalBin, List> rangeValues) { + public static Set> findDistinctSpecialRanges(DataBin numericalBin, List> rangeValues) { Range range = calcRange(numericalBin); return rangeValues.stream().filter(range::encloses).collect(Collectors.toSet()); } - public List convertToDistinctBins( + public static List convertToDistinctBins( List dataBins, List numericalValues, List> rangeValues @@ -416,11 +419,11 @@ public List convertToDistinctBins( List distinctBins = new ArrayList<>(); for (DataBin bin: dataBins) { - Set distinctValues = this.findDistinctValues(bin, numericalValues); - Set> distinctRanges = this.findDistinctSpecialRanges(bin, rangeValues); + Set distinctValues = findDistinctValues(bin, numericalValues); + Set> distinctRanges = findDistinctSpecialRanges(bin, rangeValues); // if the bin contains only one distinct value and no range value then create a distinct bin - if (distinctRanges.size() == 0 && distinctValues.size() == 1 && this.areAllIntegers(distinctValues)) { + if (distinctRanges.size() == 0 && distinctValues.size() == 1 && areAllIntegers(distinctValues)) { BigDecimal distinctValue = distinctValues.iterator().next(); DataBin distinctBin = new DataBin(); @@ -446,7 +449,7 @@ public List convertToDistinctBins( } } - public Boolean areAllDistinctExceptOutliers(List dataBins) { + public static Boolean areAllDistinctExceptOutliers(List dataBins) { return dataBins .stream() .filter(b -> b.getStart() != null && b.getEnd() != null) @@ -455,7 +458,7 @@ public Boolean areAllDistinctExceptOutliers(List dataBins) { .orElse(false); } - public Boolean areAllIntegers(Set uniqueValues) { + public static Boolean areAllIntegers(Set uniqueValues) { return uniqueValues .stream() .map(value -> value.stripTrailingZeros().scale() <= 0) @@ -463,7 +466,7 @@ public Boolean areAllIntegers(Set uniqueValues) { .orElse(false); } - public List generateBins(List sortedNumericalValues, BigDecimal binSize, BigDecimal anchorValue) { + public static List generateBins(List sortedNumericalValues, BigDecimal binSize, BigDecimal anchorValue) { Assert.notNull(sortedNumericalValues, "sortedNumerical values is null!"); Assert.notNull(binSize, "binSize values is null!"); diff --git a/src/main/java/org/cbioportal/web/util/DataBinner.java b/src/main/java/org/cbioportal/web/util/DataBinner.java index 2807f6c1211..85e21f2e69c 100644 --- a/src/main/java/org/cbioportal/web/util/DataBinner.java +++ b/src/main/java/org/cbioportal/web/util/DataBinner.java @@ -20,8 +20,6 @@ public class DataBinner { private static final Integer DEFAULT_DISTINCT_VALUE_THRESHOLD = 10; - @Autowired - private DataBinHelper dataBinHelper; @Autowired private DiscreteDataBinner discreteDataBinner; @Autowired @@ -111,7 +109,7 @@ public List recalcBinCount( dataBin.setCount(0); // calculate range - Range range = dataBinHelper.calcRange(dataBin); + Range range = DataBinHelper.calcRange(dataBin); if (range != null) { for (BigDecimal value : numericalValues) { @@ -209,7 +207,7 @@ public List calculateDataBins( boolean numericalOnly = false; Range range = dataBinFilter.getStart() == null && dataBinFilter.getEnd() == null ? - Range.all() : dataBinHelper.calcRange(dataBinFilter.getStart(), true, dataBinFilter.getEnd(), true); + Range.all() : DataBinHelper.calcRange(dataBinFilter.getStart(), true, dataBinFilter.getEnd(), true); if (range.hasUpperBound()) { clinicalData = filterSmallerThanUpperBound(clinicalData, range.upperEndpoint()); @@ -248,11 +246,11 @@ public List calculateDataBins( } // remove leading and trailing empty bins before adding non numerical ones - dataBins = dataBinHelper.trim(dataBins); + dataBins = DataBinHelper.trim(dataBins); // in some cases every numerical bin actually contains only a single discrete value // convert interval bins to distinct (single value) bins in these cases - dataBins = dataBinHelper.convertToDistinctBins( + dataBins = DataBinHelper.convertToDistinctBins( dataBins, filterNumericalValues(clinicalData), filterSpecialRanges(clinicalData) ); @@ -274,11 +272,11 @@ public List> filterSpecialRanges(List clinicalData) .map(Binnable::getAttrValue) .filter(s -> (s.contains(">") || s.contains("<")) && // ignore any invalid values such as >10PY, <20%, etc. - NumberUtils.isCreatable(dataBinHelper.stripOperator(s))) - .map(v -> dataBinHelper.calcRange( + NumberUtils.isCreatable(DataBinHelper.stripOperator(s))) + .map(v -> DataBinHelper.calcRange( // only use "<" or ">" to make sure that we only generate open ranges - dataBinHelper.extractOperator(v).substring(0, 1), - new BigDecimal(dataBinHelper.stripOperator(v)))) + DataBinHelper.extractOperator(v).substring(0, 1), + new BigDecimal(DataBinHelper.stripOperator(v)))) .collect(Collectors.toList()); } @@ -290,7 +288,7 @@ public List filterNonNumericalValues(List clinicalData) { // filter out numerical values and 'NA's return clinicalData.stream() .map(Binnable::getAttrValue) - .filter(s -> !NumberUtils.isCreatable(dataBinHelper.stripOperator(s)) && !dataBinHelper.isNA(s)) + .filter(s -> !NumberUtils.isCreatable(DataBinHelper.stripOperator(s)) && !DataBinHelper.isNA(s)) .collect(Collectors.toList()); } @@ -375,7 +373,7 @@ public Collection calcNumericalDataBins( List sortedNumericalValues = new ArrayList<>(numericalValues); Collections.sort(sortedNumericalValues); - Range boxRange = dataBinHelper.calcBoxRange(sortedNumericalValues); + Range boxRange = DataBinHelper.calcBoxRange(sortedNumericalValues); // remove initial outliers List withoutOutliers = sortedNumericalValues.stream().filter(isNotOutlier).collect(Collectors.toList()); @@ -396,12 +394,12 @@ public Collection calcNumericalDataBins( customBins = this.adjustCustomBins(customBins, lowerOutlierBin, upperOutlierBin); dataBins = linearDataBinner.calculateDataBins(customBins, numericalValues); } else if (DataBinFilter.BinMethod.GENERATE == binMethod && binsGeneratorConfig != null) { - List bins = this.dataBinHelper.generateBins(sortedNumericalValues, binsGeneratorConfig.getBinSize(), binsGeneratorConfig.getAnchorValue()); + List bins = DataBinHelper.generateBins(sortedNumericalValues, binsGeneratorConfig.getBinSize(), binsGeneratorConfig.getAnchorValue()); dataBins = linearDataBinner.calculateDataBins(bins, numericalValues); } else if (DataBinFilter.BinMethod.MEDIAN == binMethod) { // NOOP - handled later } else if (DataBinFilter.BinMethod.QUARTILE == binMethod) { - List boundaries = this.dataBinHelper.calcQuartileBoundaries(sortedNumericalValues); + List boundaries = DataBinHelper.calcQuartileBoundaries(sortedNumericalValues); dataBins = linearDataBinner.calculateDataBins(boundaries, numericalValues); } else if (boxRange.upperEndpoint().subtract(boxRange.lowerEndpoint()).compareTo(new BigDecimal(1000)) == 1 && (disableLogScale == null || !disableLogScale)) { @@ -410,7 +408,7 @@ public Collection calcNumericalDataBins( withoutOutliers, lowerOutlierBin.getEnd(), upperOutlierBin.getStart()); - } else if (dataBinHelper.isSmallData(sortedNumericalValues)) { + } else if (DataBinHelper.isSmallData(sortedNumericalValues)) { dataBins = scientificSmallDataBinner.calculateDataBins( sortedNumericalValues, withoutOutliers, @@ -422,7 +420,7 @@ public Collection calcNumericalDataBins( boxRange = Range.closed(dataBins.get(0).getStart(), dataBins.get(dataBins.size() - 1).getEnd()); } } else { - Boolean areAllIntegers = this.dataBinHelper.areAllIntegers(uniqueValues); + Boolean areAllIntegers = DataBinHelper.areAllIntegers(uniqueValues); if (areAllIntegers) { boxRange = Range.closed( @@ -448,7 +446,7 @@ public Collection calcNumericalDataBins( // In edge cases all quartile values can be identical (all // values are in the outlier bins). || (DataBinFilter.BinMethod.QUARTILE == binMethod && dataBins.size() == 0)) { - BigDecimal median = this.dataBinHelper.calcMedian(sortedNumericalValues); + BigDecimal median = DataBinHelper.calcMedian(sortedNumericalValues); lowerOutlierBin.setEnd(median); upperOutlierBin.setStart(median); // Covers the situation where there is a single custom boundary (i.e. there are only outlier bins). @@ -546,7 +544,7 @@ public List filterBiggerThanLowerBound(List clinicalData, Bi } public DataBin calcUpperOutlierBin(List clinicalData) { - DataBin dataBin = dataBinHelper.calcUpperOutlierBin( + DataBin dataBin = DataBinHelper.calcUpperOutlierBin( doubleValuesForSpecialOutliers(clinicalData, ">="), doubleValuesForSpecialOutliers(clinicalData, ">")); @@ -557,7 +555,7 @@ public DataBin calcUpperOutlierBin(List clinicalData) { } public DataBin calcLowerOutlierBin(List clinicalData) { - DataBin dataBin = dataBinHelper.calcLowerOutlierBin( + DataBin dataBin = DataBinHelper.calcLowerOutlierBin( doubleValuesForSpecialOutliers(clinicalData, "<="), doubleValuesForSpecialOutliers(clinicalData, "<")); @@ -690,7 +688,7 @@ public Long countNAs(List clinicalData, ClinicalDataType clinicalDataT public Long countNAs(List clinicalData) { return clinicalData == null ? 0 : clinicalData.stream() - .filter(c -> dataBinHelper.isNA(c.getAttrValue())) + .filter(c -> DataBinHelper.isNA(c.getAttrValue())) .count(); } diff --git a/src/main/java/org/cbioportal/web/util/DiscreteDataBinner.java b/src/main/java/org/cbioportal/web/util/DiscreteDataBinner.java index bff1eaf390b..d6eaf334f82 100644 --- a/src/main/java/org/cbioportal/web/util/DiscreteDataBinner.java +++ b/src/main/java/org/cbioportal/web/util/DiscreteDataBinner.java @@ -1,7 +1,6 @@ package org.cbioportal.web.util; import org.cbioportal.model.DataBin; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.math.BigDecimal; @@ -12,14 +11,11 @@ @Component public class DiscreteDataBinner { - @Autowired - private DataBinHelper dataBinHelper; - public List calculateDataBins(List values, Set uniqueValues) { List dataBins = initDataBins(uniqueValues); - dataBinHelper.calcCounts(dataBins, values); + DataBinHelper.calcCounts(dataBins, values); return dataBins; } diff --git a/src/main/java/org/cbioportal/web/util/IdPopulator.java b/src/main/java/org/cbioportal/web/util/IdPopulator.java index bfda0b01e95..e7c02227bdf 100644 --- a/src/main/java/org/cbioportal/web/util/IdPopulator.java +++ b/src/main/java/org/cbioportal/web/util/IdPopulator.java @@ -1,14 +1,12 @@ package org.cbioportal.web.util; import org.cbioportal.model.ClinicalAttribute; -import org.cbioportal.service.AttributeByStudyService; import org.cbioportal.service.PatientService; import org.cbioportal.service.util.ClinicalAttributeUtil; import org.cbioportal.web.parameter.SampleIdentifier; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.ArrayList; import java.util.List; @Component diff --git a/src/main/java/org/cbioportal/web/util/LinearDataBinner.java b/src/main/java/org/cbioportal/web/util/LinearDataBinner.java index eb9a0abf281..34bea85d9e4 100644 --- a/src/main/java/org/cbioportal/web/util/LinearDataBinner.java +++ b/src/main/java/org/cbioportal/web/util/LinearDataBinner.java @@ -2,7 +2,6 @@ import com.google.common.collect.Range; import org.cbioportal.model.DataBin; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.math.BigDecimal; @@ -34,9 +33,6 @@ public class LinearDataBinner { public static final Integer DEFAULT_INTERVAL_COUNT = 20; - @Autowired - private DataBinHelper dataBinHelper; - public List calculateDataBins(boolean areAllIntegers, Range boxRange, List values, @@ -50,7 +46,7 @@ public List calculateDataBins(boolean areAllIntegers, // special case for "AGE" attributes if (attributeId.isPresent() && - dataBinHelper.isAgeAttribute(attributeId.get()) && + DataBinHelper.isAgeAttribute(attributeId.get()) && min.doubleValue() < 18 && boxRange.upperEndpoint().subtract(boxRange.lowerEndpoint()).divide(BigDecimal.valueOf(2)).compareTo(BigDecimal.valueOf(18)) == 1 && dataBins.get(0).getEnd().compareTo(BigDecimal.valueOf(18)) == 1) { @@ -58,7 +54,7 @@ public List calculateDataBins(boolean areAllIntegers, dataBins.get(0).setStart(BigDecimal.valueOf(18)); } - dataBinHelper.calcCounts(dataBins, values); + DataBinHelper.calcCounts(dataBins, values); return dataBins; } @@ -66,7 +62,7 @@ public List calculateDataBins(boolean areAllIntegers, public List calculateDataBins(List customBins, List values) { List dataBins = initDataBins(customBins); - dataBinHelper.calcCounts(dataBins, values); + DataBinHelper.calcCounts(dataBins, values); return dataBins; } diff --git a/src/main/java/org/cbioportal/web/util/LogScaleDataBinner.java b/src/main/java/org/cbioportal/web/util/LogScaleDataBinner.java index 1f6b34d30cf..febeb34ebb8 100644 --- a/src/main/java/org/cbioportal/web/util/LogScaleDataBinner.java +++ b/src/main/java/org/cbioportal/web/util/LogScaleDataBinner.java @@ -2,7 +2,6 @@ import com.google.common.collect.Range; import org.cbioportal.model.DataBin; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.math.BigDecimal; @@ -11,8 +10,6 @@ @Component public class LogScaleDataBinner { - @Autowired - private DataBinHelper dataBinHelper; public List calculateDataBins(Range boxRange, List values, @@ -57,7 +54,7 @@ public List calculateDataBins(Range boxRange, } } - return dataBinHelper.initDataBins(values, intervals); + return DataBinHelper.initDataBins(values, intervals); } public BigDecimal calcIntervalValue(BigDecimal exponent) { diff --git a/src/main/java/org/cbioportal/web/util/ScientificSmallDataBinner.java b/src/main/java/org/cbioportal/web/util/ScientificSmallDataBinner.java index 276ab1bb2ba..f3766164ef8 100644 --- a/src/main/java/org/cbioportal/web/util/ScientificSmallDataBinner.java +++ b/src/main/java/org/cbioportal/web/util/ScientificSmallDataBinner.java @@ -2,7 +2,6 @@ import com.google.common.collect.Range; import org.cbioportal.model.DataBin; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.math.BigDecimal; @@ -14,22 +13,19 @@ @Component public class ScientificSmallDataBinner { - @Autowired - private DataBinHelper dataBinHelper; - public List calculateDataBins(List sortedNumericalValues, List valuesWithoutOutliers, BigDecimal lowerOutlier, BigDecimal upperOutlier) { List exponents = sortedNumericalValues .stream() - .map(d -> BigDecimal.valueOf(dataBinHelper.calcExponent(d))) + .map(d -> BigDecimal.valueOf(DataBinHelper.calcExponent(d))) .filter(d -> d.compareTo(new BigDecimal("0")) != 0) .collect(Collectors.toList()); Collections.sort(exponents); - Range exponentBoxRange = dataBinHelper.calcBoxRange(exponents); + Range exponentBoxRange = DataBinHelper.calcBoxRange(exponents); List intervals = new ArrayList<>(); @@ -72,6 +68,6 @@ public List calculateDataBins(List sortedNumericalValues, } } - return dataBinHelper.initDataBins(valuesWithoutOutliers, intervals, lowerOutlier, upperOutlier); + return DataBinHelper.initDataBins(valuesWithoutOutliers, intervals, lowerOutlier, upperOutlier); } } diff --git a/src/test/java/org/cbioportal/persistence/mybatisclickhouse/MolecularProfileCountTest.java b/src/test/java/org/cbioportal/persistence/mybatisclickhouse/MolecularProfileCountTest.java index 1b5650fadc3..b7a25d3ec0e 100644 --- a/src/test/java/org/cbioportal/persistence/mybatisclickhouse/MolecularProfileCountTest.java +++ b/src/test/java/org/cbioportal/persistence/mybatisclickhouse/MolecularProfileCountTest.java @@ -1,5 +1,6 @@ package org.cbioportal.persistence.mybatisclickhouse; +import org.cbioportal.persistence.helper.StudyViewFilterHelper; import org.cbioportal.persistence.mybatisclickhouse.config.MyBatisConfig; import org.cbioportal.web.parameter.CategorizedClinicalDataCountFilter; @@ -44,8 +45,7 @@ public void getMolecularProfileCounts() { studyViewFilter.setGenomicProfiles(profileGroups); - var molecularProfileCounts = studyViewMapper.getMolecularProfileSampleCounts(studyViewFilter, - CategorizedClinicalDataCountFilter.getBuilder().build(), false, List.of()); + var molecularProfileCounts = studyViewMapper.getMolecularProfileSampleCounts(StudyViewFilterHelper.build(studyViewFilter, null, null)); var size = molecularProfileCounts.stream().filter(gc->gc.getValue().equals("mutations")) .findFirst().get().getCount().intValue(); @@ -63,8 +63,7 @@ public void getMolecularProfileCountsMultipleStudies() { studyViewFilter.setGenomicProfiles(profileGroups); - var molecularProfileCounts = studyViewMapper.getMolecularProfileSampleCounts(studyViewFilter, - CategorizedClinicalDataCountFilter.getBuilder().build(), false, List.of()); + var molecularProfileCounts = studyViewMapper.getMolecularProfileSampleCounts(StudyViewFilterHelper.build(studyViewFilter, null, null)); var size = molecularProfileCounts.stream().filter(gc->gc.getValue().equals("mutations")) .findFirst().get().getCount().intValue(); @@ -82,8 +81,7 @@ public void getMolecularProfileCountsMultipleProfilesUnion() { studyViewFilter.setGenomicProfiles(profileGroups); - var molecularProfileCounts = studyViewMapper.getMolecularProfileSampleCounts(studyViewFilter, - CategorizedClinicalDataCountFilter.getBuilder().build(), false, List.of() ); + var molecularProfileCounts = studyViewMapper.getMolecularProfileSampleCounts(StudyViewFilterHelper.build(studyViewFilter, null, null)); var sizeMutations = molecularProfileCounts.stream().filter(gc->gc.getValue().equals("mutations")) .findFirst().get().getCount().intValue(); @@ -106,8 +104,7 @@ public void getMolecularProfileCountsMultipleProfilesIntersect() { studyViewFilter.setGenomicProfiles(profileGroups); - var molecularProfileCounts = studyViewMapper.getMolecularProfileSampleCounts(studyViewFilter, - CategorizedClinicalDataCountFilter.getBuilder().build(), false, List.of()); + var molecularProfileCounts = studyViewMapper.getMolecularProfileSampleCounts(StudyViewFilterHelper.build(studyViewFilter, null, null)); var sizeMutations = molecularProfileCounts.stream().filter(gc->gc.getValue().equals("mutations")) .findFirst().get().getCount().intValue(); diff --git a/src/test/java/org/cbioportal/web/util/ClinicalDataBinUtilTest.java b/src/test/java/org/cbioportal/web/util/ClinicalDataBinUtilTest.java index 83383756a04..b25def51f5b 100644 --- a/src/test/java/org/cbioportal/web/util/ClinicalDataBinUtilTest.java +++ b/src/test/java/org/cbioportal/web/util/ClinicalDataBinUtilTest.java @@ -12,13 +12,9 @@ import org.cbioportal.service.PatientService; import org.cbioportal.service.impl.CustomDataServiceImpl; import org.cbioportal.service.util.ClinicalAttributeUtil; -import org.cbioportal.service.util.CustomAttributeWithData; -import org.cbioportal.service.util.CustomDataSession; -import org.cbioportal.service.util.CustomDataValue; import org.cbioportal.service.util.SessionServiceRequestHandler; import org.cbioportal.web.parameter.*; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -74,6 +70,7 @@ public class ClinicalDataBinUtilTest { @Spy @InjectMocks private DataBinner dataBinner; + @Spy @InjectMocks private DiscreteDataBinner discreteDataBinner; diff --git a/src/test/java/org/cbioportal/web/util/DataBinnerTest.java b/src/test/java/org/cbioportal/web/util/DataBinnerTest.java index b6fe1f81688..5ed86de169b 100644 --- a/src/test/java/org/cbioportal/web/util/DataBinnerTest.java +++ b/src/test/java/org/cbioportal/web/util/DataBinnerTest.java @@ -31,11 +31,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.mockito.InjectMocks; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; import org.mockito.internal.matchers.apachecommons.ReflectionEquals; -import org.mockito.junit.MockitoJUnitRunner; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest