Skip to content

Commit

Permalink
Minor code cleanup in AnnotateNovelSites
Browse files Browse the repository at this point in the history
  • Loading branch information
bbimber committed Nov 2, 2024
1 parent 1738c47 commit 8758f22
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions src/main/java/com/github/discvrseq/walkers/AnnotateNovelSites.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,44 +136,43 @@ public void apply(List<VariantContext> variantContexts, ReferenceContext referen
if (novelSitesWriter != null) {
novelSitesWriter.add(vcb.genotypes().make());
}

continue;
}
else {
boolean foundMatchingRef = false;
boolean isNovel = false;
for (VariantContext refVariant : refVariants) {

// Inspect to determine if site counts:
boolean foundMatchingRef = false;
boolean isNovel = false;
for (VariantContext refVariant : refVariants) {
if (refVariant.getReference().equals(vc.getReference())) {
Set<String> values = new LinkedHashSet<>(refVariant.getAttributeAsStringList(novelSiteAnnotationName, existingSiteDefaultAnnotationValue));

// Prior site exists, alleles identical. No action needed:
if (refVariant.getReference().equals(vc.getReference())) {
if (refVariant.getAlternateAlleles().equals(vc.getAlternateAlleles())) {
List<String> val = refVariant.getAttributeAsStringList(novelSiteAnnotationName, refVariant.getAttributeAsString(novelSiteAnnotationName, existingSiteDefaultAnnotationValue));
if (val != null && !val.isEmpty()) {
vcb.attribute(novelSiteAnnotationName, new ArrayList<>(val));
}
}
else {
// Alleles are different, so annotate with both
Set<String> anns = new LinkedHashSet<>(refVariant.getAttributeAsStringList(novelSiteAnnotationName, refVariant.getAttributeAsString(novelSiteAnnotationName, existingSiteDefaultAnnotationValue)));
anns.add(novelSiteAnnotationValue);
isNovel = true;

vcb.attribute(novelSiteAnnotationName, new ArrayList<>(anns));
}
foundMatchingRef = true;
break;
if (refVariant.getAlternateAlleles().equals(vc.getAlternateAlleles())) {
vcb.attribute(novelSiteAnnotationName, new ArrayList<>(values));
} else {
// Alleles are different, so annotate with both
values.add(novelSiteAnnotationValue);
isNovel = true;
vcb.attribute(novelSiteAnnotationName, new ArrayList<>(values));
}
}

if (!foundMatchingRef) {
vcb.attribute(novelSiteAnnotationName, novelSiteAnnotationValue);
isNovel = true;
novelSites++;
foundMatchingRef = true;
break;
}
}

vc = vcb.make();
writer.add(vc);
if (!foundMatchingRef) {
vcb.attribute(novelSiteAnnotationName, novelSiteAnnotationValue);
isNovel = true;
novelSites++;
}

if (isNovel && novelSitesWriter != null) {
novelSitesWriter.add(vcb.genotypes().make());
}
vc = vcb.make();
writer.add(vc);

if (isNovel && novelSitesWriter != null) {
novelSitesWriter.add(vcb.genotypes().make());
}
}
}
Expand Down

0 comments on commit 8758f22

Please sign in to comment.