Repository navigation
Expand file tree
/
Copy pathNGSToolkit.tsx
More file actions
5889 lines (5599 loc) · 316 KB
/
Copy pathNGSToolkit.tsx
File metadata and controls
5889 lines (5599 loc) · 316 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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { ngsArtifactUrl, useNgsArtifacts, type NgsPackageArtifact } from '../lib/ngsArtifacts';
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import { JobStageProgress } from './JobStageProgress';
import { useLocation, useNavigate } from 'react-router-dom';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import type { QueryClient } from '@tanstack/react-query';
import Plot from 'react-plotly.js';
import type { Data, Layout, PlotMouseEvent } from 'plotly.js';
import type { IGV as IgvLibrary } from 'igv';
import { api, createOntSignalViewerSession, DEFAULT_ONT_SIGNAL_RENDER_PARAMS, fetchFullJob, fetchJobLogs, fetchJobStages, fetchJobs, fetchOntRawSignalCapabilities, fetchOntSignalViewerSession, fetchPooledAssignmentManifest, type Job, type JobLogs, type OntSignalViewerAlignmentColorBy, type OntSignalViewerAlignmentDisplayMode, type OntSignalViewerAlignmentGroupBy, type OntSignalViewerSession } from '../lib/api';
import {
alignmentTrackAutoLoadDisposition,
buildAlignmentTrackConfig,
buildFullSourceCoverageTrackConfig,
buildLocalIgvConfig,
createGenerationBoundResourceWithTimeout,
createIgvGenerationMount,
ownsIgvLoadTerminalState,
parseLocalIgvRange,
loadMissingTracksById,
removeIgvBrowser,
removeIgvGenerationMount,
resolveAlignmentViewerArtifacts,
resolveBoundSessionLocus,
resolveBrowserAlignmentTrackSource,
resolveIgvClickedReadId,
publishCurrentIgvReadSelection,
resolveIgvReadLocus,
locusMatchesAlignmentSlice,
resolvePendingSessionLocus,
resolveSessionAuxiliaryTracks,
replaceAlignmentTrackTransactionally,
type AlignmentReadLocus,
type BrowserAlignmentTrackSource,
type PendingSessionNavigation,
} from '../lib/ngsAlignmentViewer';
import {
alignmentReadIgvLocus,
bindAlignmentSessionsToResultAuthority,
createAlignmentLocusSlice,
createLatestRequestGuard,
disposeAlignmentAccess,
describeNgsError,
fetchAlignmentRead,
fetchAlignmentSessions,
fetchAlignmentPresentation,
isAlignmentAccessDenied,
rotateAlignmentAccess,
type AlignmentRead,
type AlignmentLocusSlice,
type AlignmentPresentation,
type AlignmentSession,
} from '../lib/ngsAlignmentSession';
import {
isNgsJob,
ngsJobShouldPoll,
ngsToolkitSearchForView,
ngsToolkitViewFromSearch,
type NgsToolkitView,
} from '../lib/ngsResultRouting';
import { normalizeNanoporeCloneState } from '../lib/nanoporeCloneState';
import { jobPollingInterval } from '../lib/queryPolling';
import { NanoporeTemplate } from './NanoporeTemplate';
import { OntInstrumentPanel } from './ngs/OntInstrumentPanel';
import { RawReadInspector } from './ngs/RawReadInspector';
import { ReadAndSignalWorkbench } from './ngs/ReadAndSignalWorkbench';
import { NgsArtifactDownloads } from './ngs/NgsArtifactDownloads';
import { isOwnedFullscreen, toggleOwnedFullscreen } from './ngs/ngsFullscreenOwner';
import { BarcodeUnitsPanel } from './ngs/BarcodeUnitsPanel';
import { PooledAssignmentReviewPanel } from './ngs/PooledAssignmentReviewPanel';
import { SequenceQcManifestPanel } from './ngs/SequenceQcManifestPanel';
import { OntFastqQcResultPanel } from './ngs/OntFastqQcResultPanel';
import { AlignmentPresentationStatus } from './ngs/AlignmentPresentationStatus';
import { useOntFastqQcResult } from './ngs/useOntFastqQcResult';
import { useSequenceQcManifest } from './ngs/useSequenceQcManifest';
import { useThemeColors, useThemePlotlyLayout } from './useThemeColors';
import { useGlobalExperimentContext } from './experiments/GlobalExperimentContext';
import ExperimentReferenceLinks from './molbio-ngs/ExperimentReferenceLinks';
import NgsMolBioProjectHub from './molbio-ngs/NgsMolBioProjectHub';
type ToolkitView = NgsToolkitView;
type LogTab = 'parsed' | 'command' | 'stderr' | 'nextflow';
type StageOutputsMap = Record<string, string[]>;
interface OwnedIgvNavigation {
requestId: number;
navigation: PendingSessionNavigation;
}
const NANOPORE_DOC_LINKS = [
{ label: 'Dorado docs', href: 'https://dorado-docs.readthedocs.io/en/latest/' },
{ label: 'Dorado GitHub', href: 'https://github.com/nanoporetech/dorado' },
{ label: 'modkit GitHub', href: 'https://github.com/nanoporetech/modkit' },
{ label: 'wf-clone GitHub', href: 'https://github.com/epi2me-labs/wf-clone-validation' },
{ label: 'minimap2 GitHub', href: 'https://github.com/lh3/minimap2' },
{ label: 'IGV.js docs', href: 'https://igv.org/doc/igvjs/' },
{ label: 'Nextflow docs', href: 'https://www.nextflow.io/docs/latest/index.html' },
] as const;
interface IgvArtifacts {
bamPath: string | null;
bamUrl: string | null;
baiPath: string | null;
baiUrl: string | null;
fastaPath: string | null;
fastaUrl: string | null;
faiPath: string | null;
faiUrl: string | null;
coverageDepthPath: string | null;
coverageDepthUrl: string | null;
positionGradientPath: string | null;
positionGradientUrl: string | null;
gcContentPath: string | null;
gcContentUrl: string | null;
gcZscorePath: string | null;
gcZscoreUrl: string | null;
splitDensityPath: string | null;
splitDensityUrl: string | null;
softclipDensityPath: string | null;
softclipDensityUrl: string | null;
junctionHotspotsPath: string | null;
junctionHotspotsUrl: string | null;
reportPath: string | null;
reportUrl: string | null;
trackConfigPath: string | null;
trackConfigUrl: string | null;
missingReason: string | null;
}
interface MethylationArtifacts {
summaryPath: string | null;
summaryUrl: string | null;
bedPath: string | null;
bedUrl: string | null;
missingReason: string | null;
}
interface IgvAlignmentSource {
label: string;
bamPath: string;
bamUrl: string | null;
baiPath: string | null;
baiUrl: string | null;
}
interface IgvReferenceSource {
label: string;
fastaPath: string;
fastaUrl: string | null;
faiPath: string | null;
faiUrl: string | null;
}
interface MultimerArtifacts {
summaryPath: string | null;
summaryUrl: string | null;
lengthsPath: string | null;
lengthsUrl: string | null;
candidatesPath: string | null;
candidatesUrl: string | null;
logPath: string | null;
logUrl: string | null;
dimerFastqPath: string | null;
dimerFastqUrl: string | null;
dimerFastaPath: string | null;
dimerFastaUrl: string | null;
dimerLengthsPath: string | null;
dimerLengthsUrl: string | null;
dimerSummaryPath: string | null;
dimerSummaryUrl: string | null;
dimerConsensusPath: string | null;
dimerConsensusUrl: string | null;
dominantDimerConsensusPath: string | null;
dominantDimerConsensusUrl: string | null;
dominantDimerConsensusMetadataPath: string | null;
dominantDimerConsensusMetadataUrl: string | null;
dimerJunctionPath: string | null;
dimerJunctionUrl: string | null;
dimerJunctionEventsPath: string | null;
dimerJunctionEventsUrl: string | null;
dimerJunctionClustersPath: string | null;
dimerJunctionClustersUrl: string | null;
dimerJunctionHotspotsPath: string | null;
dimerJunctionHotspotsUrl: string | null;
dimerJunctionRotatedPath: string | null;
dimerJunctionRotatedUrl: string | null;
dimerJunctionRotationSummaryPath: string | null;
dimerJunctionRotationSummaryUrl: string | null;
dimerBreakpointScreenPath: string | null;
dimerBreakpointScreenUrl: string | null;
dimerBreakpointSequencesPath: string | null;
dimerBreakpointSequencesUrl: string | null;
dimerSecondaryAnomaliesPath: string | null;
dimerSecondaryAnomaliesUrl: string | null;
dimerSecondarySummaryPath: string | null;
dimerSecondarySummaryUrl: string | null;
dimerReadsPath: string | null;
dimerReadsUrl: string | null;
dimerReadLedgerPath: string | null;
dimerReadLedgerUrl: string | null;
dimerBreakpointReadsPath: string | null;
dimerBreakpointReadsUrl: string | null;
dimerRotatedRemapSummaryPath: string | null;
dimerRotatedRemapSummaryUrl: string | null;
dimerRotatedRemapBreakpointsPath: string | null;
dimerRotatedRemapBreakpointsUrl: string | null;
dimerBamPath: string | null;
dimerBamUrl: string | null;
dimerBaiPath: string | null;
dimerBaiUrl: string | null;
dimerReferencePath: string | null;
dimerReferenceUrl: string | null;
dimerReferenceIndexPath: string | null;
dimerReferenceIndexUrl: string | null;
missingReason: string | null;
}
function summaryTableLookup(table: SummaryTable | null | undefined): Map<string, string> {
if (!table || table.header.length === 0) return new Map<string, string>();
const metricIdx = table.header.findIndex((h) => h.trim().toLowerCase() === 'metric');
const valueIdx = table.header.findIndex((h) => h.trim().toLowerCase() === 'value');
if (metricIdx < 0 || valueIdx < 0) return new Map<string, string>();
const lookup = new Map<string, string>();
for (const row of table.rows) {
const key = String(row[metricIdx] ?? '').trim().toLowerCase();
if (!key) continue;
lookup.set(key, String(row[valueIdx] ?? '').trim());
}
return lookup;
}
interface SummaryTable {
header: string[];
rows: string[][];
}
interface MultimerCandidateRow {
readIndex: number | null;
readLength: number | null;
classification: string;
}
interface DimerJunctionProfileRow {
positionModRef: number;
readCount: number;
spanningReads: number;
}
interface DimerReadJunctionRow {
readId: string;
start: number | null;
end: number | null;
positionModRef: number | null;
crossesJunction: boolean | null;
method: string | null;
orientation: string | null;
missingLeftBp: number | null;
missingRightBp: number | null;
source: 'legacy' | 'events';
}
interface DimerJunctionClusterRow {
clusterId: string | null;
positionModRef: number;
supportReads: number;
crossingReads: number;
supportPercent: number | null;
method: string | null;
orientation: string | null;
eventCount: number | null;
inBoundaryWindow: boolean | null;
source: 'clusters' | 'hotspots' | 'events' | 'profile';
}
interface DimerBreakpointScreenRow {
positionModRef: number;
totalSupportReads: number;
seamSupportReads: number;
splitSupportReads: number;
supportPctAll: number | null;
splitPctOfPosition: number | null;
splitPctOfAllSplit: number | null;
inBoundaryWindow: boolean | null;
boundaryStartReads: number | null;
boundaryStartFraction: number | null;
seamFraction: number | null;
splitToSeamRatio: number | null;
artifactFlag: boolean | null;
confidence: string | null;
junctionWindowLabel: string | null;
junctionWindowSeq: string | null;
}
interface MultimerReportData {
summary: SummaryTable | null;
metrics: Record<string, number>;
readLengths: number[];
candidates: MultimerCandidateRow[];
dimerSummary: SummaryTable | null;
dimerJunctionRows: DimerJunctionProfileRow[];
dimerJunctionClusters: DimerJunctionClusterRow[];
dimerBreakpointScreenRows: DimerBreakpointScreenRow[];
dimerReadJunctions: DimerReadJunctionRow[];
dimerConsensusPreview: string | null;
dominantDimerConsensusPreview: string | null;
dominantDimerConsensusMetadata: SummaryTable | null;
referenceName: string | null;
referenceLength: number | null;
referenceSequence: string | null;
}
interface MethylationLocus {
chrom: string;
start: number;
end: number;
code: string;
strand: string;
percentModified: number | null;
coverage: number | null;
}
interface MethylationPoint {
chrom: string;
position: number;
code: string;
percentModified: number | null;
coverage: number | null;
}
interface MethylationSeries {
code: string;
label: string;
points: MethylationPoint[];
}
interface MotifSiteCall {
chrom: string;
position: number;
motif: 'Dam' | 'Dcm';
context: string;
strand: '+' | '-';
pairKey: string;
percentModified: number | null;
coverage: number | null;
}
interface MethylationReportData {
summary: SummaryTable | null;
topLoci: MethylationLocus[];
series: MethylationSeries[];
damSites: MotifSiteCall[];
dcmSites: MotifSiteCall[];
referenceName: string | null;
referenceLength: number | null;
referenceSequence: string | null;
}
interface SelectedMotifPoint extends MotifSiteCall {
sequenceContext: string | null;
contextStart: number | null;
contextEnd: number | null;
}
interface SequenceRow {
start: number;
end: number;
bases: string;
}
interface SequenceBaseHighlight {
motif: 'Dam' | 'Dcm';
strand: '+' | '-';
percentModified: number;
color: string;
}
interface HighlightedSequenceSegment {
text: string;
position: number | null;
highlight: SequenceBaseHighlight | null;
isSelected: boolean;
}
const STAGE_LABELS: Record<string, string> = {
dorado_basecall: 'Dorado Basecall',
doradobasecall: 'Dorado Basecall',
dorado_align: 'Dorado Align',
doradoalign: 'Dorado Align',
bam_prepare: 'BAM Prepare',
preparebamforanalysis: 'BAM Prepare',
modkit: 'modkit',
modkitpileup: 'modkit Pileup',
modkitsummary: 'modkit Summary',
fastq_qc: 'FASTQ Plasmid QC',
fastqplasmidqc: 'FASTQ Plasmid QC',
multimer_qc: 'Multimer QC',
dimer_analysis: 'Dimer Analysis',
dimeranalysis: 'Dimer Analysis',
fastqdimeranalysis: 'Dimer Analysis',
fastq_align: 'FASTQ Align',
fastqalign: 'FASTQ Align',
fastqmultimerqc: 'Multimer QC',
runclonevalidation: 'wf-clone-validation',
'wf-clone-validation': 'wf-clone-validation',
wf_clone_validation: 'wf-clone-validation',
};
const STATUS_OPTIONS = ['all', 'queued', 'running', 'completed', 'failed', 'cancelled'];
const ALLOWED_ROOT_PREFIXES = ['bms_results/', 'inputs/', 'benchmarkdata/', 'lib/', 'rcsb/', 'downloads/', 'data/'];
const IGV_REQUIRED_VERSION = '3.7.3';
const IGV_INIT_TIMEOUT_MS = 20000;
const IGV_INITIAL_LOCUS_WINDOW_BP = 800;
const IGV_INITIAL_FULL_LOCUS_MAX_BP = 100000;
const IGV_READS_TRACK_MIN_HEIGHT_PX = 260;
const IGV_READS_TRACK_MIN_WITHOUT_AUX_PX = 520;
const IGV_READS_TRACK_BOTTOM_GUTTER_PX = 8;
const IGV_AUX_TRACK_RESERVED_GUTTER_PX = 24;
const IGV_AUX_TRACK_MAX_RESERVED_FRACTION = 0.42;
const METHYLATION_BED_MAX_BYTES = 8 * 1024 * 1024;
const METHYLATION_SUMMARY_MAX_BYTES = 2 * 1024 * 1024;
const REFERENCE_FASTA_MAX_BYTES = 2 * 1024 * 1024;
const MULTIMER_SUMMARY_MAX_BYTES = 512 * 1024;
const MULTIMER_LENGTHS_MAX_BYTES = 8 * 1024 * 1024;
const MULTIMER_CANDIDATES_MAX_BYTES = 2 * 1024 * 1024;
const DIMER_CONSENSUS_MAX_BYTES = 512 * 1024;
const DIMER_CONSENSUS_PREVIEW_CHARS = 12000;
const MAX_PLOT_POINTS_PER_CODE = 5000;
const REFERENCE_SEQUENCE_LINE_WIDTH = 120;
const DEFAULT_MOTIF_MIN_COVERAGE = 20;
const ALIGNMENT_STAGE_ALIASES = ['dorado_align', 'doradoalign', 'bam_prepare', 'bamprepare', 'preparebamforanalysis', 'fastq_align', 'fastqalign'];
const REFERENCE_STAGE_ALIASES = [...ALIGNMENT_STAGE_ALIASES, 'reference_prepare', 'referenceprepareforigv'];
const MODKIT_STAGE_ALIASES = ['modkit', 'modkitpileup', 'modkitsummary'];
const MULTIMER_STAGE_ALIASES = ['fastq_qc', 'fastqqc', 'fastqplasmidqc', 'multimer_qc', 'multimerqc', 'fastqmultimerqc'];
const DIMER_STAGE_ALIASES = ['dimer_analysis', 'dimeranalysis', 'fastqdimeranalysis'];
const METHYLATION_STRAND_FILTERS = ['both', '+', '-'] as const;
const MOTIF_CONCORDANCE_DELTA_PERCENT = 5;
const RELEVANT_METHYLATION_CODES = new Set(['a', 'm']);
const IGV_ALIGNMENT_DISPLAY_OPTIONS = [
{ value: 'EXPANDED', label: 'Expanded' },
{ value: 'SQUISHED', label: 'Squished' },
{ value: 'FULL', label: 'Full' },
];
const IGV_ALIGNMENT_COLOR_OPTIONS = [
{ value: 'none', label: 'Color: None' },
{ value: 'strand', label: 'Color: Strand' },
{ value: 'firstOfPairStrand', label: 'Color: First Pair Strand' },
{ value: 'pairOrientation', label: 'Color: Pair Orientation' },
{ value: 'tlen', label: 'Color: Template Length' },
{ value: 'unexpectedPair', label: 'Color: Unexpected Pair' },
{ value: 'basemod', label: 'Color: Base Mods' },
{ value: 'basemod2', label: 'Color: Base Mods (Alt)' },
];
const IGV_ALIGNMENT_GROUP_OPTIONS = [
{ value: 'none', label: 'Group: None' },
{ value: 'strand', label: 'Group: Strand' },
{ value: 'firstOfPairStrand', label: 'Group: First Pair Strand' },
{ value: 'pairOrientation', label: 'Group: Pair Orientation' },
{ value: 'mateChr', label: 'Group: Mate Chromosome' },
{ value: 'chimeric', label: 'Group: Chimeric' },
{ value: 'supplementary', label: 'Group: Supplementary' },
{ value: 'readOrder', label: 'Group: Read Order' },
];
let igvLibraryPromise: Promise<{ igv: IgvLibrary; version: string }> | null = null;
function isAllowedRelativePath(path: string): boolean {
return ALLOWED_ROOT_PREFIXES.some((prefix) => path.startsWith(prefix));
}
function normalizeAllowedRelativePath(path: string | null | undefined): string | null {
if (!path) return null;
const normalized = path.replace(/\\/g, '/').replace(/\/+$/, '');
if (!normalized) return null;
if (isAllowedRelativePath(`${normalized}/`)) {
return normalized;
}
const lowered = normalized.toLowerCase();
for (const rootPrefix of ALLOWED_ROOT_PREFIXES) {
const root = rootPrefix.replace(/\/+$/, '');
const rootLower = root.toLowerCase();
const token = `/${rootLower}/`;
const idx = lowered.lastIndexOf(token);
if (idx >= 0) {
const rel = normalized.slice(idx + 1);
if (isAllowedRelativePath(`${rel}/`)) {
return rel;
}
}
if (lowered.endsWith(`/${rootLower}`) && isAllowedRelativePath(`${root}/`)) {
return root;
}
}
return null;
}
function resolveRunPrefix(outputDir: string | null | undefined, paths: string[]): string | null {
const normalized = normalizeAllowedRelativePath(outputDir);
if (normalized) return normalized;
if (!outputDir) return null;
const leaf = outputDir
.replace(/\\/g, '/')
.replace(/\/+$/, '')
.split('/')
.filter(Boolean)
.pop();
if (!leaf) return null;
for (const path of dedupePaths(paths)) {
const segments = path.replace(/\\/g, '/').split('/').filter(Boolean);
const idx = segments.lastIndexOf(leaf);
if (idx <= 0) continue;
const prefix = segments.slice(0, idx + 1).join('/');
if (isAllowedRelativePath(`${prefix}/`)) {
return prefix;
}
}
return null;
}
function dedupePaths(paths: string[]): string[] {
return [...new Set(paths.filter((value): value is string => typeof value === 'string' && value.length > 0))];
}
function filterPathsByRunPrefix(paths: string[], runPrefix: string | null): string[] {
const deduped = dedupePaths(paths);
if (!runPrefix) return deduped;
const prefix = runPrefix.replace(/\/+$/, '');
return deduped.filter((path) => path === prefix || path.startsWith(`${prefix}/`));
}
function findFirstMatchingPath(paths: string[], patterns: RegExp[]): string | null {
// Patterns are ordered from the preferred native output to legacy fallbacks.
for (const pattern of patterns) {
const match = paths.find(path => pattern.test(path.toLowerCase()));
if (match) return match;
}
return null;
}
function normalizeStageKey(stage: string): string {
return stage.toLowerCase().replace(/[^a-z0-9]/g, '');
}
function hasMeaningfulValue(value: unknown): boolean {
if (value == null) return false;
if (typeof value === 'string') {
const normalized = value.trim().toLowerCase();
return normalized !== '' && !['null', 'none', 'undefined', 'n/a', 'na'].includes(normalized);
}
return Boolean(value);
}
function resolveFastqQcEnabled(params: Record<string, unknown>, hasFastq: boolean): boolean {
if (!hasFastq) return false;
if (typeof params.run_fastq_qc === 'boolean') return params.run_fastq_qc;
// Legacy persisted jobs only. New launches use run_fastq_qc.
if (typeof params.run_multimer_qc === 'boolean') return params.run_multimer_qc;
return false;
}
function collectPathsForStageAliases(stageOutputs: StageOutputsMap, aliases: string[]): string[] {
const aliasSet = new Set(aliases.map(normalizeStageKey));
return Object.entries(stageOutputs || {})
.flatMap(([stage, outputs]) => {
if (!aliasSet.has(normalizeStageKey(stage))) return [];
if (!Array.isArray(outputs)) return [];
return outputs.filter((value): value is string => typeof value === 'string' && value.length > 0);
});
}
function collectStageOutputPaths(stageOutputs: StageOutputsMap): string[] {
const values = Object.values(stageOutputs || {});
return values.flat().filter((value): value is string => typeof value === 'string' && value.length > 0);
}
function resolveBamIndexArtifactPath(bamPath: string | null, paths: string[]): string | null {
if (bamPath) {
const exactCandidates = [`${bamPath}.bai`, `${bamPath}.csi`];
const exact = exactCandidates.find((candidate) => paths.includes(candidate));
if (exact) return exact;
const bamBase = bamPath.split('/').pop();
if (bamBase) {
const paired = paths.find((path) => path.endsWith(`${bamBase}.bai`) || path.endsWith(`${bamBase}.csi`));
if (paired) return paired;
}
}
return findFirstMatchingPath(paths, [/\.bam\.(bai|csi)$/i, /\.(bai|csi)$/i]);
}
function resolveFastaIndexArtifactPath(fastaPath: string | null, paths: string[]): string | null {
if (!fastaPath) return null;
const exact = `${fastaPath}.fai`;
if (paths.includes(exact)) return exact;
const fastaBase = fastaPath.split('/').pop();
if (fastaBase) {
const paired = paths.find((path) => path.endsWith(`${fastaBase}.fai`));
if (paired) return paired;
}
return findFirstMatchingPath(paths, [/\.fai$/i]);
}
function formatIgvSourceLabel(path: string): string {
const parts = path.replace(/\\/g, '/').split('/').filter(Boolean);
if (parts.length <= 2) return parts.join('/');
return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`;
}
function resolveIgvArtifacts(job: Job | null, stageOutputs: StageOutputsMap, artifacts: NgsPackageArtifact[]): IgvArtifacts {
const toStreamHref = (path: string, jobId?: string) => ngsArtifactUrl(path, jobId, artifacts);
const toDownloadHref = toStreamHref;
if (!job) {
return {
bamPath: null,
bamUrl: null,
baiPath: null,
baiUrl: null,
fastaPath: null,
fastaUrl: null,
faiPath: null,
faiUrl: null,
coverageDepthPath: null,
coverageDepthUrl: null,
positionGradientPath: null,
positionGradientUrl: null,
gcContentPath: null,
gcContentUrl: null,
gcZscorePath: null,
gcZscoreUrl: null,
splitDensityPath: null,
splitDensityUrl: null,
softclipDensityPath: null,
softclipDensityUrl: null,
junctionHotspotsPath: null,
junctionHotspotsUrl: null,
reportPath: null,
reportUrl: null,
trackConfigPath: null,
trackConfigUrl: null,
missingReason: 'Select a run to inspect IGV artifacts.',
};
}
const paths = collectStageOutputPaths(stageOutputs);
const alignmentPaths = collectPathsForStageAliases(stageOutputs, ALIGNMENT_STAGE_ALIASES);
const referencePaths = collectPathsForStageAliases(stageOutputs, REFERENCE_STAGE_ALIASES);
const dimerPaths = collectPathsForStageAliases(stageOutputs, DIMER_STAGE_ALIASES);
const params = (job.params || {}) as Record<string, unknown>;
const runPrefix = resolveRunPrefix(job.output_dir, paths);
const scopedPaths = filterPathsByRunPrefix(paths, runPrefix);
const scopedAlignmentPaths = filterPathsByRunPrefix(alignmentPaths, runPrefix);
const scopedReferencePaths = filterPathsByRunPrefix(referencePaths, runPrefix);
const scopedDimerPaths = filterPathsByRunPrefix(dimerPaths, runPrefix);
const dimerBase = runPrefix
? (scopedDimerPaths.length > 0 ? scopedDimerPaths : scopedPaths)
: (dimerPaths.length > 0 ? dimerPaths : paths);
const alignmentBase = runPrefix
? (scopedAlignmentPaths.length > 0 ? scopedAlignmentPaths : dimerBase)
: (alignmentPaths.length > 0 ? alignmentPaths : dimerBase);
const referenceBase = runPrefix
? (scopedReferencePaths.length > 0 ? scopedReferencePaths : dimerBase)
: (referencePaths.length > 0 ? referencePaths : dimerBase);
const alignmentCandidates = dedupePaths(alignmentBase);
const referenceCandidates = dedupePaths(referenceBase);
const analysisCandidates = dedupePaths(runPrefix ? scopedPaths : paths);
const viewerInputs = dedupePaths([
...alignmentCandidates,
...referenceCandidates,
...analysisCandidates,
]).map((path) => ({ path }));
const primaryViewer = resolveAlignmentViewerArtifacts(viewerInputs, 'primary');
const bamPath = primaryViewer.bam?.path || null;
const baiPath = primaryViewer.bai?.path || null;
const fastaPath = primaryViewer.fasta?.path || null;
const faiPath = primaryViewer.fai?.path || null;
const fallbackReference = typeof params.reference_fasta === 'string' ? params.reference_fasta : null;
const fallbackReferenceIndex = fallbackReference ? `${fallbackReference}.fai` : null;
const cacheKey = job.id;
const bamUrl = bamPath ? toStreamHref(bamPath, cacheKey) : null;
const baiUrl = baiPath ? toStreamHref(baiPath, cacheKey) : null;
const fastaUrl = fastaPath ? toStreamHref(fastaPath, cacheKey) : (fallbackReference ? toStreamHref(fallbackReference, cacheKey) : null);
const faiUrl = faiPath ? toStreamHref(faiPath, cacheKey) : (fallbackReferenceIndex ? toStreamHref(fallbackReferenceIndex, cacheKey) : null);
const coverageDepthPath = findFirstMatchingPath(analysisCandidates, [/\/fastq_qc\/igv_coverage_depth\.bedgraph$/i, /(^|\/)igv_coverage_depth\.bedgraph$/i]);
const positionGradientPath = findFirstMatchingPath(analysisCandidates, [/\/fastq_qc\/igv_position_gradient\.bedgraph$/i, /(^|\/)igv_position_gradient\.bedgraph$/i]);
const gcContentPath = findFirstMatchingPath(analysisCandidates, [/\/fastq_qc\/igv_gc_content\.bedgraph$/i, /(^|\/)igv_gc_content\.bedgraph$/i]);
const gcZscorePath = findFirstMatchingPath(analysisCandidates, [/\/fastq_qc\/igv_gc_zscore\.bedgraph$/i, /(^|\/)igv_gc_zscore\.bedgraph$/i]);
const splitDensityPath = findFirstMatchingPath(analysisCandidates, [/\/fastq_qc\/igv_split_read_density\.bedgraph$/i, /(^|\/)igv_split_read_density\.bedgraph$/i]);
const softclipDensityPath = findFirstMatchingPath(analysisCandidates, [/\/fastq_qc\/igv_softclip_density\.bedgraph$/i, /(^|\/)igv_softclip_density\.bedgraph$/i]);
const junctionHotspotsPath = findFirstMatchingPath(analysisCandidates, [/\/fastq_qc\/igv_junction_hotspots\.bed$/i, /(^|\/)igv_junction_hotspots\.bed$/i]);
const reportPath = findFirstMatchingPath(analysisCandidates, [/\/fastq_qc\/igv_report\.html$/i, /(^|\/)igv_report\.html$/i]);
const trackConfigPath = findFirstMatchingPath(analysisCandidates, [/\/fastq_qc\/igv_track_config\.json$/i, /(^|\/)igv_track_config\.json$/i]);
const coverageDepthUrl = coverageDepthPath ? toStreamHref(coverageDepthPath, cacheKey) : null;
const positionGradientUrl = positionGradientPath ? toStreamHref(positionGradientPath, cacheKey) : null;
const gcContentUrl = gcContentPath ? toStreamHref(gcContentPath, cacheKey) : null;
const gcZscoreUrl = gcZscorePath ? toStreamHref(gcZscorePath, cacheKey) : null;
const splitDensityUrl = splitDensityPath ? toStreamHref(splitDensityPath, cacheKey) : null;
const softclipDensityUrl = softclipDensityPath ? toStreamHref(softclipDensityPath, cacheKey) : null;
const junctionHotspotsUrl = junctionHotspotsPath ? toStreamHref(junctionHotspotsPath, cacheKey) : null;
const reportUrl = reportPath ? toDownloadHref(reportPath, cacheKey) : null;
const trackConfigUrl = trackConfigPath ? toDownloadHref(trackConfigPath, cacheKey) : null;
let missingReason: string | null = null;
if (!bamUrl) {
missingReason = 'Aligned BAM artifact not found yet.';
} else if (!baiUrl) {
missingReason = 'BAM index (.bai/.csi) not found yet.';
} else if (!fastaUrl) {
missingReason = 'Reference FASTA not found. Run with reference_fasta to enable IGV.';
} else if (!faiUrl) {
missingReason = 'Reference FASTA index (.fai) not found.';
}
return {
bamPath,
bamUrl,
baiPath,
baiUrl,
fastaPath: fastaPath || fallbackReference,
fastaUrl,
faiPath: faiPath || fallbackReferenceIndex,
faiUrl,
coverageDepthPath,
coverageDepthUrl,
positionGradientPath,
positionGradientUrl,
gcContentPath,
gcContentUrl,
gcZscorePath,
gcZscoreUrl,
splitDensityPath,
splitDensityUrl,
softclipDensityPath,
softclipDensityUrl,
junctionHotspotsPath,
junctionHotspotsUrl,
reportPath,
reportUrl,
trackConfigPath,
trackConfigUrl,
missingReason,
};
}
function resolveMethylationArtifacts(job: Job | null, stageOutputs: StageOutputsMap, artifacts: NgsPackageArtifact[]): MethylationArtifacts {
const toStreamHref = (path: string, jobId?: string) => ngsArtifactUrl(path, jobId, artifacts);
if (!job) {
return {
summaryPath: null,
summaryUrl: null,
bedPath: null,
bedUrl: null,
missingReason: 'Select a run to inspect methylation outputs.',
};
}
const params = (job.params || {}) as Record<string, unknown>;
const runModkit = params.run_modkit !== false;
const paths = collectStageOutputPaths(stageOutputs);
const modkitPaths = collectPathsForStageAliases(stageOutputs, MODKIT_STAGE_ALIASES);
const runPrefix = resolveRunPrefix(job.output_dir, paths);
const scopedPaths = filterPathsByRunPrefix(paths, runPrefix);
const scopedModkitPaths = filterPathsByRunPrefix(modkitPaths, runPrefix);
const candidateBase = runPrefix
? (scopedModkitPaths.length > 0 ? scopedModkitPaths : scopedPaths)
: (modkitPaths.length > 0 ? modkitPaths : paths);
const candidates = dedupePaths([...candidateBase, ...artifacts.filter(a => a.state === 'present' && a.filename).map(a => `/${a.source}/${a.filename}`)]);
const summaryPath = findFirstMatchingPath(candidates, [/\/methylation\/modkit_summary\.tsv$/i, /(^|\/)modkit_summary\.tsv$/i]);
const bedPath = findFirstMatchingPath(candidates, [/\/methylation\/methylation\.bed$/i, /\/methylation\/.*\.bed$/i]);
const cacheKey = job.id;
const summaryUrl = summaryPath ? toStreamHref(summaryPath, cacheKey) : null;
const bedUrl = bedPath ? toStreamHref(bedPath, cacheKey) : null;
let missingReason: string | null = null;
if (!runModkit) {
missingReason = 'modkit was disabled for this run (run_modkit=false).';
} else if (!summaryUrl && !bedUrl) {
missingReason = 'No modkit methylation outputs found yet.';
}
return {
summaryPath,
summaryUrl,
bedPath,
bedUrl,
missingReason,
};
}
function resolveMultimerArtifacts(job: Job | null, stageOutputs: StageOutputsMap, artifacts: NgsPackageArtifact[]): MultimerArtifacts {
const toStreamHref = (path: string, jobId?: string) => ngsArtifactUrl(path, jobId, artifacts);
if (!job) {
return {
summaryPath: null,
summaryUrl: null,
lengthsPath: null,
lengthsUrl: null,
candidatesPath: null,
candidatesUrl: null,
logPath: null,
logUrl: null,
dimerFastqPath: null,
dimerFastqUrl: null,
dimerFastaPath: null,
dimerFastaUrl: null,
dimerLengthsPath: null,
dimerLengthsUrl: null,
dimerSummaryPath: null,
dimerSummaryUrl: null,
dimerConsensusPath: null,
dimerConsensusUrl: null,
dominantDimerConsensusPath: null,
dominantDimerConsensusUrl: null,
dominantDimerConsensusMetadataPath: null,
dominantDimerConsensusMetadataUrl: null,
dimerJunctionPath: null,
dimerJunctionUrl: null,
dimerJunctionEventsPath: null,
dimerJunctionEventsUrl: null,
dimerJunctionClustersPath: null,
dimerJunctionClustersUrl: null,
dimerJunctionHotspotsPath: null,
dimerJunctionHotspotsUrl: null,
dimerJunctionRotatedPath: null,
dimerJunctionRotatedUrl: null,
dimerJunctionRotationSummaryPath: null,
dimerJunctionRotationSummaryUrl: null,
dimerBreakpointScreenPath: null,
dimerBreakpointScreenUrl: null,
dimerBreakpointSequencesPath: null,
dimerBreakpointSequencesUrl: null,
dimerSecondaryAnomaliesPath: null,
dimerSecondaryAnomaliesUrl: null,
dimerSecondarySummaryPath: null,
dimerSecondarySummaryUrl: null,
dimerReadsPath: null,
dimerReadsUrl: null,
dimerReadLedgerPath: null,
dimerReadLedgerUrl: null,
dimerBreakpointReadsPath: null,
dimerBreakpointReadsUrl: null,
dimerRotatedRemapSummaryPath: null,
dimerRotatedRemapSummaryUrl: null,
dimerRotatedRemapBreakpointsPath: null,
dimerRotatedRemapBreakpointsUrl: null,
dimerBamPath: null,
dimerBamUrl: null,
dimerBaiPath: null,
dimerBaiUrl: null,
dimerReferencePath: null,
dimerReferenceUrl: null,
dimerReferenceIndexPath: null,
dimerReferenceIndexUrl: null,
missingReason: 'Select a run to inspect multimer QC outputs.',
};
}
const params = (job.params || {}) as Record<string, unknown>;
const hasFastq = hasMeaningfulValue(params.fastq_path);
const runFastqQc = resolveFastqQcEnabled(params, hasFastq);
const paths = collectStageOutputPaths(stageOutputs);
const multimerPaths = collectPathsForStageAliases(stageOutputs, MULTIMER_STAGE_ALIASES);
const dimerPaths = collectPathsForStageAliases(stageOutputs, DIMER_STAGE_ALIASES);
const runPrefix = resolveRunPrefix(job.output_dir, paths);
const scopedPaths = filterPathsByRunPrefix(paths, runPrefix);
const scopedMultimerPaths = filterPathsByRunPrefix(multimerPaths, runPrefix);
const scopedDimerPaths = filterPathsByRunPrefix(dimerPaths, runPrefix);
const scopedStagePaths = dedupePaths([...scopedMultimerPaths, ...scopedDimerPaths]);
const stagePaths = dedupePaths([...multimerPaths, ...dimerPaths]);
const candidateBase = runPrefix
? (scopedStagePaths.length > 0 ? scopedStagePaths : scopedPaths)
: (stagePaths.length > 0 ? stagePaths : paths);
const candidates = dedupePaths([...candidateBase, ...artifacts.filter(a => a.state === 'present' && a.filename).map(a => `/${a.source}/${a.filename}`)]);
const summaryPath = findFirstMatchingPath(candidates, [/\/fastq_qc\/fastq_qc_summary\.tsv$/i, /(^|\/)fastq_qc_summary\.tsv$/i, /\/multimer_qc\/multimer_summary\.tsv$/i, /(^|\/)multimer_summary\.tsv$/i]);
const lengthsPath = findFirstMatchingPath(candidates, [/\/fastq_qc\/read_lengths\.tsv$/i, /(^|\/)read_lengths\.tsv$/i]);
const candidatesPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/multimer_candidates\.tsv$/i, /(^|\/)multimer_candidates\.tsv$/i]);
const logPath = findFirstMatchingPath(candidates, [/\/fastq_qc\/fastq_qc\.log$/i, /(^|\/)fastq_qc\.log$/i, /\/multimer_qc\/multimer_qc\.log$/i, /(^|\/)multimer_qc\.log$/i]);
const dimerFastqPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_candidates\.fastq$/i, /(^|\/)dimer_candidates\.fastq$/i]);
const dimerFastaPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_candidates\.fasta$/i, /(^|\/)dimer_candidates\.fasta$/i]);
const dimerLengthsPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_read_lengths\.tsv$/i, /(^|\/)dimer_read_lengths\.tsv$/i]);
const dimerSummaryPath = findFirstMatchingPath(candidates, [/\/fastq_qc\/fastq_alignment_stats\.tsv$/i, /(^|\/)fastq_alignment_stats\.tsv$/i, /\/multimer_qc\/dimer_analysis_summary\.tsv$/i, /(^|\/)dimer_analysis_summary\.tsv$/i]);
const dimerConsensusPath = findFirstMatchingPath(candidates, [/\/fastq_qc\/fastq_consensus\.fasta$/i, /(^|\/)fastq_consensus\.fasta$/i, /\/multimer_qc\/dimer_consensus\.fasta$/i, /(^|\/)dimer_consensus\.fasta$/i]);
const dominantDimerConsensusPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dominant_dimer_consensus\.fasta$/i, /(^|\/)dominant_dimer_consensus\.fasta$/i]);
const dominantDimerConsensusMetadataPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dominant_dimer_consensus_metadata\.tsv$/i, /(^|\/)dominant_dimer_consensus_metadata\.tsv$/i]);
const dimerCanonicalEvidencePath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_evidence_by_position\.tsv$/i, /(^|\/)dimer_evidence_by_position\.tsv$/i]);
const dimerCanonicalReadEventsPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_read_events\.tsv$/i, /(^|\/)dimer_read_events\.tsv$/i]);
const dimerJunctionPathLegacy = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_junction_profile\.tsv$/i, /(^|\/)dimer_junction_profile\.tsv$/i]);
const dimerJunctionEventsPathLegacy = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_junction_events\.tsv$/i, /(^|\/)dimer_junction_events\.tsv$/i]);
const dimerJunctionClustersPathLegacy = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_junction_clusters\.tsv$/i, /(^|\/)dimer_junction_clusters\.tsv$/i]);
const dimerJunctionHotspotsPathLegacy = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_junction_hotspots\.tsv$/i, /(^|\/)dimer_junction_hotspots\.tsv$/i]);
const dimerJunctionPath = dimerJunctionPathLegacy || dimerCanonicalEvidencePath;
const dimerJunctionEventsPath = dimerJunctionEventsPathLegacy || dimerCanonicalReadEventsPath;
const dimerJunctionClustersPath = dimerJunctionClustersPathLegacy || dimerCanonicalEvidencePath;
const dimerJunctionHotspotsPath = dimerJunctionHotspotsPathLegacy || dimerCanonicalEvidencePath;
const dimerJunctionRotatedPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_junction_rotated_profile\.tsv$/i, /(^|\/)dimer_junction_rotated_profile\.tsv$/i]);
const dimerJunctionRotationSummaryPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_junction_rotation_summary\.tsv$/i, /(^|\/)dimer_junction_rotation_summary\.tsv$/i]);
const dimerBreakpointScreenPathLegacy = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_breakpoint_screen\.tsv$/i, /(^|\/)dimer_breakpoint_screen\.tsv$/i]);
const dimerBreakpointScreenPath = dimerBreakpointScreenPathLegacy || dimerCanonicalEvidencePath;
const dimerBreakpointSequencesPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_breakpoint_sequences\.tsv$/i, /(^|\/)dimer_breakpoint_sequences\.tsv$/i]);
const dimerSecondaryAnomaliesPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_secondary_anomalies\.tsv$/i, /(^|\/)dimer_secondary_anomalies\.tsv$/i]);
const dimerSecondarySummaryPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_secondary_summary\.tsv$/i, /(^|\/)dimer_secondary_summary\.tsv$/i]);
const dimerReadsPathLegacy = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_read_junctions\.tsv$/i, /(^|\/)dimer_read_junctions\.tsv$/i]);
const dimerReadsPath = dimerReadsPathLegacy || dimerCanonicalReadEventsPath;
const dimerReadLedgerPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_read_ledger\.tsv$/i, /(^|\/)dimer_read_ledger\.tsv$/i]);
const dimerBreakpointReadsPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_breakpoint_reads\.tsv$/i, /(^|\/)dimer_breakpoint_reads\.tsv$/i]);
const dimerRotatedRemapSummaryPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_rotated_remap_summary\.tsv$/i, /(^|\/)dimer_rotated_remap_summary\.tsv$/i]);
const dimerRotatedRemapBreakpointsPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_rotated_remap_breakpoints\.tsv$/i, /(^|\/)dimer_rotated_remap_breakpoints\.tsv$/i]);
const dimerBamPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_candidates\.aligned\.bam$/i, /(^|\/)dimer_candidates\.aligned\.bam$/i]);
const dimerBaiPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_candidates\.aligned\.bam\.(bai|csi)$/i, /(^|\/)dimer_candidates\.aligned\.bam\.(bai|csi)$/i]);
const dimerReferencePath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_reference\.fasta$/i, /(^|\/)dimer_reference\.fasta$/i]);
const dimerReferenceIndexPath = findFirstMatchingPath(candidates, [/\/multimer_qc\/dimer_reference\.fasta\.fai$/i, /(^|\/)dimer_reference\.fasta\.fai$/i]);
const cacheKey = job.id;
const summaryUrl = summaryPath ? toStreamHref(summaryPath, cacheKey) : null;
const lengthsUrl = lengthsPath ? toStreamHref(lengthsPath, cacheKey) : null;
const candidatesUrl = candidatesPath ? toStreamHref(candidatesPath, cacheKey) : null;
const logUrl = logPath ? toStreamHref(logPath, cacheKey) : null;
const dimerFastqUrl = dimerFastqPath ? toStreamHref(dimerFastqPath, cacheKey) : null;
const dimerFastaUrl = dimerFastaPath ? toStreamHref(dimerFastaPath, cacheKey) : null;
const dimerLengthsUrl = dimerLengthsPath ? toStreamHref(dimerLengthsPath, cacheKey) : null;
const dimerSummaryUrl = dimerSummaryPath ? toStreamHref(dimerSummaryPath, cacheKey) : null;
const dimerConsensusUrl = dimerConsensusPath ? toStreamHref(dimerConsensusPath, cacheKey) : null;
const dominantDimerConsensusUrl = dominantDimerConsensusPath ? toStreamHref(dominantDimerConsensusPath, cacheKey) : null;
const dominantDimerConsensusMetadataUrl = dominantDimerConsensusMetadataPath ? toStreamHref(dominantDimerConsensusMetadataPath, cacheKey) : null;
const dimerJunctionUrl = dimerJunctionPath ? toStreamHref(dimerJunctionPath, cacheKey) : null;
const dimerJunctionEventsUrl = dimerJunctionEventsPath ? toStreamHref(dimerJunctionEventsPath, cacheKey) : null;
const dimerJunctionClustersUrl = dimerJunctionClustersPath ? toStreamHref(dimerJunctionClustersPath, cacheKey) : null;
const dimerJunctionHotspotsUrl = dimerJunctionHotspotsPath ? toStreamHref(dimerJunctionHotspotsPath, cacheKey) : null;
const dimerJunctionRotatedUrl = dimerJunctionRotatedPath ? toStreamHref(dimerJunctionRotatedPath, cacheKey) : null;
const dimerJunctionRotationSummaryUrl = dimerJunctionRotationSummaryPath ? toStreamHref(dimerJunctionRotationSummaryPath, cacheKey) : null;
const dimerBreakpointScreenUrl = dimerBreakpointScreenPath ? toStreamHref(dimerBreakpointScreenPath, cacheKey) : null;
const dimerBreakpointSequencesUrl = dimerBreakpointSequencesPath ? toStreamHref(dimerBreakpointSequencesPath, cacheKey) : null;
const dimerSecondaryAnomaliesUrl = dimerSecondaryAnomaliesPath ? toStreamHref(dimerSecondaryAnomaliesPath, cacheKey) : null;
const dimerSecondarySummaryUrl = dimerSecondarySummaryPath ? toStreamHref(dimerSecondarySummaryPath, cacheKey) : null;
const dimerReadsUrl = dimerReadsPath ? toStreamHref(dimerReadsPath, cacheKey) : null;
const dimerReadLedgerUrl = dimerReadLedgerPath ? toStreamHref(dimerReadLedgerPath, cacheKey) : null;
const dimerBreakpointReadsUrl = dimerBreakpointReadsPath ? toStreamHref(dimerBreakpointReadsPath, cacheKey) : null;
const dimerRotatedRemapSummaryUrl = dimerRotatedRemapSummaryPath ? toStreamHref(dimerRotatedRemapSummaryPath, cacheKey) : null;
const dimerRotatedRemapBreakpointsUrl = dimerRotatedRemapBreakpointsPath ? toStreamHref(dimerRotatedRemapBreakpointsPath, cacheKey) : null;
const dimerBamUrl = dimerBamPath ? toStreamHref(dimerBamPath, cacheKey) : null;
const dimerBaiUrl = dimerBaiPath ? toStreamHref(dimerBaiPath, cacheKey) : null;
const dimerReferenceUrl = dimerReferencePath ? toStreamHref(dimerReferencePath, cacheKey) : null;
const dimerReferenceIndexUrl = dimerReferenceIndexPath ? toStreamHref(dimerReferenceIndexPath, cacheKey) : null;
let missingReason: string | null = null;
if (!hasFastq) {
missingReason = 'Run does not include FASTQ input.';
} else if (!runFastqQc) {
missingReason = 'FASTQ plasmid QC is disabled for this run.';
} else if (
!summaryUrl
&& !lengthsUrl
&& !candidatesUrl
&& !dimerSummaryUrl
&& !dimerJunctionUrl
&& !dimerJunctionEventsUrl
&& !dimerJunctionClustersUrl
&& !dimerJunctionHotspotsUrl
&& !dimerJunctionRotatedUrl
&& !dimerJunctionRotationSummaryUrl
&& !dimerBreakpointScreenUrl
&& !dimerBreakpointSequencesUrl
&& !dimerSecondaryAnomaliesUrl
&& !dimerSecondarySummaryUrl
&& !dimerConsensusUrl
&& !dimerReadsUrl
&& !dimerReadLedgerUrl
&& !dimerBreakpointReadsUrl
&& !dimerRotatedRemapSummaryUrl
&& !dimerRotatedRemapBreakpointsUrl
) {
missingReason = 'No multimer QC outputs found yet.';
}
return {
summaryPath,
summaryUrl,
lengthsPath,
lengthsUrl,
candidatesPath,
candidatesUrl,
logPath,
logUrl,
dimerFastqPath,
dimerFastqUrl,
dimerFastaPath,
dimerFastaUrl,
dimerLengthsPath,