From cff645e98b9b3f21e5901e5415048c3816bf5986 Mon Sep 17 00:00:00 2001 From: ebanks Date: Mon, 9 Nov 2009 04:45:49 +0000 Subject: [PATCH] convenience method to deal with genotypes that are unsorted (e.g. CA vs. AC) git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1997 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/genotype/DiploidGenotype.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/java/src/org/broadinstitute/sting/utils/genotype/DiploidGenotype.java b/java/src/org/broadinstitute/sting/utils/genotype/DiploidGenotype.java index 9609af671..6c1102c9f 100755 --- a/java/src/org/broadinstitute/sting/utils/genotype/DiploidGenotype.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/DiploidGenotype.java @@ -61,4 +61,17 @@ public enum DiploidGenotype { public static DiploidGenotype createHomGenotype(char hom) { return DiploidGenotype.valueOf((String.valueOf(hom) + String.valueOf(hom)).toUpperCase()); } + + /** + * get the genotype, given a string of 2 chars which may not necessarily be ordered correctly + * @param genotype the string representation + * @return the diploid genotype + */ + public static DiploidGenotype unorderedValueOf(String genotype) { + if ( genotype == null || genotype.length() != 2 ) + throw new IllegalArgumentException("Diploid genotypes are represented by 2 characters"); + if ( genotype.charAt(0) > genotype.charAt(1) ) + genotype = String.format("%c%c", genotype.charAt(1), genotype.charAt(0)); + return valueOf(genotype); + } } \ No newline at end of file