/** * Returns the phred scaled probability of a cigar operator of at least this length * @param length * @return phred score */ public double getPhred(CigarOperator operator, int length) { if (length < 0) return 0; double[] opPhred = phred[CigarOperator.enumToBinary(operator)]; assert(opPhred != null); if (length >= opPhred.length) return opPhred[opPhred.length - 1]; return opPhred[length]; } }
@Test(dataProvider = "binary") public void testEnumToBinary(final int bin, final CigarOperator op) throws Exception { Assert.assertEquals(CigarOperator.enumToBinary(op), bin); }
public CigarSizeDistribution(List<CigarDetailMetrics> list) { this.phred = new double[CigarOperator.values().length][]; for (CigarOperator op : CigarOperator.values()) { char charop = (char)CigarOperator.enumToCharacter(op); this.phred[CigarOperator.enumToBinary(op)] = calcPhred(Lists.newArrayList(Iterables.filter(list, cdm -> cdm.OPERATOR == charop))); } } private static double[] calcPhred(List<CigarDetailMetrics> sc) {
/** * Convert CIGAR from object representation to disk representation. * @return Array of unsigned ints, one for each element of CIGAR. */ static int[] encode(final Cigar cigar) { if (cigar.numCigarElements() == 0) { return new int[0]; } // Binary rep can be no longer than 1/2 of text rep // Although this is documented as uint, I think lengths will never get that long, // and it's a pain in Java. final int[] binaryCigar = new int[cigar.numCigarElements()]; int binaryCigarLength = 0; for (int i = 0; i < cigar.numCigarElements(); ++i) { final CigarElement cigarElement = cigar.getCigarElement(i); final int op = CigarOperator.enumToBinary(cigarElement.getOperator()); binaryCigar[binaryCigarLength++] = cigarElement.getLength() << 4 | op; } return binaryCigar; }
/** * Convert CIGAR from object representation to disk representation. * @return Array of unsigned ints, one for each element of CIGAR. */ int[] encode(final Cigar cigar) { if (cigar.numCigarElements() == 0) { return new int[0]; } // Binary rep can be no longer than 1/2 of text rep // Although this is documented as uint, I think lengths will never get that long, // and it's a pain in Java. final int[] binaryCigar = new int[cigar.numCigarElements()]; int binaryCigarLength = 0; for (int i = 0; i < cigar.numCigarElements(); ++i) { final CigarElement cigarElement = cigar.getCigarElement(i); final int op = CigarOperator.enumToBinary(cigarElement.getOperator()); binaryCigar[binaryCigarLength++] = cigarElement.getLength() << 4 | op; } return binaryCigar; }
/** * Convert CIGAR from object representation to disk representation. * @return Array of unsigned ints, one for each element of CIGAR. */ static int[] encode(final Cigar cigar) { if (cigar.numCigarElements() == 0) { return new int[0]; } // Binary rep can be no longer than 1/2 of text rep // Although this is documented as uint, I think lengths will never get that long, // and it's a pain in Java. final int[] binaryCigar = new int[cigar.numCigarElements()]; int binaryCigarLength = 0; for (int i = 0; i < cigar.numCigarElements(); ++i) { final CigarElement cigarElement = cigar.getCigarElement(i); final int op = CigarOperator.enumToBinary(cigarElement.getOperator()); binaryCigar[binaryCigarLength++] = cigarElement.getLength() << 4 | op; } return binaryCigar; }
/** * From htsjdk * * @param cigar * @return */ static int[] encodeBinaryCigar(final Cigar cigar) { if (cigar.numCigarElements() == 0) { return new int[0]; } final int[] binaryCigar = new int[cigar.numCigarElements()]; int binaryCigarLength = 0; for (int i = 0; i < cigar.numCigarElements(); ++i) { final CigarElement cigarElement = cigar.getCigarElement(i); final int op = CigarOperator.enumToBinary(cigarElement.getOperator()); binaryCigar[binaryCigarLength++] = cigarElement.getLength() << 4 | op; } return binaryCigar; } }