Skip to content

Commit 3f84c9a

Browse files
committed
When an alignment is deleted, but not the whole analysis, retain quality metrics
1 parent 83e54ca commit 3f84c9a

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/SequenceAnalysisManager.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public Collection<Integer> deleteOutputFiles(List<Integer> outputFileIds, User u
287287
for (SequenceOutputFile so : files)
288288
{
289289
ExpData d = so.getExpData();
290-
if (d != null && d.getFile() != null && d.getFile().exists())
290+
if (d != null && d.getFile() != null)
291291
{
292292
// account for possibility that another sequence output is using this file. this would probably be from an error, like a pipeline resume/double import, but even in this case we shouldnt delete it
293293
// also check based on filepath
@@ -309,7 +309,9 @@ public Collection<Integer> deleteOutputFiles(List<Integer> outputFileIds, User u
309309
}
310310
else if (doDelete)
311311
{
312-
d.getFile().delete();
312+
if (d.getFile().exists())
313+
d.getFile().delete();
314+
313315
expDataDeleted.add(d.getRowId());
314316
}
315317
}
@@ -346,6 +348,34 @@ else if (doDelete)
346348
//also look for orphan quality metrics:
347349
if (!expDataDeleted.isEmpty())
348350
{
351+
// If the BAM was deleted by the analysis was not, rather than discard all the metrics, set dataId to NULL and keep them attached to the analysis:
352+
if (!bamsDeleted.isEmpty())
353+
{
354+
List<Map<String, Object>> rowsToUpdate = new ArrayList<>();
355+
List<Map<String, Object>> oldKeys = new ArrayList<>();
356+
new TableSelector(us.getTable(SequenceAnalysisSchema.TABLE_QUALITY_METRICS), PageFlowUtil.set("rowId", "analysis_id", "container"), new SimpleFilter(FieldKey.fromString("dataId"), bamsDeleted, CompareType.IN), null).forEachResults(rs -> {
357+
// The intent of this is to recover rows from any situation where a BAM is deleted but the analysis is not
358+
if (rs.getObject(FieldKey.fromString("analysis_id")) != null && !additionalAnalysisIds.contains(rs.getInt(FieldKey.fromString("analysis_id"))))
359+
{
360+
Map<String, Object> toUpdate = new CaseInsensitiveHashMap<>();
361+
toUpdate.put("rowId", rs.getInt(FieldKey.fromString("rowid")));
362+
toUpdate.put("dataid", null);
363+
toUpdate.put("container", rs.getString(FieldKey.fromString("container")));
364+
rowsToUpdate.add(toUpdate);
365+
366+
Map<String, Object> toUpdateKey = new CaseInsensitiveHashMap<>();
367+
toUpdateKey.put("rowId", rs.getInt(FieldKey.fromString("rowid")));
368+
oldKeys.add(toUpdateKey);
369+
}
370+
});
371+
372+
if (!rowsToUpdate.isEmpty())
373+
{
374+
_log.info("quality metric rows attached to BAMs that will not be deleted: " + rowsToUpdate.size());
375+
us.getTable(SequenceAnalysisSchema.TABLE_QUALITY_METRICS).getUpdateService().updateRows(user, container, rowsToUpdate, oldKeys, null, new HashMap<>());
376+
}
377+
}
378+
349379
List<Integer> metricRowIds = new TableSelector(us.getTable(SequenceAnalysisSchema.TABLE_QUALITY_METRICS), PageFlowUtil.set("rowId"), new SimpleFilter(FieldKey.fromString("dataId"), expDataDeleted, CompareType.IN), null).getArrayList(Integer.class);
350380
if (!metricRowIds.isEmpty())
351381
{

0 commit comments

Comments
 (0)