Program: 80609
Project: 80609
Buggy source:
/** 
 * actual implementation for canonicalization
 * @param variant
 * @param end
 * @return
 */
private List<Variant> canonicalizeVariant(Variant variant,boolean end){
  List<Variant> variantList=new ArrayList<>();
  boolean noSplit=false;
  if (variant.getType() == VariantOverallType.SNP) {
    noSplit=true;
  }
  if (variant.getCompositions() == null && variant.getGoodPaternal() == 0 && variant.getGoodMaternal() == 0) {
    noSplit=true;
  }
  if (variant.getGoodPaternal() != 0 && !canonicalizableFlexSeqTypes.contains(variant.getAlt(variant.getGoodPaternal()).getSeqType())) {
    noSplit=true;
  }
  if (variant.getGoodMaternal() != 0 && !canonicalizableFlexSeqTypes.contains(variant.getAlt(variant.getGoodMaternal()).getSeqType())) {
    noSplit=true;
  }
  if (variant.getGoodPaternal() != 0 && variant.getAlt(variant.getGoodPaternal()).length() == 0 && variant.getReference().length == 0) {
    noSplit=true;
  }
  if (variant.getGoodMaternal() > 0 && variant.getAlt(variant.getGoodMaternal()).length() == 0 && variant.getReference().length == 0) {
    noSplit=true;
  }
  if (noSplit) {
    variantList.add(variant);
    return variantList;
  }
  if (variant.getCompositions() != null) {
    for (    Variant c : variant.getCompositions()) {
      variantList.addAll(canonicalizeVariant(new Variant(c),end));
    }
    return variantList;
  }
  Variant.Builder template=new Variant.Builder().chr(variant.getChr()).isPhased(true).varId(variant.getVariantId()).filter(VCFparser.DEFAULT_FILTER).refDeleted("String_Node_Str");
  if (variant.getType(variant.getGoodMaternal()) == VariantType.Translocation_Duplication || variant.getType(variant.getGoodMaternal()) == VariantType.Interspersed_Duplication || variant.getType(variant.getGoodPaternal()) == VariantType.Translocation_Duplication || variant.getType(variant.getGoodPaternal()) == VariantType.Interspersed_Duplication) {
    for (int parentIndex=0; parentIndex < 2; parentIndex++) {
      int allele=variant.getAllele(parentIndex);
      if (variant.getType(allele) == VariantType.Reference)       continue;
      byte[] phase=new byte[2];
      phase[parentIndex]=1;
      if (variant.getType(allele) == VariantType.Translocation_Duplication || variant.getType(allele) == VariantType.Interspersed_Duplication) {
        boolean isInversed=variant.isInversed();
        Alt alt1=new Alt();
        alt1.setBreakend(new Alt.Breakend(variant.getReference().clone(),variant.getChr2(allele),isInversed ? variant.getEnd2(allele) : variant.getPos2(allele),true,!isInversed));
        variantList.add(template.pos(variant.getPos() - 1).referenceAlleleLength(0).ref(new byte[0]).alts(new Alt[]{alt1}).phase(phase).build());
        Alt alt2=new Alt();
        alt2.setBreakend(new Alt.Breakend(ambiguousBase,variant.getChr2(parentIndex),isInversed ? variant.getPos2(parentIndex) : variant.getEnd2(parentIndex),false,isInversed));
        variantList.add(template.pos(variant.getPos()).referenceAlleleLength(0).ref(new byte[0]).alts(new Alt[]{alt2}).phase(phase).build());
      }
      variant.setAllele(parentIndex,(byte)0);
    }
  }
 else   if (variant.getType(variant.getGoodMaternal()) == VariantType.Translocation_Deletion || variant.getType(variant.getGoodPaternal()) == VariantType.Translocation_Deletion) {
    for (int parentIndex=0; parentIndex < 2; parentIndex++) {
      int allele=variant.getAllele(parentIndex);
      if (variant.getType(allele) == VariantType.Reference)       continue;
      byte[] phase=new byte[2];
      phase[parentIndex]=1;
      if (variant.getType(allele) == VariantType.Translocation_Deletion) {
        Alt alt1=new Alt();
        alt1.setBreakend(new Alt.Breakend(variant.getReference().clone(),variant.getChr(),variant.getPos() + variant.getReferenceAlleleLength(),true,true));
        variantList.add(template.pos(variant.getPos() - 1).referenceAlleleLength(0).ref(new byte[0]).alts(new Alt[]{alt1}).phase(phase).build());
      }
      variant.setAllele(parentIndex,(byte)0);
    }
  }
 else   if (variant.getType(variant.getGoodPaternal()) != VariantType.Reference && variant.getType(variant.getGoodMaternal()) != VariantType.Reference) {
    int[] alleleNumber={variant.getAllele(0),variant.getAllele(1)};
    byte[][] alternativeAlleleSequence={variant.getAlt(alleleNumber[0]).getSequence(),variant.getAlt(alleleNumber[1]).getSequence()};
    byte[] referenceAlleleSequence=variant.getReference();
    int currentPosition=variant.getPos();
    int minMatchLength=variant.getMinMatchLength();
    if (minMatchLength > 0) {
      referenceAlleleSequence=Arrays.copyOfRange(referenceAlleleSequence,minMatchLength,referenceAlleleSequence.length);
      for (int i=0; i < 2; i++) {
        alternativeAlleleSequence[i]=Arrays.copyOfRange(alternativeAlleleSequence[i],minMatchLength,alternativeAlleleSequence[i].length);
      }
      currentPosition+=minMatchLength;
    }
    int[] alleleLengthDifference={alternativeAlleleSequence[0].length - referenceAlleleSequence.length,alternativeAlleleSequence[1].length - referenceAlleleSequence.length};
    canonicalizeToIndels(variantList,alleleLengthDifference,referenceAlleleSequence,alternativeAlleleSequence,variant,currentPosition,end);
    for (int relativePosition=0; relativePosition < referenceAlleleSequence.length; relativePosition++, currentPosition++) {
      int[] alleleSpecificRelativePosition=new int[2];
      if (end) {
        for (int j=0; j < 2; j++) {
          if (relativePosition < referenceAlleleSequence.length + alleleLengthDifference[j]) {
            alleleSpecificRelativePosition[j]=relativePosition;
          }
 else {
            alleleSpecificRelativePosition[j]=-1;
          }
        }
      }
 else {
        for (int j=0; j < 2; j++) {
          alleleSpecificRelativePosition[j]=relativePosition + alleleLengthDifference[j];
        }
      }
      if (alleleSpecificRelativePosition[0] < 0 && alleleSpecificRelativePosition[1] < 0) {
      }
 else       if (alleleSpecificRelativePosition[0] >= 0 && alleleSpecificRelativePosition[1] < 0 && alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]] != referenceAlleleSequence[relativePosition]) {
        byte[] phase={1,1};
        Alt alt=new Alt();
        alt.setSeq(new FlexSeq(alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]]));
        variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceAlleleSequence[relativePosition]}).alts(new Alt[]{alt}).phase(phase).build());
      }
 else       if (alleleSpecificRelativePosition[0] < 0 && alleleSpecificRelativePosition[1] >= 0 && alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]] != referenceAlleleSequence[relativePosition]) {
        byte[] phase={1,1};
        Alt alt=new Alt();
        alt.setSeq(new FlexSeq(alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]]));
        variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceAlleleSequence[relativePosition]}).alts(new Alt[]{alt}).phase(phase).build());
      }
 else       if (alleleSpecificRelativePosition[0] >= 0 && alleleSpecificRelativePosition[1] < 0 && alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]] == referenceAlleleSequence[relativePosition]) {
      }
 else       if (alleleSpecificRelativePosition[0] < 0 && alleleSpecificRelativePosition[1] >= 0 && alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]] == referenceAlleleSequence[relativePosition]) {
      }
 else       if (alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]] == referenceAlleleSequence[relativePosition] && alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]] == referenceAlleleSequence[relativePosition]) {
      }
 else       if (alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]] == alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]]) {
        byte[] phase={1,1};
        Alt alt=new Alt();
        alt.setSeq(new FlexSeq(alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]]));
        variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceAlleleSequence[relativePosition]}).alts(new Alt[]{alt}).phase(phase).build());
      }
 else       if (alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]] != referenceAlleleSequence[relativePosition] && alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]] != referenceAlleleSequence[relativePosition]) {
        byte[] phase={1,2};
        Alt[] alts=new Alt[2];
        alts[0]=new Alt();
        alts[1]=new Alt();
        alts[0].setSeq(new FlexSeq(alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]]));
        alts[1].setSeq(new FlexSeq(alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]]));
        variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceAlleleSequence[relativePosition]}).alts(alts).phase(phase).build());
      }
 else {
        for (int a=0; a < 2; a++) {
          if (alternativeAlleleSequence[a][alleleSpecificRelativePosition[a]] != referenceAlleleSequence[relativePosition]) {
            byte[] phase={0,0};
            phase[a]=1;
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq(alternativeAlleleSequence[a][alleleSpecificRelativePosition[a]]));
            variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceAlleleSequence[relativePosition]}).alts(new Alt[]{alt}).phase(phase).build());
          }
        }
      }
    }
    variant.setAllele(0,(byte)0);
    variant.setAllele(1,(byte)0);
  }
 else {
    for (int alleleIndex=0; alleleIndex < 2; alleleIndex++) {
      int allele=variant.getAllele(alleleIndex);
      if (variant.getType(allele) == VariantType.Complex || variant.getType(allele) == VariantType.MNP || variant.getType(allele) == VariantType.SNP) {
        byte[] alternativeAlleleSequence=variant.getAlt(allele).getSequence();
        byte[] referenceSequence=variant.getReference();
        int currentPosition=variant.getPos();
        int alleleLengthDifference=alternativeAlleleSequence.length - referenceSequence.length;
        if (alleleLengthDifference > 0) {
          byte[] phase={0,0};
          phase[alleleIndex]=1;
          if (end) {
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq(Arrays.copyOfRange(alternativeAlleleSequence,0,alleleLengthDifference)));
            variantList.add(template.pos(currentPosition + referenceSequence.length).referenceAlleleLength(0).ref(new byte[0]).alts(new Alt[]{alt}).phase(phase).build());
          }
 else {
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq(Arrays.copyOfRange(alternativeAlleleSequence,0,alleleLengthDifference)));
            variantList.add(template.pos(currentPosition).referenceAlleleLength(0).ref(new byte[0]).alts(new Alt[]{alt}).phase(phase).build());
          }
        }
 else         if (alleleLengthDifference < 0) {
          byte[] phase={0,0};
          phase[alleleIndex]=1;
          if (end) {
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq());
            variantList.add(template.pos(currentPosition + alternativeAlleleSequence.length).referenceAlleleLength(-alleleLengthDifference).ref(Arrays.copyOfRange(referenceSequence,alternativeAlleleSequence.length,alternativeAlleleSequence.length - alleleLengthDifference)).alts(new Alt[]{alt}).phase(phase).build());
          }
 else {
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq());
            variantList.add(template.pos(currentPosition).referenceAlleleLength(-alleleLengthDifference).ref(Arrays.copyOfRange(referenceSequence,0,-alleleLengthDifference)).alts(new Alt[]{alt}).phase(phase).build());
          }
        }
        for (int i=0; i < referenceSequence.length; i++) {
          int idx;
          if (end) {
            if (i < referenceSequence.length + alleleLengthDifference) {
              idx=i;
            }
 else {
              idx=-1;
            }
          }
 else {
            idx=i + alleleLengthDifference;
          }
          if (idx >= 0 && alternativeAlleleSequence[idx] != referenceSequence[i]) {
            byte[] phase={0,0};
            phase[alleleIndex]=1;
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq(alternativeAlleleSequence[idx]));
            variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceSequence[i]}).alts(new Alt[]{alt}).phase(phase).build());
          }
          currentPosition++;
        }
        variant.setAllele(alleleIndex,(byte)0);
      }
    }
  }
  if (!variant.isRef()) {
    variantList.add(variant);
  }
  return variantList;
}

Fixed version (ground truth):
/** 
 * actual implementation for canonicalization
 * @param variant
 * @param end
 * @return
 */
private List<Variant> canonicalizeVariant(Variant variant,boolean end){
  List<Variant> variantList=new ArrayList<>();
  boolean noSplit=false;
  if (variant.getType() == VariantOverallType.SNP) {
    noSplit=true;
  }
  if (variant.getCompositions() == null && variant.getGoodPaternal() == 0 && variant.getGoodMaternal() == 0) {
    noSplit=true;
  }
  if (variant.getGoodPaternal() != 0 && !canonicalizableFlexSeqTypes.contains(variant.getAlt(variant.getGoodPaternal()).getSeqType())) {
    noSplit=true;
  }
  if (variant.getGoodMaternal() != 0 && !canonicalizableFlexSeqTypes.contains(variant.getAlt(variant.getGoodMaternal()).getSeqType())) {
    noSplit=true;
  }
  if (variant.getGoodPaternal() != 0 && variant.getAlt(variant.getGoodPaternal()).length() == 0 && variant.getReference().length == 0) {
    noSplit=true;
  }
  if (variant.getGoodMaternal() > 0 && variant.getAlt(variant.getGoodMaternal()).length() == 0 && variant.getReference().length == 0) {
    noSplit=true;
  }
  if (noSplit) {
    variantList.add(variant);
    return variantList;
  }
  if (variant.getCompositions() != null) {
    for (    Variant c : variant.getCompositions()) {
      variantList.addAll(canonicalizeVariant(new Variant(c),end));
    }
    return variantList;
  }
  Variant.Builder template=new Variant.Builder().chr(variant.getChr()).isPhased(true).varId(variant.getVariantId()).filter(VCFparser.DEFAULT_FILTER).refDeleted("String_Node_Str");
  if (variant.getType(variant.getGoodMaternal()) == VariantType.Translocation_Duplication || variant.getType(variant.getGoodMaternal()) == VariantType.Interspersed_Duplication || variant.getType(variant.getGoodPaternal()) == VariantType.Translocation_Duplication || variant.getType(variant.getGoodPaternal()) == VariantType.Interspersed_Duplication) {
    for (int parentIndex=0; parentIndex < 2; parentIndex++) {
      int allele=variant.getAllele(parentIndex);
      if (variant.getType(allele) == VariantType.Reference)       continue;
      byte[] phase=new byte[2];
      phase[parentIndex]=1;
      if (variant.getType(allele) == VariantType.Translocation_Duplication || variant.getType(allele) == VariantType.Interspersed_Duplication) {
        boolean isInversed=variant.isInversed();
        Alt alt1=new Alt();
        alt1.setBreakend(new Alt.Breakend(variant.getReference().clone(),variant.getChr2(allele),isInversed ? variant.getEnd2(allele) : variant.getPos2(allele),true,!isInversed));
        variantList.add(template.pos(variant.getPos() - 1).referenceAlleleLength(0).ref(new byte[]{'N'}).alts(new Alt[]{alt1}).phase(phase).build());
        Alt alt2=new Alt();
        alt2.setBreakend(new Alt.Breakend(ambiguousBase,variant.getChr2(parentIndex),isInversed ? variant.getPos2(parentIndex) : variant.getEnd2(parentIndex),false,isInversed));
        variantList.add(template.pos(variant.getPos()).referenceAlleleLength(0).ref(new byte[]{'N'}).alts(new Alt[]{alt2}).phase(phase).build());
      }
      variant.setAllele(parentIndex,(byte)0);
    }
  }
 else   if (variant.getType(variant.getGoodMaternal()) == VariantType.Translocation_Deletion || variant.getType(variant.getGoodPaternal()) == VariantType.Translocation_Deletion) {
    for (int parentIndex=0; parentIndex < 2; parentIndex++) {
      int allele=variant.getAllele(parentIndex);
      if (variant.getType(allele) == VariantType.Reference)       continue;
      byte[] phase=new byte[2];
      phase[parentIndex]=1;
      if (variant.getType(allele) == VariantType.Translocation_Deletion) {
        Alt alt1=new Alt();
        alt1.setBreakend(new Alt.Breakend(variant.getReference().clone(),variant.getChr(),variant.getPos() + variant.getReferenceAlleleLength(),true,true));
        variantList.add(template.pos(variant.getPos() - 1).referenceAlleleLength(0).ref(new byte[]{'N'}).alts(new Alt[]{alt1}).phase(phase).build());
      }
      variant.setAllele(parentIndex,(byte)0);
    }
  }
 else   if (variant.getType(variant.getGoodPaternal()) != VariantType.Reference && variant.getType(variant.getGoodMaternal()) != VariantType.Reference) {
    int[] alleleNumber={variant.getAllele(0),variant.getAllele(1)};
    byte[][] alternativeAlleleSequence={variant.getAlt(alleleNumber[0]).getSequence(),variant.getAlt(alleleNumber[1]).getSequence()};
    byte[] referenceAlleleSequence=variant.getReference();
    int currentPosition=variant.getPos();
    int minMatchLength=variant.getMinMatchLength();
    if (minMatchLength > 0) {
      referenceAlleleSequence=Arrays.copyOfRange(referenceAlleleSequence,minMatchLength,referenceAlleleSequence.length);
      for (int i=0; i < 2; i++) {
        alternativeAlleleSequence[i]=Arrays.copyOfRange(alternativeAlleleSequence[i],minMatchLength,alternativeAlleleSequence[i].length);
      }
      currentPosition+=minMatchLength;
    }
    int[] alleleLengthDifference={alternativeAlleleSequence[0].length - referenceAlleleSequence.length,alternativeAlleleSequence[1].length - referenceAlleleSequence.length};
    canonicalizeToIndels(variantList,alleleLengthDifference,referenceAlleleSequence,alternativeAlleleSequence,variant,currentPosition,end);
    for (int relativePosition=0; relativePosition < referenceAlleleSequence.length; relativePosition++, currentPosition++) {
      int[] alleleSpecificRelativePosition=new int[2];
      if (end) {
        for (int j=0; j < 2; j++) {
          if (relativePosition < referenceAlleleSequence.length + alleleLengthDifference[j]) {
            alleleSpecificRelativePosition[j]=relativePosition;
          }
 else {
            alleleSpecificRelativePosition[j]=-1;
          }
        }
      }
 else {
        for (int j=0; j < 2; j++) {
          alleleSpecificRelativePosition[j]=relativePosition + alleleLengthDifference[j];
        }
      }
      if (alleleSpecificRelativePosition[0] < 0 && alleleSpecificRelativePosition[1] < 0) {
      }
 else       if (alleleSpecificRelativePosition[0] >= 0 && alleleSpecificRelativePosition[1] < 0 && alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]] != referenceAlleleSequence[relativePosition]) {
        byte[] phase={1,1};
        Alt alt=new Alt();
        alt.setSeq(new FlexSeq(alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]]));
        variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceAlleleSequence[relativePosition]}).alts(new Alt[]{alt}).phase(phase).build());
      }
 else       if (alleleSpecificRelativePosition[0] < 0 && alleleSpecificRelativePosition[1] >= 0 && alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]] != referenceAlleleSequence[relativePosition]) {
        byte[] phase={1,1};
        Alt alt=new Alt();
        alt.setSeq(new FlexSeq(alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]]));
        variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceAlleleSequence[relativePosition]}).alts(new Alt[]{alt}).phase(phase).build());
      }
 else       if (alleleSpecificRelativePosition[0] >= 0 && alleleSpecificRelativePosition[1] < 0 && alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]] == referenceAlleleSequence[relativePosition]) {
      }
 else       if (alleleSpecificRelativePosition[0] < 0 && alleleSpecificRelativePosition[1] >= 0 && alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]] == referenceAlleleSequence[relativePosition]) {
      }
 else       if (alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]] == referenceAlleleSequence[relativePosition] && alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]] == referenceAlleleSequence[relativePosition]) {
      }
 else       if (alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]] == alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]]) {
        byte[] phase={1,1};
        Alt alt=new Alt();
        alt.setSeq(new FlexSeq(alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]]));
        variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceAlleleSequence[relativePosition]}).alts(new Alt[]{alt}).phase(phase).build());
      }
 else       if (alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]] != referenceAlleleSequence[relativePosition] && alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]] != referenceAlleleSequence[relativePosition]) {
        byte[] phase={1,2};
        Alt[] alts=new Alt[2];
        alts[0]=new Alt();
        alts[1]=new Alt();
        alts[0].setSeq(new FlexSeq(alternativeAlleleSequence[0][alleleSpecificRelativePosition[0]]));
        alts[1].setSeq(new FlexSeq(alternativeAlleleSequence[1][alleleSpecificRelativePosition[1]]));
        variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceAlleleSequence[relativePosition]}).alts(alts).phase(phase).build());
      }
 else {
        for (int a=0; a < 2; a++) {
          if (alternativeAlleleSequence[a][alleleSpecificRelativePosition[a]] != referenceAlleleSequence[relativePosition]) {
            byte[] phase={0,0};
            phase[a]=1;
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq(alternativeAlleleSequence[a][alleleSpecificRelativePosition[a]]));
            variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceAlleleSequence[relativePosition]}).alts(new Alt[]{alt}).phase(phase).build());
          }
        }
      }
    }
    variant.setAllele(0,(byte)0);
    variant.setAllele(1,(byte)0);
  }
 else {
    for (int alleleIndex=0; alleleIndex < 2; alleleIndex++) {
      int allele=variant.getAllele(alleleIndex);
      if (variant.getType(allele) == VariantType.Complex || variant.getType(allele) == VariantType.MNP || variant.getType(allele) == VariantType.SNP) {
        byte[] alternativeAlleleSequence=variant.getAlt(allele).getSequence();
        byte[] referenceSequence=variant.getReference();
        int currentPosition=variant.getPos();
        int alleleLengthDifference=alternativeAlleleSequence.length - referenceSequence.length;
        if (alleleLengthDifference > 0) {
          byte[] phase={0,0};
          phase[alleleIndex]=1;
          if (end) {
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq(Arrays.copyOfRange(alternativeAlleleSequence,0,alleleLengthDifference)));
            variantList.add(template.pos(currentPosition + referenceSequence.length).referenceAlleleLength(0).ref(new byte[]{'N'}).alts(new Alt[]{alt}).phase(phase).build());
          }
 else {
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq(Arrays.copyOfRange(alternativeAlleleSequence,0,alleleLengthDifference)));
            variantList.add(template.pos(currentPosition).referenceAlleleLength(0).ref(new byte[]{'N'}).alts(new Alt[]{alt}).phase(phase).build());
          }
        }
 else         if (alleleLengthDifference < 0) {
          byte[] phase={0,0};
          phase[alleleIndex]=1;
          if (end) {
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq());
            variantList.add(template.pos(currentPosition + alternativeAlleleSequence.length).referenceAlleleLength(-alleleLengthDifference).ref(Arrays.copyOfRange(referenceSequence,alternativeAlleleSequence.length,alternativeAlleleSequence.length - alleleLengthDifference)).alts(new Alt[]{alt}).phase(phase).build());
          }
 else {
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq());
            variantList.add(template.pos(currentPosition).referenceAlleleLength(-alleleLengthDifference).ref(Arrays.copyOfRange(referenceSequence,0,-alleleLengthDifference)).alts(new Alt[]{alt}).phase(phase).build());
          }
        }
        for (int i=0; i < referenceSequence.length; i++) {
          int idx;
          if (end) {
            if (i < referenceSequence.length + alleleLengthDifference) {
              idx=i;
            }
 else {
              idx=-1;
            }
          }
 else {
            idx=i + alleleLengthDifference;
          }
          if (idx >= 0 && alternativeAlleleSequence[idx] != referenceSequence[i]) {
            byte[] phase={0,0};
            phase[alleleIndex]=1;
            Alt alt=new Alt();
            alt.setSeq(new FlexSeq(alternativeAlleleSequence[idx]));
            variantList.add(template.pos(currentPosition).referenceAlleleLength(1).ref(new byte[]{referenceSequence[i]}).alts(new Alt[]{alt}).phase(phase).build());
          }
          currentPosition++;
        }
        variant.setAllele(alleleIndex,(byte)0);
      }
    }
  }
  if (!variant.isRef()) {
    variantList.add(variant);
  }
  return variantList;
}