@@ -602,6 +602,11 @@ public static TableInfo getTableInfoQCMetricCache()
602602 return getSchema ().getTable (TargetedMSSchema .TABLE_QC_METRIC_CACHE );
603603 }
604604
605+ public static TableInfo getTableInfoPTMPercentsGroupedPrepivotCache ()
606+ {
607+ return getSchema ().getTable (TargetedMSSchema .TABLE_PTM_PERCENTS_GROUPED_PREPIVOT_CACHE );
608+ }
609+
605610 public static TableInfo getTableInfoSkylineAuditLogEntry ()
606611 {
607612 return getSchema ().getTable (TargetedMSSchema .TABLE_SKYLINE_AUDITLOG_ENTRY );
@@ -1029,6 +1034,12 @@ public static TargetedMSRun[] getRunsInContainer(Container container)
10291034 container .getId (), SkylineDocImporter .STATUS_SUCCESS , Boolean .FALSE );
10301035 }
10311036
1037+ public static TargetedMSRun [] getAllNonDeletedRuns ()
1038+ {
1039+ return getRuns ("StatusId=? AND deleted=?" ,
1040+ SkylineDocImporter .STATUS_SUCCESS , Boolean .FALSE );
1041+ }
1042+
10321043 @ Nullable
10331044 public static TargetedMSRun getRunByFileName (String fileName , Container container )
10341045 {
@@ -1762,6 +1773,7 @@ private static SQLFragment getTempChromInfoIdsDependentDeleteSql(TableInfo fromT
17621773 /** Actually delete runs that have been marked as deleted from the database */
17631774 private static void purgeDeletedRuns ()
17641775 {
1776+ deleteRunDependent (getTableInfoPTMPercentsGroupedPrepivotCache ());
17651777 // Delete from FoldChange
17661778 deleteRunDependent (getTableInfoFoldChange ());
17671779 // Delete from CalibrationCurve
@@ -2732,6 +2744,63 @@ public static void updateModifiedAreaProportions(@Nullable Logger log, @NotNull
27322744 executor .execute ("DROP TABLE " + areasTableName );
27332745 }
27342746
2747+ /**
2748+ * Pre-compute PTMPercentsGroupedPrepivot results during import and store in PTMPercentsCache.
2749+ * Only populates cache for ExperimentMAM folders.
2750+ */
2751+ public static void populatePTMPercentsGroupedPrepivotCache (@ NotNull TargetedMSRun run , @ NotNull User user , @ NotNull Container container )
2752+ {
2753+ // Delete any existing cache rows for this run
2754+ new SqlExecutor (getSchema ()).execute (
2755+ new SQLFragment ("DELETE FROM " ).append (getTableInfoPTMPercentsGroupedPrepivotCache ()).append (" WHERE RunId = ?" ).add (run .getId ()));
2756+
2757+ // Only populate cache for ExperimentMAM folders
2758+ if (getFolderType (container ) != TargetedMSService .FolderType .ExperimentMAM )
2759+ {
2760+ return ;
2761+ }
2762+
2763+ _log .info ("Populating PTMPercentsGroupedPrepivotCache for run " + run .getId ());
2764+
2765+ String labkeySql = "SELECT\n " +
2766+ " Modification,\n " +
2767+ " TotalPercentModified,\n " +
2768+ " PercentModified,\n " +
2769+ " MaxPercentModified,\n " +
2770+ " ModificationCount,\n " +
2771+ " Id,\n " +
2772+ " PeptideModifiedSequence,\n " +
2773+ " Sequence,\n " +
2774+ " PreviousAA,\n " +
2775+ " NextAA,\n " +
2776+ " SampleFileId,\n " +
2777+ " ReplicateName,\n " +
2778+ " AminoAcid,\n " +
2779+ " SiteLocation,\n " +
2780+ " Location,\n " +
2781+ " PeptideGroupId\n " +
2782+ "FROM PTMPercentsGroupedPrepivot\n " +
2783+ "WHERE PeptideGroupId.RunId = " + run .getId ();
2784+
2785+ UserSchema schema = QueryService .get ().getUserSchema (user , container , TargetedMSSchema .SCHEMA_KEY );
2786+ TableInfo tableInfo = QueryService .get ().createTable (schema , labkeySql , null , true );
2787+
2788+ SQLFragment insertSql = new SQLFragment ();
2789+ insertSql .append ("INSERT INTO " ).append (getTableInfoPTMPercentsGroupedPrepivotCache ());
2790+ insertSql .append (" (Container, RunId, Modification, TotalPercentModified, PercentModified, MaxPercentModified," );
2791+ insertSql .append (" ModificationCount, Id, PeptideModifiedSequence, Sequence," );
2792+ insertSql .append (" PreviousAA, NextAA, SampleFileId, ReplicateName, AminoAcid, SiteLocation, Location, PeptideGroupId)" );
2793+ insertSql .append (" SELECT ?, ?, lk.Modification, lk.TotalPercentModified, lk.PercentModified, lk.MaxPercentModified," );
2794+ insertSql .append (" lk.ModificationCount, lk.Id, lk.PeptideModifiedSequence, lk.Sequence," );
2795+ insertSql .append (" lk.PreviousAA, lk.NextAA, lk.SampleFileId, lk.ReplicateName, lk.AminoAcid, lk.SiteLocation, lk.Location, lk.PeptideGroupId" );
2796+ insertSql .append (" FROM " ).append (tableInfo , "lk" );
2797+ insertSql .add (container .getEntityId ());
2798+ insertSql .add (run .getId ());
2799+ new SqlExecutor (getSchema ()).execute (insertSql );
2800+
2801+ _log .info ("Finished populating PTMPercentsGroupedPrepivotCache for run " + run .getId ());
2802+ }
2803+
27352804 /**
27362805 * Returns the Transition Full Scan settings for the given run. This may be null if the settings were not included
27372806 * in the Skyline document.
0 commit comments