Program: 80629
Project: 80629
Buggy source:
/** 
 * This is the main function that makes the diploid genome for each chromosome/sequence, all variants are traversed. Each variant is decomposed into a combination of deletion and insertion. Original sequence is flagged at variant loci. Perturbed sequences will be generated based on these flags. Map file format (MFF) records will generated by iterating over flag array of each sequence. VCFs (one for each sequence) containing all sampled variants will be generated as well with optional phasing information (if both maternal and paternal genomes are chosen for output).
 */
public void makeDiploid(){
}

Fixed version (ground truth):
/** 
 * This is the main function that makes the diploid genome for each chromosome/sequence, all variants are traversed. Each variant is decomposed into a combination of deletion and insertion. Original sequence is flagged at variant loci. Perturbed sequences will be generated based on these flags. Map file format (MFF) records will generated by iterating over flag array of each sequence. VCFs (one for each sequence) containing all sampled variants will be generated as well with optional phasing information (if both maternal and paternal genomes are chosen for output).
 */
public void makeDiploid(){
  StringBuilder map_string=new StringBuilder();
  SimpleReference allSequences=new SimpleReference(chrfiles);
  for (  ChrString chr : allSequences.keySet()) {
    Sequence referenceSequence=allSequences.getSequence(chr);
    System.out.println("String_Node_Str" + referenceSequence.getName() + "String_Node_Str");
    boolean output_paternal=true;
    boolean output_maternal=true;
    if (gender == GenderType.FEMALE) {
      if (chr.isY()) {
        output_paternal=false;
        output_maternal=false;
      }
    }
 else     if (gender == GenderType.MALE) {
      if (chr.isX()) {
        output_paternal=false;
      }
      if (chr.isY()) {
        output_maternal=false;
      }
    }
    if (chr.isMT()) {
      output_paternal=false;
    }
    if (!output_paternal && !output_maternal) {
      continue;
    }
    final List<Variant> varList=variants.containsKey(chr) ? variants.get(chr) : Collections.EMPTY_LIST;
    final List<Boolean> maternalIsVariantAdded=new ArrayList<>();
    final List<Boolean> paternalIsVariantAdded=new ArrayList<>();
    int len=referenceSequence.length();
    byte[] maternalSequence=new byte[len];
    byte[] paternalSequence=new byte[len];
    for (int c=1; c <= len; c++) {
      maternalSequence[c - 1]=paternalSequence[c - 1]=referenceSequence.byteAt(c);
    }
    Hashtable<Integer,FlexSeq> paternalInsertionSeq=new Hashtable<>(150);
    Hashtable<Integer,FlexSeq> maternalInsertionSeq=new Hashtable<>(150);
    int nPaternalVariant=0, nMaternalVariant=0;
    int nPaternalVariantBase=0, nMaternalVariantBase=0;
    for (    Variant var : varList) {
      if (!var.isPhased()) {
        var.randomizeHaplotype();
      }
      if (var.paternal() > 0) {
        if (addVariant(paternalSequence,referenceSequence,var,var.paternal(),paternalInsertionSeq)) {
          nPaternalVariant++;
          nPaternalVariantBase+=var.variantBases();
          paternalIsVariantAdded.add(true);
        }
 else {
          paternalIsVariantAdded.add(false);
        }
      }
 else {
        paternalIsVariantAdded.add(false);
      }
      if (var.maternal() > 0) {
        if (addVariant(maternalSequence,referenceSequence,var,var.maternal(),maternalInsertionSeq)) {
          nMaternalVariant++;
          nMaternalVariantBase+=var.variantBases();
          maternalIsVariantAdded.add(true);
        }
 else {
          maternalIsVariantAdded.add(false);
        }
      }
 else {
        maternalIsVariantAdded.add(false);
      }
    }
    log.info("String_Node_Str" + varList.size());
    writeVCF(referenceSequence,varList,paternalIsVariantAdded,maternalIsVariantAdded,output_paternal,output_maternal);
    if (output_paternal) {
      String paternalSequenceName=referenceSequence.getName() + "String_Node_Str" + DIPLOID_CHRS[1];
      String paternalSequenceFileName=referenceSequence.getName() + "String_Node_Str" + id+ "String_Node_Str"+ DIPLOID_CHRS[1]+ "String_Node_Str";
      makePosMap(map_string,paternalSequenceName,referenceSequence,paternalSequence,paternalInsertionSeq);
      writeHaploid(paternalSequence,paternalInsertionSeq,paternalSequenceName,paternalSequenceFileName);
      System.out.println("String_Node_Str" + nPaternalVariant + "String_Node_Str"+ nPaternalVariantBase+ "String_Node_Str"+ "String_Node_Str");
    }
    if (output_maternal) {
      String maternalSequenceName=referenceSequence.getName() + "String_Node_Str" + DIPLOID_CHRS[0];
      String maternalSequenceFileName=referenceSequence.getName() + "String_Node_Str" + id+ "String_Node_Str"+ DIPLOID_CHRS[0]+ "String_Node_Str";
      makePosMap(map_string,maternalSequenceName,referenceSequence,maternalSequence,maternalInsertionSeq);
      writeHaploid(maternalSequence,maternalInsertionSeq,maternalSequenceName,maternalSequenceFileName);
      System.out.println("String_Node_Str" + nMaternalVariant + "String_Node_Str"+ nMaternalVariantBase+ "String_Node_Str"+ "String_Node_Str");
    }
  }
  try {
    FileWriter fw=new FileWriter(new File(outDir,id + "String_Node_Str"));
    BufferedWriter bw=new BufferedWriter(fw);
    bw.write(map_string.toString());
    bw.newLine();
    bw.close();
    fw.close();
    outputMap=new File(outDir,id + "String_Node_Str");
  }
 catch (  IOException ex) {
    log.error(ex.toString());
  }
}