forked from BimberLab/DiscvrLabKeyModules
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrphanFilePipelineJob.java
More file actions
650 lines (563 loc) · 29.6 KB
/
OrphanFilePipelineJob.java
File metadata and controls
650 lines (563 loc) · 29.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
package org.labkey.sequenceanalysis.pipeline;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.labkey.api.data.CompareType;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerManager;
import org.labkey.api.data.Selector;
import org.labkey.api.data.SimpleFilter;
import org.labkey.api.data.TableInfo;
import org.labkey.api.data.TableSelector;
import org.labkey.api.exp.api.ExpData;
import org.labkey.api.exp.api.ExperimentService;
import org.labkey.api.files.FileUrls;
import org.labkey.api.pipeline.AbstractTaskFactory;
import org.labkey.api.pipeline.AbstractTaskFactorySettings;
import org.labkey.api.pipeline.CancelledException;
import org.labkey.api.pipeline.PipeRoot;
import org.labkey.api.pipeline.PipelineJob;
import org.labkey.api.pipeline.PipelineJobException;
import org.labkey.api.pipeline.PipelineJobService;
import org.labkey.api.pipeline.PipelineService;
import org.labkey.api.pipeline.PipelineStatusFile;
import org.labkey.api.pipeline.RecordedActionSet;
import org.labkey.api.pipeline.TaskId;
import org.labkey.api.pipeline.TaskPipeline;
import org.labkey.api.query.FieldKey;
import org.labkey.api.query.QueryService;
import org.labkey.api.query.UserSchema;
import org.labkey.api.security.User;
import org.labkey.api.util.FileType;
import org.labkey.api.util.FileUtil;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.view.ActionURL;
import org.labkey.api.view.ViewBackgroundInfo;
import org.labkey.api.writer.PrintWriters;
import org.labkey.sequenceanalysis.SequenceAnalysisSchema;
import org.labkey.sequenceanalysis.util.SequenceUtil;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import static org.labkey.sequenceanalysis.pipeline.SequenceTaskHelper.SHARED_SUBFOLDER_NAME;
public class OrphanFilePipelineJob extends PipelineJob
{
// Default constructor for serialization
protected OrphanFilePipelineJob()
{
}
public OrphanFilePipelineJob(Container c, User user, ActionURL url, PipeRoot pipeRoot)
{
super(OrphanFilePipelineProvider.NAME, new ViewBackgroundInfo(c, user, url), pipeRoot);
File subdir = new File(pipeRoot.getRootPath(), "orphanSequenceFiles");
if (!subdir.exists())
{
subdir.mkdirs();
}
setLogFile(new File(subdir, FileUtil.makeFileNameWithTimestamp("orphanFilesPipeline", "log")));
}
@Override
public ActionURL getStatusHref()
{
return PageFlowUtil.urlProvider(FileUrls.class).urlBegin(getContainer());
}
@Override
public String getDescription()
{
return "Find Orphan Sequence Files";
}
@Override
public TaskPipeline<?> getTaskPipeline()
{
return PipelineJobService.get().getTaskPipeline(new TaskId(OrphanFilePipelineJob.class));
}
public static class Task extends PipelineJob.Task<Task.Factory>
{
protected Task(Factory factory, PipelineJob job)
{
super(factory, job);
}
public static class Factory extends AbstractTaskFactory<AbstractTaskFactorySettings, Factory>
{
public Factory()
{
super(Task.class);
}
@Override
public List<FileType> getInputTypes()
{
return Collections.emptyList();
}
@Override
public String getStatusName()
{
return PipelineJob.TaskStatus.running.toString();
}
@Override
public List<String> getProtocolActionNames()
{
return List.of("Find Orphan Sequence Files");
}
@Override
public PipelineJob.Task<?> createTask(PipelineJob job)
{
return new Task(this, job);
}
@Override
public boolean isJobComplete(PipelineJob job)
{
return false;
}
}
@Override
public @NotNull RecordedActionSet run() throws PipelineJobException
{
getJob().getLogger().info("## The following sections list any files or pipeline jobs that appear to be orphans, not connected to any imported readsets or sequence outputs:");
Set<File> orphanFiles = new HashSet<>();
Set<File> orphanIndexes = new HashSet<>();
Set<File> probableDeletes = new HashSet<>();
Set<PipelineStatusFile> orphanJobs = new HashSet<>();
List<String> messages = new ArrayList<>();
Set<File> knownJobPaths = Collections.unmodifiableSet(getKnownSequenceJobPaths(getJob().getContainer(), getJob().getUser(), messages));
//find known ExpDatas from this container, across all workbooks
Set<Integer> knownExpDatas = new HashSet<>();
Container parent = getJob().getContainer().isWorkbook() ? getJob().getContainer().getParent() : getJob().getContainer();
UserSchema us = QueryService.get().getUserSchema(getJob().getUser(), parent, SequenceAnalysisSchema.SCHEMA_NAME);
knownExpDatas.addAll(new TableSelector(us.getTable(SequenceAnalysisSchema.TABLE_READ_DATA, null), PageFlowUtil.set("fileid1"),null, null).getArrayList(Integer.class));
knownExpDatas.addAll(new TableSelector(us.getTable(SequenceAnalysisSchema.TABLE_READ_DATA, null), PageFlowUtil.set("fileid2"),null, null).getArrayList(Integer.class));
knownExpDatas.addAll(new TableSelector(us.getTable(SequenceAnalysisSchema.TABLE_ANALYSES, null), PageFlowUtil.set("alignmentfile"),null, null).getArrayList(Integer.class));
knownExpDatas.addAll(new TableSelector(us.getTable(SequenceAnalysisSchema.TABLE_OUTPUTFILES, null), PageFlowUtil.set("dataId"),null, null).getArrayList(Integer.class));
knownExpDatas.remove(null);
knownExpDatas = Collections.unmodifiableSet(knownExpDatas);
//messages.add("## total registered sequence ExpData: " + knownExpDatas.size());
// Build map of URL/ExpData for all data, to cover cross-container files
Map<URI, Set<Integer>> knownDataMap = new HashMap<>();
for (Integer d : knownExpDatas)
{
ExpData ed = ExperimentService.get().getExpData(d);
if (ed != null)
{
if (!knownDataMap.containsKey(ed.getDataFileURI()))
{
knownDataMap.put(ed.getDataFileURI(), new HashSet<>());
}
knownDataMap.get(ed.getDataFileURI()).add(d);
}
}
getOrphanFilesForContainer(getJob().getContainer(), getJob().getUser(), orphanFiles, orphanIndexes, orphanJobs, messages, probableDeletes, knownJobPaths, knownExpDatas, knownDataMap);
probableDeletes.addAll(orphanIndexes);
if (!orphanFiles.isEmpty())
{
StringBuilder sb = new StringBuilder();
orphanFiles.forEach(f -> sb.append("\n").append(f.getPath()));
getJob().getLogger().info("## The following sequence files are not referenced by readsets, analyses or output files:" + sb);
}
if (!orphanIndexes.isEmpty())
{
StringBuilder sb = new StringBuilder();
orphanIndexes.forEach(f -> sb.append("\n").append(f.getPath()));
getJob().getLogger().info("## The following index files appear to be orphans:" + sb);
}
if (!orphanJobs.isEmpty())
{
getJob().getLogger().info("## There are {} sequence jobs are not referenced by readsets, analyses or output files.", orphanJobs.size());
getJob().getLogger().info("## The best action would be to view the pipeline job list, 'Sequence Jobs' view, and filter for jobs without sequence outputs. Deleting any unwanted jobs through the UI should also delete files.");
}
if (!messages.isEmpty())
{
getJob().getLogger().info("## The following messages were generated:");
getJob().getLogger().info(StringUtils.join(messages, "\n"));
}
if (!probableDeletes.isEmpty())
{
StringBuilder sb = new StringBuilder();
File output = new File(getJob().getLogFile().getParentFile(), "toRemove.sh");
try (PrintWriter writer = PrintWriters.getPrintWriter(output))
{
writer.println("#!/bin/bash");
writer.println("");
writer.println("set -e");
writer.println("set -x");
writer.println("");
probableDeletes.forEach(f -> writer.println("rm -Rf '" + f.getPath() + "'"));
}
catch (IOException e)
{
throw new PipelineJobException(e);
}
probableDeletes.forEach(f -> sb.append("\n").append(f.getPath()));
getJob().getLogger().info("## The following files can almost certainly be deleted; however, please exercise caution. Note: the file toRemove.sh has been written and can be executed to remove these:" + sb);
}
return new RecordedActionSet();
}
private static final Set<String> pipelineDirs = PageFlowUtil.set(ReadsetImportJob.FOLDER_NAME, ReadsetImportJob.FOLDER_NAME + "Pipeline", AlignmentAnalysisJob.FOLDER_NAME, AlignmentAnalysisJob.FOLDER_NAME + "Pipeline", "sequenceOutputs", SequenceOutputHandlerJob.FOLDER_NAME + "Pipeline", "illuminaImport", "analyzeAlignment");
private static final Set<String> skippedDirs = PageFlowUtil.set(".sequences", ".jbrowse");
private Set<File> getKnownSequenceJobPaths(Container c, User u, Collection<String> messages)
{
c = c.isWorkbook() ? c.getParent() : c;
//Note: these can cut across workbooks, so search using the parent container
Set<Integer> knownPipelineJobs = new HashSet<>();
UserSchema us = QueryService.get().getUserSchema(u, c, SequenceAnalysisSchema.SCHEMA_NAME);
TableInfo rd = us.getTable(SequenceAnalysisSchema.TABLE_READ_DATA, null);
knownPipelineJobs.addAll(new TableSelector(rd, new LinkedHashSet<>(QueryService.get().getColumns(rd, PageFlowUtil.set(FieldKey.fromString("runId/jobId"))).values()), new SimpleFilter(FieldKey.fromString("runId/jobId"), null, CompareType.NONBLANK), null).getArrayList(Integer.class));
TableInfo rs = us.getTable(SequenceAnalysisSchema.TABLE_READSETS, null);
knownPipelineJobs.addAll(new TableSelector(rs, new LinkedHashSet<>(QueryService.get().getColumns(rs, PageFlowUtil.set(FieldKey.fromString("runId/jobId"))).values()), new SimpleFilter(FieldKey.fromString("runId/jobId"), null, CompareType.NONBLANK), null).getArrayList(Integer.class));
TableInfo a = us.getTable(SequenceAnalysisSchema.TABLE_ANALYSES, null);
knownPipelineJobs.addAll(new TableSelector(a, new LinkedHashSet<>(QueryService.get().getColumns(a, PageFlowUtil.set(FieldKey.fromString("runId/jobId"))).values()), new SimpleFilter(FieldKey.fromString("runId/jobId"), null, CompareType.NONBLANK), null).getArrayList(Integer.class));
TableInfo of = us.getTable(SequenceAnalysisSchema.TABLE_OUTPUTFILES, null);
knownPipelineJobs.addAll(new TableSelector(of, new LinkedHashSet<>(QueryService.get().getColumns(of, PageFlowUtil.set(FieldKey.fromString("runId/jobId"))).values()), new SimpleFilter(FieldKey.fromString("runId/jobId"), null, CompareType.NONBLANK), null).getArrayList(Integer.class));
knownPipelineJobs.addAll(new TableSelector(SequenceAnalysisSchema.getTable(SequenceAnalysisSchema.TABLE_REF_NT_SEQUENCES), PageFlowUtil.set("jobId"), new SimpleFilter(FieldKey.fromString("jobId"), null, CompareType.NONBLANK), null).getArrayList(Integer.class));
knownPipelineJobs = Collections.unmodifiableSet(knownPipelineJobs);
//messages.add("## total expected pipeline job folders: " + knownPipelineJobs.size());
TableSelector jobTs = new TableSelector(PipelineService.get().getJobsTable(u, c), PageFlowUtil.set("FilePath"), new SimpleFilter(FieldKey.fromString("RowId"), knownPipelineJobs, CompareType.IN), null);
Set<File> knownJobPaths = new HashSet<>();
for (String filePath : jobTs.getArrayList(String.class))
{
File f = new File(filePath).getParentFile();
if (!f.exists())
{
messages.add("## unable to find expected pipeline job folder: " + f.getPath());
}
else
{
knownJobPaths.add(f);
}
}
//messages.add("## total job paths: " + knownJobPaths.size());
return knownJobPaths;
}
private Map<URI, Set<Integer>> getDataMapForContainer(Container c, Map<URI, Set<Integer>> knownExpDataMap)
{
SimpleFilter dataFilter = new SimpleFilter(FieldKey.fromString("container"), c.getId());
TableInfo dataTable = ExperimentService.get().getTinfoData();
TableSelector ts = new TableSelector(dataTable, PageFlowUtil.set("RowId", "DataFileUrl"), dataFilter, null);
final Map<URI, Set<Integer>> dataMap = new HashMap<>();
ts.forEach(new Selector.ForEachBlock<>()
{
@Override
public void exec(ResultSet rs) throws SQLException
{
if (rs.getString("DataFileUrl") == null)
{
return;
}
try
{
URI uri = new URI(rs.getString("DataFileUrl"));
if (!dataMap.containsKey(uri))
{
dataMap.put(uri, new HashSet<>());
}
dataMap.get(uri).add(rs.getInt("RowId"));
}
catch (URISyntaxException e)
{
getJob().getLogger().error(e.getMessage(), e);
}
}
});
//messages.add("## total ExpData paths: " + dataMap.size());
// append additional datas:
for (URI u : knownExpDataMap.keySet())
{
if (!dataMap.containsKey(u))
{
dataMap.put(u, new HashSet<>());
}
dataMap.get(u).addAll(knownExpDataMap.get(u));
}
return dataMap;
}
public void getOrphanFilesForContainer(Container c, User u, Set<File> orphanFiles, Set<File> orphanIndexes, Set<PipelineStatusFile> orphanJobs, List<String> messages, Set<File> probableDeletes, Set<File> knownSequenceJobPaths, Set<Integer> knownExpDatas, Map<URI, Set<Integer>> knownExpDataMap)
{
PipeRoot root = PipelineService.get().getPipelineRootSetting(c);
if (root == null)
{
return;
}
getJob().updateStatusForTask();
if (getJob().isCancelled())
{
throw new CancelledException();
}
messages.add("## processing container: " + c.getPath());
Map<URI, Set<Integer>> dataMap = getDataMapForContainer(c, knownExpDataMap);
Container parent = c.isWorkbook() ? c.getParent() : c;
TableInfo jobsTableParent = PipelineService.get().getJobsTable(u, parent);
Set<File> unexpectedPipelineDirs = new HashSet<>();
for (String dirName : pipelineDirs)
{
File dir = new File(root.getRootPath(), dirName);
if (dir.exists())
{
for (File subdir : dir.listFiles())
{
if (!subdir.isDirectory())
{
continue;
}
boolean isOrphanPipelineDir = isOrphanPipelineDir(jobsTableParent, subdir, c, knownExpDatas, knownSequenceJobPaths, orphanJobs, messages);
if (!isOrphanPipelineDir)
{
if (!knownSequenceJobPaths.contains(subdir))
{
probableDeletes.add(subdir);
unexpectedPipelineDirs.add(subdir);
}
File sharedDir = new File(subdir, SHARED_SUBFOLDER_NAME);
if (sharedDir.exists())
{
long size = FileUtils.sizeOfDirectory(sharedDir);
if (size > 1e6)
{
getJob().getLogger().warn("Large Shared folder: " + sharedDir.getPath());
}
}
getOrphanFilesForDirectory(knownExpDatas, dataMap, subdir, orphanFiles, orphanIndexes);
}
}
}
}
// any files remaining in knownJobPaths indicates that we didnt find registered sequence data. this could be a job
// that either failed or for whatever reason is no longer important
if (!unexpectedPipelineDirs.isEmpty())
{
messages.add("## The following directories match existing pipeline jobs, but do not contain registered data for this container:");
for (File f : unexpectedPipelineDirs)
{
long size = FileUtils.sizeOfDirectory(f);
//ignore if less than 1mb
if (size > 1e6)
{
messages.add("## size: " + FileUtils.byteCountToDisplaySize(size));
messages.add(f.getPath());
}
}
}
File deletedDir = new File(root.getRootPath().getParentFile(), ".deleted");
if (deletedDir.exists())
{
getJob().getLogger().warn("WARNING: .deleted dir found: " + deletedDir.getPath());
}
File assayData = new File(root.getRootPath(), "assaydata");
if (assayData.exists())
{
File[] bigFiles = assayData.listFiles(new FileFilter()
{
@Override
public boolean accept(File pathname)
{
return (pathname.length() >= 5e3);
}
});
if (bigFiles != null && bigFiles.length > 0)
{
messages.add("## large files in assaydata, might be unnecessary:");
for (File f : bigFiles)
{
messages.add(f.getPath());
}
}
File archive = new File(assayData, "archive");
if (archive.exists())
{
File[] files = archive.listFiles();
if (files != null && files.length > 0)
{
messages.add("## the following files are in assaydata/archive, and were probably automatically moved here after delete. they might be unnecessary:");
for (File f : files)
{
messages.add(f.getPath());
}
}
}
}
List<Container> children = ContainerManager.getChildren(c);
// Check for unexpected subfolders:
Set<String> allowableSubfolders = children.stream().map(Container::getName).collect(Collectors.toSet());
Set<File> unknownFolders = Arrays.stream(Objects.requireNonNull(root.getRootPath().getParentFile().listFiles())).filter(fn -> !fn.getName().startsWith("@") & !allowableSubfolders.contains(fn.getName())).collect(Collectors.toSet());
if (!unknownFolders.isEmpty()) {
unknownFolders.forEach(x -> getJob().getLogger().warn("Folder does not match expected child: " + x.getPath()));
}
for (Container child : children)
{
if (child.isWorkbook())
{
getOrphanFilesForContainer(child, u, orphanFiles, orphanIndexes, orphanJobs, messages, probableDeletes, knownSequenceJobPaths, knownExpDatas, knownExpDataMap);
}
}
}
private boolean isOrphanPipelineDir(TableInfo jobsTable, File dir, Container c, Set<Integer> knownExpDataIds, Set<File> knownSequenceJobPaths, Set<PipelineStatusFile> orphanJobs, List<String> messages)
{
//find statusfile. Note: this should consider all workbooks, not just current dir
List<Integer> jobIds = new TableSelector(jobsTable, PageFlowUtil.set("RowId"), new SimpleFilter(FieldKey.fromString("FilePath"), dir.getPath() + System.getProperty("file.separator"), CompareType.STARTS_WITH), null).getArrayList(Integer.class);
if (jobIds.isEmpty())
{
//NOTE: this is logged above
//messages.add("## Unable to find matching job, might be orphan: ");
//messages.add(dir.getPath());
return false;
}
else if (jobIds.size() > 1)
{
messages.add("## More than one possible job found, this may simply indicate parent/child jobs: " + dir.getPath());
}
//this could be a directory from an analysis that doesnt register files, like picard metrics
if (knownSequenceJobPaths.contains(dir))
{
return false;
}
// NOTE: if this file is within a known job path, it still could be an orphan. first check whether the directory has registered files.
// If so, remove that path from the set of known job paths
List<? extends ExpData> dataUnderPath = ExperimentService.get().getExpDatasUnderPath(dir, c);
Set<Integer> dataIdsUnderPath = new HashSet<>();
for (ExpData d : dataUnderPath)
{
dataIdsUnderPath.add(d.getRowId());
}
if (!CollectionUtils.containsAny(dataIdsUnderPath, knownExpDataIds))
{
for (int jobId : jobIds)
{
PipelineStatusFile sf = PipelineService.get().getStatusFile(jobId);
orphanJobs.add(sf);
}
return true;
}
return false;
}
private void getOrphanFilesForDirectory(Set<Integer> knownExpDatas, Map<URI, Set<Integer>> dataMap, File dir, Set<File> orphanSequenceFiles, Set<File> orphanIndexes)
{
//skipped for perf reasons. extremely unlikely
//if (!dir.exists() || Files.isSymbolicLink(dir.toPath()))
//{
// return;
//}
//TODO: look for a /Shared folder with large items under it
File[] arr = dir.listFiles();
if (arr == null)
{
getJob().getLogger().error("unable to list files: " + dir.getPath());
return;
}
for (File f : arr)
{
if (f.isDirectory())
{
if (f.getName().endsWith(".gdb"))
{
if (!dataMap.containsKey(new File(f, "__tiledb_workspace.tdb").toURI()))
{
orphanSequenceFiles.add(f);
}
}
getOrphanFilesForDirectory(knownExpDatas, dataMap, f, orphanSequenceFiles, orphanIndexes);
}
else
{
//iterate possible issues:
// extremely large log (200 MB):
if (f.getName().endsWith(".log") & f.length() > (200*1024*1024))
{
getJob().getLogger().warn("WARNING: Extremely large log file: " + f.getPath() + ", " + FileUtils.byteCountToDisplaySize(f.length()));
}
if (f.getName().endsWith(".rds") && !f.getName().endsWith("hashing.rawCounts.rds"))
{
if (!dataMap.containsKey(f.toURI()))
{
getJob().getLogger().warn("WARNING: Unknown RDS file: " + f.getPath());
}
}
//orphan index
if (f.getPath().toLowerCase().endsWith(".bai") || f.getPath().toLowerCase().endsWith(".tbi") || f.getPath().toLowerCase().endsWith(".idx") || f.getPath().toLowerCase().endsWith(".crai"))
{
if (!new File(FileUtil.getBaseName(f.getPath())).exists())
{
orphanIndexes.add(f);
continue;
}
}
//orphan copy file:
if (f.getName().endsWith(".copy"))
{
orphanSequenceFiles.add(f);
}
//heapdump:
if (f.getName().endsWith(".hprof"))
{
orphanSequenceFiles.add(f);
}
//core dump:
if (f.getName().matches("core.[0-9]+"))
{
orphanSequenceFiles.add(f);
}
//sequence files not associated w/ DB records:
if (SequenceUtil.FILETYPE.fastq.getFileType().isType(f) || SequenceUtil.FILETYPE.bam.getFileType().isType(f) || SequenceUtil.FILETYPE.vcf.getFileType().isType(f) || SequenceUtil.FILETYPE.gvcf.getFileType().isType(f))
{
//find all ExpDatas referencing this file
Set<Integer> dataIdsForFile = dataMap.get(FileUtil.getAbsoluteCaseSensitiveFile(f).toURI());
if (dataIdsForFile == null || !CollectionUtils.containsAny(dataIdsForFile, knownExpDatas))
{
//a hack, but special-case undetermined/unaligned FASTQ files
if (SequenceUtil.FILETYPE.fastq.getFileType().isType(f))
{
if (f.getPath().contains("/Normalization/") && f.getName().startsWith("Undetermined_"))
continue;
else if (f.getPath().contains("/Normalization/") && f.getName().contains("_unknowns"))
continue;
else if (f.getPath().contains("/outs/") || f.getPath().contains("/Alignment/") && (f.getName().contains("unaligned") || f.getName().contains("unmapped") || f.getName().contains(".overlapping-")))
continue;
else if (f.getName().contains(".overlapping-R"))
{
//outputs from earlier TCR pipelines:
continue;
}
}
else if (SequenceUtil.FILETYPE.bam.getFileType().isType(f))
{
//ignore 10x products:
if (f.getPath().contains("/outs/"))
{
continue;
}
}
//this is too broad a net
// if (dataIdsForFile != null)
// {
// for (int rowId : dataIdsForFile)
// {
// ExpData d = ExperimentService.get().getExpData(rowId);
// Set<String> roles = ExperimentService.get().getDataInputRoles(d.getContainer(), ContainerFilter.EVERYTHING, ExpProtocol.ApplicationType.ExperimentRunOutput);
// if (roles != null && roles.contains(SequenceTaskHelper.NORMALIZED_FASTQ_OUTPUTNAME))
// {
// continue OUTER;
// }
// }
// }
orphanSequenceFiles.add(f);
}
}
}
}
}
}
}