From b9020e74a0bc163404ca5d036b1ef7dc99ca312c Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Wed, 25 Mar 2026 10:29:07 -0700 Subject: [PATCH 1/2] Minor code cleanup --- .../model/QCMetricConfiguration.java | 21 +++++ .../labkey/targetedms/TargetedMSManager.java | 78 +++++++++---------- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/api-src/org/labkey/api/targetedms/model/QCMetricConfiguration.java b/api-src/org/labkey/api/targetedms/model/QCMetricConfiguration.java index 73d10893e..948521bce 100644 --- a/api-src/org/labkey/api/targetedms/model/QCMetricConfiguration.java +++ b/api-src/org/labkey/api/targetedms/model/QCMetricConfiguration.java @@ -16,10 +16,16 @@ package org.labkey.api.targetedms.model; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.json.JSONObject; public class QCMetricConfiguration implements Comparable { + public enum TimeValueOption + { + First, Last, Min, Max + } + private int _id; private String _name; private String _queryName; @@ -124,6 +130,21 @@ public void setTimeValueOption(String timeValueOption) _timeValueOption = timeValueOption; } + @Nullable + public TimeValueOption getParsedTimeValueOption() + { + if (_timeValueOption == null) + return null; + try + { + return TimeValueOption.valueOf(_timeValueOption); + } + catch (IllegalArgumentException e) + { + return null; + } + } + public Double getTraceValue() { return _traceValue; diff --git a/src/org/labkey/targetedms/TargetedMSManager.java b/src/org/labkey/targetedms/TargetedMSManager.java index c2c228a33..5dd9f57db 100644 --- a/src/org/labkey/targetedms/TargetedMSManager.java +++ b/src/org/labkey/targetedms/TargetedMSManager.java @@ -163,7 +163,7 @@ private TargetedMSManager() * client rendering the overview, all of which need to know the enabled configs. */ private static final Cache> _metricCache = CacheManager.getBlockingCache(1000, TimeUnit.HOURS.toMillis(1), "Enabled QC metric configs", - (c, argument) -> + (_, argument) -> { try { @@ -1048,7 +1048,7 @@ public static TargetedMSRun getRunByFileName(String fileName, Container containe List matches = new TableSelector(TargetedMSManager.getTableInfoRuns(), filter, null).getArrayList(TargetedMSRun.class); if (matches.size() == 1) { - return matches.get(0); + return matches.getFirst(); } return null; } @@ -1084,7 +1084,7 @@ else if(representativeState == RunRepresentativeDataState.Representative_Peptide // for the documents not yet imported. updateSql.append(" AND StatusId = ? "); updateSql.add(SkylineDocImporter.STATUS_SUCCESS); - updateSql.append(" AND Id NOT IN ("+StringUtils.join(representativeRunIds, ",")+")"); + updateSql.append(" AND Id NOT IN (").append(StringUtils.join(representativeRunIds, ",")).append(")"); new SqlExecutor(TargetedMSManager.getSchema()).execute(updateSql); } @@ -1125,7 +1125,7 @@ private static List getProteinRepresentativeRunIds(Container container, in reprRunIdSql.append(TargetedMSManager.getTableInfoRuns(), "runs"); String states = StringUtils.join(stateArray, ','); - reprRunIdSql.append(" WHERE pepgrp.RepresentativeDataState IN (" + states + ")"); + reprRunIdSql.append(" WHERE pepgrp.RepresentativeDataState IN (").append(states).append(")"); reprRunIdSql.append(" AND runs.Container = ?"); reprRunIdSql.add(container); reprRunIdSql.append(" AND runs.Id = pepgrp.RunId"); @@ -1160,7 +1160,7 @@ private static List getPeptideRepresentativeRunIds(Container container, in String states = StringUtils.join(stateArray, ','); - reprRunIdSql.append(" WHERE gp.RepresentativeDataState IN (" + states + ")"); + reprRunIdSql.append(" WHERE gp.RepresentativeDataState IN (").append(states).append(")"); reprRunIdSql.append(" AND gp.GeneralMoleculeId = gm.Id"); reprRunIdSql.append(" AND gm.PeptideGroupId = pepgrp.Id"); reprRunIdSql.append(" AND Container = ?"); @@ -1918,19 +1918,15 @@ private static void purgeDeletedRuns() // Delete from all list-related tables deleteListDependent(); + // Get a list of runs to be deleted so that we can flush them from the cache + SQLFragment sql = new SQLFragment("SELECT Id FROM " + getTableInfoRuns() + " WHERE Deleted = ?", true); + List deletedRunIds = new SqlSelector(getSchema(), sql).getArrayList(Long.class); + // Delete from runs execute("DELETE FROM " + getTableInfoRuns() + " WHERE Deleted = ?", true); // Remove any cached results for the deleted runs - removeCachedResults(); - } - - private static void removeCachedResults() - { - // Get a list of deleted runs - SQLFragment sql = new SQLFragment("SELECT Id FROM " + getTableInfoRuns() + " WHERE Deleted = ?", true); - List deletedRunIds = new SqlSelector(getSchema(), sql).getArrayList(Long.class); - if(!deletedRunIds.isEmpty()) + if (!deletedRunIds.isEmpty()) { ModificationManager.removeRunCachedResults(deletedRunIds); PeptideManager.removeRunCachedResults(deletedRunIds); @@ -2155,17 +2151,20 @@ public static void renameRun(long runId, String newDescription, User user) throw if (newDescription == null || newDescription.isEmpty()) return; - new SqlExecutor(getSchema()).execute("UPDATE " + getTableInfoRuns() + " SET Description=? WHERE Id = ?", - newDescription, runId); - TargetedMSRun run = getRun(runId); - if (run != null) + try (DbScope.Transaction _ = getSchema().getScope().ensureTransaction()) { - // Keep the experiment run wrapper in sync - ExpRun expRun = ExperimentService.get().getExpRun(run.getExperimentRunLSID()); - if (expRun != null) + new SqlExecutor(getSchema()).execute("UPDATE " + getTableInfoRuns() + " SET Description=? WHERE Id = ?", + newDescription, runId); + TargetedMSRun run = getRun(runId); + if (run != null) { - expRun.setName(newDescription); - expRun.save(user); + // Keep the experiment run wrapper in sync + ExpRun expRun = ExperimentService.get().getExpRun(run.getExperimentRunLSID()); + if (expRun != null) + { + expRun.setName(newDescription); + expRun.save(user); + } } } } @@ -2199,7 +2198,7 @@ public static SampleFile getSampleFile(long id, Container container) { throw new IllegalStateException("More than one SampleFile for Id " + id); } - return matches.isEmpty() ? null : matches.get(0); + return matches.isEmpty() ? null : matches.getFirst(); } public static List getSampleFiles(Container container, @Nullable SQLFragment whereClause) @@ -2813,13 +2812,6 @@ public static TransitionSettings.FullScanSettings getTransitionFullScanSettings( .getObject(TransitionSettings.FullScanSettings.class); } - public static TransitionSettings.Predictor getReplicatePredictor(long predictorId) - { - return new TableSelector(TargetedMSManager.getTableInfoTransitionFullScanSettings(), - new SimpleFilter(FieldKey.fromParts("Id"), predictorId), null) - .getObject(TransitionSettings.Predictor.class); - } - private static List getPredictorsToDelete() { SQLFragment sql = new SQLFragment("Select Id FROM " + getTableInfoPredictor() + " WHERE " + @@ -2871,12 +2863,12 @@ public static List calculateTraceMetricValues(List minTimeValue) @@ -2891,7 +2883,7 @@ else if (minTimeValue == null) break; } } - else if (timeValueOption != null && timeValueOption.equals("Last")) + else if (timeValueOption == QCMetricConfiguration.TimeValueOption.Last) { // last value before the maxTimeValue if (maxTimeValue != null && times[i] < maxTimeValue) @@ -2904,7 +2896,7 @@ else if (maxTimeValue == null) valuesToStore.put(sampleFileChromInfo, values[i]); } } - else if (timeValueOption != null && timeValueOption.equals("Min")) + else if (timeValueOption == QCMetricConfiguration.TimeValueOption.Min) { // minValue between minTimeValue and maxTimeValue if (minTimeValue != null && maxTimeValue != null && times[i] >= minTimeValue && times[i] <= maxTimeValue) @@ -2929,9 +2921,8 @@ else if (minTimeValue == null && maxTimeValue == null && values[i] < minValue) { minValue = values[i]; } - valuesToStore.put(sampleFileChromInfo, minValue); } - else if (timeValueOption != null && timeValueOption.equals("Max")) + else if (timeValueOption == QCMetricConfiguration.TimeValueOption.Max) { // maxValue between minTimeValue and maxTimeValue if (minTimeValue != null && maxTimeValue != null && times[i] >= minTimeValue && times[i] <= maxTimeValue) @@ -2956,7 +2947,6 @@ else if (minTimeValue == null && maxTimeValue == null && values[i] > maxValue) { maxValue = values[i]; } - valuesToStore.put(sampleFileChromInfo, maxValue); } else if (traceValue != null && values[i] >= traceValue) @@ -2965,6 +2955,16 @@ else if (traceValue != null && values[i] >= traceValue) break; } } + + // Store Min/Max only if at least one data point matched the time filter + if (timeValueOption == QCMetricConfiguration.TimeValueOption.Min && minValue != Float.MAX_VALUE) + { + valuesToStore.put(sampleFileChromInfo, minValue); + } + else if (timeValueOption == QCMetricConfiguration.TimeValueOption.Max && maxValue != Float.MIN_VALUE) + { + valuesToStore.put(sampleFileChromInfo, maxValue); + } } } From fbaa1c4b622ae1523bec2452ecd668104462757e Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Thu, 26 Mar 2026 13:53:36 -0700 Subject: [PATCH 2/2] Followup fixes --- src/org/labkey/targetedms/TargetedMSManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/org/labkey/targetedms/TargetedMSManager.java b/src/org/labkey/targetedms/TargetedMSManager.java index 5dd9f57db..e023dd1b3 100644 --- a/src/org/labkey/targetedms/TargetedMSManager.java +++ b/src/org/labkey/targetedms/TargetedMSManager.java @@ -2151,7 +2151,7 @@ public static void renameRun(long runId, String newDescription, User user) throw if (newDescription == null || newDescription.isEmpty()) return; - try (DbScope.Transaction _ = getSchema().getScope().ensureTransaction()) + try (DbScope.Transaction t = getSchema().getScope().ensureTransaction()) { new SqlExecutor(getSchema()).execute("UPDATE " + getTableInfoRuns() + " SET Description=? WHERE Id = ?", newDescription, runId); @@ -2166,6 +2166,7 @@ public static void renameRun(long runId, String newDescription, User user) throw expRun.save(user); } } + t.commit(); } } @@ -2865,7 +2866,7 @@ public static List calculateTraceMetricValues(List= traceValue) { valuesToStore.put(sampleFileChromInfo, minValue); } - else if (timeValueOption == QCMetricConfiguration.TimeValueOption.Max && maxValue != Float.MIN_VALUE) + else if (timeValueOption == QCMetricConfiguration.TimeValueOption.Max && maxValue != -Float.MAX_VALUE) { valuesToStore.put(sampleFileChromInfo, maxValue); }