From b68d1ac2600d04fcd0cac9ff4da7c5950fd4216c Mon Sep 17 00:00:00 2001 From: James Date: Tue, 4 Dec 2018 12:39:39 -0500 Subject: [PATCH] responded to first round of comments --- .../htsjdk/variant/variantcontext/Genotype.java | 14 +++++++------- .../variant/variantcontext/VariantContext.java | 10 +++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/htsjdk/variant/variantcontext/Genotype.java b/src/main/java/htsjdk/variant/variantcontext/Genotype.java index deb0e54efb..a0c80c2e22 100644 --- a/src/main/java/htsjdk/variant/variantcontext/Genotype.java +++ b/src/main/java/htsjdk/variant/variantcontext/Genotype.java @@ -202,28 +202,28 @@ protected GenotypeType determineType() { } boolean sawNoCall = false, sawMultipleAlleles = false; - Allele firstAllele = null; + Allele firstCallAllele = null; for ( int i = 0; i < alleles.size(); i++ ) { final Allele allele = alleles.get(i); if ( allele.isNoCall() ) { sawNoCall = true; - } else if ( firstAllele == null ) { - firstAllele = allele; - } else if ( !allele.equals(firstAllele) ) + } else if ( firstCallAllele == null ) { + firstCallAllele = allele; + } else if ( !allele.equals(firstCallAllele) ) sawMultipleAlleles = true; } if ( sawNoCall ) { - if ( firstAllele == null ) + if ( firstCallAllele == null ) return GenotypeType.NO_CALL; return GenotypeType.MIXED; } - if ( firstAllele == null ) + if ( firstCallAllele == null ) throw new IllegalStateException("BUG: there are no alleles present in this genotype but the alleles list is not null"); - return sawMultipleAlleles ? GenotypeType.HET : firstAllele.isReference() ? GenotypeType.HOM_REF : GenotypeType.HOM_VAR; + return sawMultipleAlleles ? GenotypeType.HET : firstCallAllele.isReference() ? GenotypeType.HOM_REF : GenotypeType.HOM_VAR; } /** diff --git a/src/main/java/htsjdk/variant/variantcontext/VariantContext.java b/src/main/java/htsjdk/variant/variantcontext/VariantContext.java index abc2c1e3c2..54bc38d73f 100644 --- a/src/main/java/htsjdk/variant/variantcontext/VariantContext.java +++ b/src/main/java/htsjdk/variant/variantcontext/VariantContext.java @@ -1353,8 +1353,11 @@ private void validateGenotypes() { if ( this.genotypes == null ) throw new IllegalStateException("Genotypes is null"); for ( int i = 0; i < genotypes.size(); i++ ) { - if ( genotypes.get(i).isAvailable() ) { - for ( Allele gAllele : genotypes.get(i).getAlleles() ) { + Genotype genotype = genotypes.get(i); + if ( genotype.isAvailable() ) { + final List alleles = genotype.getAlleles(); + for ( int j = 0; j < alleles.size(); j++ ) { + final Allele gAllele = alleles.get(j); if ( ! hasAllele(gAllele) && gAllele.isCalled() ) throw new IllegalStateException("Allele in genotype " + gAllele + " not in the variant context " + alleles); } @@ -1698,7 +1701,8 @@ public boolean hasSymbolicAlleles() { } public static boolean hasSymbolicAlleles( final List alleles ) { - for (int i = 0; i < alleles.size(); i++ ) { + int size = alleles.size(); + for (int i = 0; i < size; i++ ) { if (alleles.get(i).isSymbolic()) { return true; }