MCPcopy Create free account
hub / github.com/RealTimeGenomics/rtg-tools / splitGt

Method splitGt

src/main/java/com/rtg/vcf/VcfUtils.java:221–257  ·  view source on GitHub ↗

Utility method for splitting a VCF genotype subfield into an array of numeric allele identifiers. @param gt a VCF genotype subfield (the GT value). @return a new int[] containing one int per allele. Any missing values ('.') will be assigned index -1. @throws NumberFormatEx

(String gt)

Source from the content-addressed store, hash-verified

219 * @throws NumberFormatException if the subfield is malformed.
220 */
221 public static int[] splitGt(String gt) {
222 try {
223 final int gtlen = gt.length();
224 if (gtlen == 1) { // Typical haploid call
225 return new int[]{alleleId(gt.charAt(0))};
226 } else {
227 int[] result = new int[2]; // Initialize assuming the most common case, diploid, and resize if needed
228 int ploid = 0;
229 int allelestart = 0;
230 for (int i = 0; i < gtlen; ++i) {
231 final char c = gt.charAt(i);
232 if (c == PHASED_SEPARATOR || c == UNPHASED_SEPARATOR) {
233 if (ploid == result.length) { // More than diploid call!
234 result = Arrays.copyOf(result, result.length + 1);
235 }
236 result[ploid++] = alleleId(gt, allelestart, i - allelestart);
237 allelestart = i + 1;
238 }
239 }
240 if (allelestart < gtlen) {
241 if (ploid == result.length) { // More than diploid call!
242 result = Arrays.copyOf(result, result.length + 1);
243 }
244 result[ploid++] = alleleId(gt, allelestart, gtlen - allelestart);
245 }
246 if (ploid < result.length) { // Can only happen if a haploid genotype with allele id > 9
247 result = Arrays.copyOf(result, ploid);
248 }
249 if (ploid == 0) {
250 throw new NumberFormatException();
251 }
252 return result;
253 }
254 } catch (NumberFormatException e) {
255 throw new VcfFormatException("Malformed VCF GT value \"" + gt + "\"");
256 }
257 }
258
259 /**
260 * Utility method for creating a VCF genotype subfield from an array of

Callers 15

testSplitGTMethod · 0.95
checkIsNonVariantGtMethod · 0.95
checkIsNonMissingGtMethod · 0.95
testGetVariantTypeRecMethod · 0.95
decomposeMethod · 0.95
phaseDiploidCallMethod · 0.95
splitRemapGtMethod · 0.95
mainExecMethod · 0.95
acceptGtSpecificMethod · 0.95
tallyVariantMethod · 0.95
annotateMethod · 0.95
getValidGtMethod · 0.95

Calls 2

alleleIdMethod · 0.95
lengthMethod · 0.65

Tested by 4

testSplitGTMethod · 0.76
checkIsNonVariantGtMethod · 0.76
checkIsNonMissingGtMethod · 0.76
testGetVariantTypeRecMethod · 0.76