private static Map<Integer, AlignmentSpan> addAllSpans(final Map<Integer, AlignmentSpan> spanMap, final Map<Integer, AlignmentSpan> addition) { for (final Map.Entry<Integer, AlignmentSpan> entry:addition.entrySet()) { addSpan(entry.getKey(), entry.getValue().getStart(), entry.getValue().getCount(), entry.getValue().getSpan(), spanMap); } return spanMap; }
private static Map<Integer, AlignmentSpan> addAllSpans(final Map<Integer, AlignmentSpan> spanMap, final Map<Integer, AlignmentSpan> addition) { for (final Map.Entry<Integer, AlignmentSpan> entry:addition.entrySet()) { addSpan(entry.getKey(), entry.getValue().getStart(), entry.getValue().getSpan(), entry.getValue().getCount(), spanMap); } return spanMap; }
/** * Create index entries for a single container. * @param container the container to index */ public void processContainer(final Container container) { // TODO: this should be refactored and delegate to container/slice if (!container.isEOF()) { for (final Slice s: container.slices) { if (s.sequenceId == Slice.MULTI_REFERENCE) { final Map<Integer, AlignmentSpan> spans = s.getMultiRefAlignmentSpans(container.header, ValidationStringency.DEFAULT_STRINGENCY); this.entries.addAll(spans.entrySet().stream() .map(e -> new CRAIEntry(e.getKey(), e.getValue().getStart(), e.getValue().getSpan(), container.offset, container.landmarks[s.index], s.size)) .collect(Collectors.toList())); } else { entries.add(s.getCRAIEntry(container.offset)); } } } }
/** * Return a list of CRAI Entries; one for each reference in the multireference slice. * TODO: this should be refactored and delegate to container/slice */ private static Collection<CRAIEntry> getCRAIEntriesForMultiRefSlice( final Slice slice, final CompressionHeader header, final long containerOffset, final int[] landmarks) { final Map<Integer, AlignmentSpan> spans = slice.getMultiRefAlignmentSpans(header, ValidationStringency.DEFAULT_STRINGENCY); List<CRAIEntry> entries = new ArrayList<>(spans.size()); for (int seqId : spans.keySet()) { CRAIEntry e = new CRAIEntry(); e.sequenceId = seqId; AlignmentSpan span = spans.get(seqId); e.alignmentStart = span.getStart(); e.alignmentSpan = span.getSpan(); e.sliceSize = slice.size; e.sliceIndex = slice.index; e.containerStartOffset = containerOffset; e.sliceOffset = landmarks[slice.index]; entries.add(e); } return entries; }
/** * Add multiple reads to the span. * * @param start alignment start * @param span alignment span * @param count number of reads to add */ public void add(final int start, final int span, final int count) { if (this.getStart() > start) { this.setSpan(Math.max(this.getStart() + this.getSpan(), start + span) - start); this.setStart(start); } else if (this.getStart() < start) { this.setSpan(Math.max(this.getStart() + this.getSpan(), start + span) - this.getStart()); } else { this.setSpan(Math.max(this.getSpan(), span)); } this.count += count; }
/** * Add multiple reads to the span. * * @param start alignment start * @param span alignment span * @param count number of reads to add */ public void add(final int start, final int span, final int count) { if (this.getStart() > start) { this.setSpan(Math.max(this.getStart() + this.getSpan(), start + span) - start); this.setStart(start); } else if (this.getStart() < start) { this.setSpan(Math.max(this.getStart() + this.getSpan(), start + span) - this.getStart()); } else { this.setSpan(Math.max(this.getSpan(), span)); } this.count += count; }
public static Map<Integer, AlignmentSpan> getSpans(List<SAMRecord> samRecords) { Map<Integer, AlignmentSpan> spans = new HashMap<Integer, AlignmentSpan>(); int unmapped = 0; for (final SAMRecord r : samRecords) { int refId = r.getReferenceIndex(); if (refId == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) { unmapped++; continue; } int start = r.getAlignmentStart(); int end = r.getAlignmentEnd(); if (spans.containsKey(refId)) { spans.get(refId).add(start, end - start, 1); } else { spans.put(refId, new AlignmentSpan(start, end - start)); } } if (unmapped > 0) { AlignmentSpan span = new AlignmentSpan(AlignmentSpan.UNMAPPED_SPAN.getStart(), AlignmentSpan.UNMAPPED_SPAN.getSpan(), unmapped); spans.put(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX, span); } return spans; }
AlignmentSpan span = spans.get(seqId); e.alignmentStart = span.getStart(); e.alignmentSpan = span.getSpan(); e.sliceSize = slice.size; e.sliceIndex = slice.index;
SAMSequenceRecord sequence = header.getSequence(entry.getKey()); ReferenceRegion region = referenceSource.getRegion(sequence, entry.getValue().getStart(), entry.getValue().getStart() + entry.getValue().getSpan() - 1); if (region == null) { throw new RuntimeException("Reference sequence required but not found: " + sequence.getSequenceName()
fakeSlice.alignmentSpan = span.getSpan(); fakeSlice.nofRecords = span.getCount(); processSingleReferenceSlice(fakeSlice);
fakeSlice.alignmentSpan = span.getSpan(); fakeSlice.nofRecords = span.getCount(); processSingleReferenceSlice(fakeSlice);
tracks.ensureRange(span.getStart(), span.getSpan()); updateTracks(samRecords, tracks);
final SAMFileSpan spanOfSecondContainer = index.getSpanOverlapping(refId, alignmentSpan.getStart(), alignmentSpan.getStart()+ alignmentSpan.getSpan()); Assert.assertNotNull(spanOfSecondContainer); Assert.assertFalse(spanOfSecondContainer.isEmpty()); final SAMRecord record = iterator.next(); if (record.getReferenceIndex().intValue() == refId) { boolean overlaps = CoordMath.overlaps(record.getAlignmentStart(), record.getAlignmentEnd(), alignmentSpan.getStart(), alignmentSpan.getStart()+ alignmentSpan.getSpan()); if (overlaps) matchFound = true;
final SAMFileSpan spanOfSecondContainer = index.getSpanOverlapping(refId, alignmentSpan.getStart(), alignmentSpan.getStart()+ alignmentSpan.getSpan()); Assert.assertNotNull(spanOfSecondContainer); Assert.assertFalse(spanOfSecondContainer.isEmpty()); final SAMRecord record = iterator.next(); if (record.getReferenceIndex().intValue() == refId) { boolean overlaps = CoordMath.overlaps(record.getAlignmentStart(), record.getAlignmentEnd(), alignmentSpan.getStart(), alignmentSpan.getStart()+ alignmentSpan.getSpan()); if (overlaps) matchFound = true;