public static boolean hasAnyOverlap(Variant current, Variant other, Collection<AlternateCoordinate> alts) { if (current.overlapWith(other, true)) { return true; // Important for REF region } return alts.stream().filter(a -> current.overlapWith(a.getChromosome(), a.getStart(), a.getEnd(), true)) .findAny().isPresent(); }
protected void validateAlternate(AlternateCoordinate alt) { if (alt.getChromosome() == null) { throw new IllegalStateException("Chromosome of alt is null: " + alt); } if (alt.getStart() == null) { throw new IllegalStateException("Start of alt is null: " + alt); } if (alt.getEnd() == null) { throw new IllegalStateException("End of alt is null: " + alt); } if (alt.getReference() == null) { throw new IllegalStateException("Reference of alt is null: " + alt); } if (alt.getAlternate() == null) { throw new IllegalStateException("Alternate of alt is null: " + alt); } }
public static boolean isSameVariant(AlternateCoordinate a, AlternateCoordinate b){ return StringUtils.equals(a.getChromosome(), b.getChromosome()) && a.getStart().equals(b.getStart()) && a.getEnd().equals(b.getEnd()) && StringUtils.equals(a.getReference(), b.getReference()) && StringUtils.equals(a.getAlternate(), b.getAlternate()); } }
/** * Create a list of alternates as Integers to speed up the creation of the VariantAlternateRearranger. * * The creation of the VariantAlternateRearranger makes a lot of comparitions among elements from the list of alternates. * Creating a list of hashCodes from the alternates, speeds up significantly the creation of the rearrangers. * @param alternates List of alternates * @return List of hashCodes for each alternate */ private List<Integer> alternatesToHash(List<AlternateCoordinate> alternates) { List<Integer> list = new ArrayList<>(alternates.size()); for (AlternateCoordinate a : alternates) { // list.add(Objects.hash(a.getChromosome(), a.getStart(), a.getEnd(), a.getReference(), a.getAlternate(), a.getType())); int result = 1; result = 31 * result + a.getChromosome().hashCode(); result = 31 * result + a.getStart().hashCode(); result = 31 * result + a.getEnd().hashCode(); result = 31 * result + a.getReference().hashCode(); result = 31 * result + a.getAlternate().hashCode(); result = 31 * result + a.getType().hashCode(); list.add(result); } return list; }
public static boolean hasAnyOverlap(Variant current, Variant other) { if (current.overlapWith(other, true)) { return true; } // SecAlt of query return other.getStudies().stream() .filter( s -> // foreach study s.getSecondaryAlternates().stream() .filter(a -> { // Avoid NPE a = copyAlt(other, a); return current.overlapWith(a.getChromosome(), a.getStart(), a.getEnd(), true); } ) .findAny() .isPresent() ) .findAny() .isPresent(); }
public static boolean isSameVariant(Variant a, AlternateCoordinate b){ return StringUtils.equals(a.getChromosome(), b.getChromosome()) && a.getStart().equals(b.getStart()) && a.getEnd().equals(b.getEnd()) && StringUtils.equals(a.getReference(), b.getReference()) && StringUtils.equals(a.getAlternate(), b.getAlternate()); }
private String getSecondaryAlternates(Variant variant, StudyEntry studyEntry) { StringBuilder sb = new StringBuilder(); Iterator<AlternateCoordinate> iterator = studyEntry.getSecondaryAlternates().iterator(); while (iterator.hasNext()) { AlternateCoordinate alt = iterator.next(); sb.append(alt.getChromosome() == null ? variant.getChromosome() : alt.getChromosome()); sb.append(ALTERNATE_COORDINATE_SEPARATOR); sb.append(alt.getStart() == null ? variant.getStart() : alt.getStart()); sb.append(ALTERNATE_COORDINATE_SEPARATOR); sb.append(alt.getEnd() == null ? variant.getEnd() : alt.getEnd()); sb.append(ALTERNATE_COORDINATE_SEPARATOR); sb.append(alt.getReference() == null ? variant.getReference() : alt.getReference()); sb.append(ALTERNATE_COORDINATE_SEPARATOR); sb.append(alt.getAlternate() == null ? variant.getAlternate() : alt.getAlternate()); sb.append(ALTERNATE_COORDINATE_SEPARATOR); sb.append(alt.getType() == null ? variant.getType() : alt.getType()); if (iterator.hasNext()) { sb.append(','); } } return sb.toString(); }
} else if (this.collapseDeletions && current.getType().equals(VariantType.SNP)) { varToAlts.forEach(p -> p.getValue().stream() .filter(a -> current.overlapWith(a.getChromosome(), a.getStart(), a.getEnd(), true)) .forEach(altSets::add)); } else {
alt.put(ALTERNATES_CHR, coordinate.getChromosome() != null ? coordinate.getChromosome() : variant.getChromosome()); alt.put(ALTERNATES_REF, coordinate.getReference() != null ? coordinate.getReference() : variant.getReference()); alt.put(ALTERNATES_ALT, coordinate.getAlternate());
.filter(a -> { if (a.getType().equals(VariantType.INDEL)) { return current.overlapWith(a.getChromosome(), a.getStart(), a.getEnd(), true);
private static AlternateCoordinate copyAlt(Variant var, AlternateCoordinate orig) { AlternateCoordinate copy = new AlternateCoordinate(); copy.setChromosome(orig.getChromosome() == null ? var.getChromosome() : orig.getChromosome()); copy.setStart(orig.getStart() == null ? var.getStart() : orig.getStart()); copy.setEnd(orig.getEnd() == null ? var.getEnd() : orig.getEnd()); copy.setReference(orig.getReference() == null ? var.getReference() : orig.getReference()); copy.setAlternate(orig.getAlternate() == null ? var.getAlternate() : orig.getAlternate()); copy.setType(orig.getType() == null ? var.getType() : orig.getType()); return copy; }
recordBuilder.addSecondaryAlternates(VariantProto.AlternateCoordinate .newBuilder() .setChromosome(alternate.getChromosome() != null ? alternate.getChromosome() : "") .setStart(alternate.getStart() != null ? alternate.getStart() : 0) .setEnd(alternate.getEnd() != null ? alternate.getEnd() : 0)
public static Variant asVariant(Variant a, AlternateCoordinate altA) { String chr = ObjectUtils.firstNonNull(altA.getChromosome(), a.getChromosome()); Integer start = ObjectUtils.firstNonNull(altA.getStart(), a.getStart()); Integer end = ObjectUtils.firstNonNull(altA.getEnd(), a.getEnd()); String ref = ObjectUtils.firstNonNull(altA.getReference(), a.getReference()); String alt = ObjectUtils.firstNonNull(altA.getAlternate(), a.getAlternate()); VariantType type = ObjectUtils.firstNonNull(altA.getType(), a.getType()); try { Variant variant = new Variant(chr, start, end, ref, alt); variant.setType(type); return variant; } catch (IllegalArgumentException e) { String msg = altA + "\n" + a.toJson() + "\n"; throw new IllegalStateException(msg, e); } }