public static Allele extend(final Allele left, final byte[] right) { if (left.isSymbolic()) throw new IllegalArgumentException("Cannot extend a symbolic allele"); byte[] bases = new byte[left.length() + right.length]; System.arraycopy(left.getBases(), 0, bases, 0, left.length()); System.arraycopy(right, 0, bases, left.length(), right.length); return create(bases, left.isReference()); }
@Override public int compareTo(final Allele other) { if ( isReference() && other.isNonReference() ) return -1; else if ( isNonReference() && other.isReference() ) return 1; else return getBaseString().compareTo(other.getBaseString()); // todo -- potential performance issue }
public String toString() { return ( isNoCall() ? NO_CALL_STRING : getDisplayString() ) + (isReference() ? "*" : ""); }
private static Allele reverseComplement(final Allele oldAllele, final Interval target, final ReferenceSequence referenceSequence, final boolean isIndel, final boolean addToStart) { if (oldAllele.isSymbolic() || oldAllele.isNoCall()) { return oldAllele; } else if (isIndel) { // target.getStart is 1-based, reference bases are 0-based final StringBuilder alleleBuilder = new StringBuilder(target.getEnd() - target.getStart() + 1); if (addToStart) { alleleBuilder.append((char) referenceSequence.getBases()[target.getStart() - 2]); } alleleBuilder.append(SequenceUtil.reverseComplement(oldAllele.getBaseString().substring(1, oldAllele.length()))); if (!addToStart) { alleleBuilder.append((char) referenceSequence.getBases()[target.getEnd() - 1]); } return Allele.create(alleleBuilder.toString(), oldAllele.isReference()); } else { return Allele.create(SequenceUtil.reverseComplement(oldAllele.getBaseString()), oldAllele.isReference()); } }
@Test public void testBreakpoint() { Allele a = Allele.create("A[chr1:1["); Assert.assertTrue(a.isSymbolic()); Assert.assertEquals("A[chr1:1[", a.getDisplayString()); Assert.assertTrue(Allele.create("]chr1:1]A").isSymbolic()); Assert.assertTrue(Allele.create("[chr1:1[A").isSymbolic()); Assert.assertTrue(Allele.create("A]chr1:1]").isSymbolic()); }
@Test public void testCreatingNoCallAlleles() { Assert.assertTrue(NoCall.isNonReference()); Assert.assertFalse(NoCall.isReference()); Assert.assertFalse(NoCall.basesMatch(Allele.NO_CALL_STRING)); Assert.assertEquals(NoCall.length(), 0); Assert.assertTrue(NoCall.isNoCall()); Assert.assertFalse(NoCall.isCalled()); }
public List<Allele> truthAlleles() { if (allAlleles.isEmpty() || this.truthAllele1 == null) { return Collections.emptyList(); } else { final Allele truthAllele1 = Allele.create(this.truthAllele1, this.allAlleles.indexOf(this.truthAllele1) == 0); final Allele truthAllele2 = Allele.create(this.truthAllele2, this.allAlleles.indexOf(this.truthAllele2) == 0); return Arrays.asList(truthAllele1, truthAllele2); } }
/** * parse a single allele, given the allele list * @param alleles the alleles available * @param alt the allele to parse * @param lineNo the line number for this record */ private static void parseSingleAltAllele(List<Allele> alleles, String alt, int lineNo) { checkAllele(alt, false, lineNo); Allele allele = Allele.create(alt, false); if ( ! allele.isNoCall() ) alleles.add(allele); }
@Test public void testBreakpointSymbolicBreakend() { Assert.assertTrue(Allele.create("A[<contig>:1[").isSymbolic()); Assert.assertTrue(Allele.create("A]<contig>:1]").isSymbolic()); Assert.assertTrue(Allele.create("]<contig>:1]A").isSymbolic()); Assert.assertTrue(Allele.create("[<contig>:1[A").isSymbolic()); }
private static boolean firstIsPrefixOfSecond(Allele a1, Allele a2) { String a1String = a1.getBaseString(); return a2.getBaseString().substring(0, a1String.length()).equals(a1String); } }
@Test public void testCreatingSpanningDeletionAlleles() { Assert.assertTrue(SpandDel.isNonReference()); Assert.assertFalse(SpandDel.isReference()); Assert.assertTrue(SpandDel.basesMatch(Allele.SPAN_DEL_STRING)); Assert.assertEquals(SpandDel.length(), 1); }
private AlleleList<Allele> alleleList(final int alleleCount, final boolean hasReference) { final Allele[] alleles = AlleleListUnitTester.generateRandomAlleles(alleleCount,100); if (hasReference) { final int referenceIndex = rnd.nextInt(alleleCount); alleles[referenceIndex] = Allele.create(alleles[referenceIndex].getBases(),true); } final AlleleList<Allele> alleleList = new IndexedAlleleList<>(alleles); if (alleleList.alleleCount() != alleles.length) throw new SkipException("repeated alleles, should be infrequent"); return alleleList; }
/** * @return true if the alleles indicate a simple indel, false otherwise. */ public boolean isSimpleIndel() { return getType() == Type.INDEL // allelic lengths differ && isBiallelic() // exactly 2 alleles && getReference().length() > 0 // ref is not null or symbolic && getAlternateAllele(0).length() > 0 // alt is not null or symbolic && getReference().getBases()[0] == getAlternateAllele(0).getBases()[0] // leading bases match for both alleles && (getReference().length() == 1 || getAlternateAllele(0).length() == 1); }
public void validateReferenceBases(final Allele reportedReference, final Allele observedReference) { if ( reportedReference != null && !reportedReference.basesMatch(observedReference) ) { throw new TribbleException.InternalCodecException(String.format("the REF allele is incorrect for the record at position %s:%d, fasta says %s vs. VCF says %s", getContig(), getStart(), observedReference.getBaseString(), reportedReference.getBaseString())); } }
@Test public void testExtend() { Assert.assertEquals("AT", Allele.extend(Allele.create("A"), "T".getBytes()).toString()); Assert.assertEquals("ATA", Allele.extend(Allele.create("A"), "TA".getBytes()).toString()); Assert.assertEquals("A", Allele.extend(Allele.NO_CALL, "A".getBytes()).toString()); Assert.assertEquals("ATCGA", Allele.extend(Allele.create("AT"), "CGA".getBytes()).toString()); Assert.assertEquals("ATCGA", Allele.extend(Allele.create("ATC"), "GA".getBytes()).toString()); } }
public String get(VariantContext vc) { StringBuilder x = new StringBuilder(); x.append(vc.getReference().getDisplayString()); return x.toString(); } });
/** * Return the DNA bases segregating in this allele in String format. * This is useful, because toString() adds a '*' to reference alleles and getBases() returns garbage when you call toString() on it. * * @return the segregating bases */ public String getBaseString() { return isNoCall() ? NO_CALL_STRING : new String(getBases()); }
/** * This is a utility method that will convert a list of alleles into a list of base strings. Reference status * is ignored when creating these strings (i.e. 'A', not 'A*'). These strings should be sufficient * to recreate an Allele using Allele.create() * * @param alleles The list of alleles * @return A list of strings representing the bases of the input alleles. */ protected static List<String> allelesToStringList(final List<Allele> alleles) { final List<String> ret = new ArrayList<>(); alleles.forEach(a -> ret.add(a.isNoCall() ? Allele.NO_CALL_STRING : a.getDisplayString())); return ret; }