Program: 38100
Project: 38100
Buggy source:
/** 
 * This method might be deleted or edited to be the new procedure. Work in progress atm with Adam
 * @param params Bowtie parameters
 * @param fastqFile The raw file which is to be processed.
 * @param sgrFile The name of the output file produced
 * @param keepSam Boolean telling whether intermediate .sam file should besaved.
 * @param genomeVersion Version of genome, not used at the moment.
 * @param referenceGenome Path to reference genome.
 * @param filepathRaw File path to experiment raw file directory
 * @param filepathProfile File path to experiment profile file directory
 * @return Processed files to save to database.
 * @throws ProcessException
 */
public static File[] procedureRaw(String params,String fastqFile,String sgrFile,boolean keepSam,boolean removeDups,String genomeVersion,String referenceGenome,String filepathRaw,String filepathProfile) throws ProcessException, InterruptedException, IOException {
  ArrayList<File> returnFiles=new ArrayList<>();
  new File(filepathProfile).mkdirs();
  Stack<String> toBeRemoved=new Stack<>();
  Stack<Map.Entry<String,String>> filesToSaveToExperiment=new Stack<>();
  String tmpDirPath=tempFolder + "String_Node_Str" + Thread.currentThread().getId()+ "String_Node_Str";
  createDirectory(tmpDirPath);
  filepathRaw=fixEndOfPath(filepathRaw);
  filepathProfile=fixEndOfPath(filepathProfile);
  fastqFile=filepathRaw + fastqFile;
  String samFile=tmpDirPath + FilenameUtils.getBaseName(sgrFile) + "String_Node_Str";
  String sortedSam=FilenameUtils.removeExtension(samFile) + "String_Node_Str";
  String sortedSamWithoutDups=FilenameUtils.removeExtension(samFile) + "String_Node_Str";
  ErrorLogger.log("String_Node_Str","String_Node_Str");
  Bowtie2 bowtieProcess=new Bowtie2(referenceGenome,null,null,fastqFile,samFile,params.split("String_Node_Str"));
  try {
    bowtieProcess.validate();
  }
 catch (  ValidateException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str" + "String_Node_Str" + bowtieProcess.toString() + "String_Node_Str");
    throw new ProcessException(e);
  }
  String bowtieReturnMessage="String_Node_Str";
  try {
    bowtieReturnMessage=bowtieProcess.execute();
    ErrorLogger.log("String_Node_Str","String_Node_Str");
  }
 catch (  InterruptedException|IOException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str" + "String_Node_Str" + bowtieReturnMessage + "String_Node_Str");
    throw e;
  }
  try {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    Picard.runSortSam(samFile,sortedSam);
    toBeRemoved.push(samFile);
    ErrorLogger.log("String_Node_Str","String_Node_Str");
  }
 catch (  ValidateException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    throw new ProcessException(e);
  }
catch (  InterruptedException|IOException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str" + e.getMessage());
    throw e;
  }
  if (removeDups) {
    try {
      ErrorLogger.log("String_Node_Str","String_Node_Str");
      Picard.runRemoveDuplicates(sortedSam,sortedSamWithoutDups);
      ErrorLogger.log("String_Node_Str","String_Node_Str");
      toBeRemoved.push(sortedSam);
    }
 catch (    ValidateException e) {
      ErrorLogger.log("String_Node_Str","String_Node_Str");
      throw new ProcessException(e);
    }
catch (    IOException|InterruptedException e) {
      ErrorLogger.log("String_Node_Str","String_Node_Str");
      ErrorLogger.log("String_Node_Str",e.getMessage());
      throw e;
    }
  }
 else {
    sortedSamWithoutDups=sortedSam;
  }
  try {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    Pyicos.runConvert(sortedSamWithoutDups,tmpDirPath + FilenameUtils.getBaseName(sgrFile) + "String_Node_Str");
    ErrorLogger.log("String_Node_Str","String_Node_Str");
  }
 catch (  ValidateException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    ErrorLogger.log("String_Node_Str",e.getMessage());
    throw new ProcessException(e);
  }
catch (  InterruptedException|IOException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    throw e;
  }
  ErrorLogger.log("String_Node_Str","String_Node_Str");
  ProfileDataConverter pdc=new ProfileDataConverter();
  String testSgrFile=pdc.wigToSgr("String_Node_Str",tmpDirPath + FilenameUtils.getBaseName(sgrFile) + "String_Node_Str");
  ErrorLogger.log("String_Node_Str","String_Node_Str" + testSgrFile + "String_Node_Str"+ sgrFile);
  filesToSaveToExperiment.push(new AbstractMap.SimpleEntry<>(sgrFile,filepathProfile + FilenameUtils.getName(sgrFile)));
  if (keepSam) {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    filesToSaveToExperiment.push(new AbstractMap.SimpleEntry<>(sortedSamWithoutDups,filepathProfile + FilenameUtils.getName(sortedSamWithoutDups)));
  }
 else {
    toBeRemoved.push(sortedSamWithoutDups);
  }
  ErrorLogger.log("String_Node_Str","String_Node_Str");
  ErrorLogger.log("String_Node_Str","String_Node_Str" + filepathProfile + "String_Node_Str");
  for (  Map.Entry<String,String> filePair : filesToSaveToExperiment) {
    try {
      Debug.log("String_Node_Str" + filePair.getKey());
      Files.move(Paths.get(filePair.getKey()),Paths.get(filePair.getValue()));
      returnFiles.add(new File(filePair.getValue()));
    }
 catch (    IOException e) {
      ErrorLogger.log("String_Node_Str","String_Node_Str" + "String_Node_Str" + filePair + "String_Node_Str"+ filepathProfile);
      throw e;
    }
  }
  for (  String fileName : toBeRemoved) {
    File file=new File(fileName);
    Debug.log("String_Node_Str" + file.getCanonicalPath());
    file.delete();
  }
  return returnFiles.toArray(new File[returnFiles.size()]);
}

Fixed version (ground truth):
/** 
 * This method might be deleted or edited to be the new procedure. Work in progress atm with Adam
 * @param params Bowtie parameters
 * @param fastqFile The raw file which is to be processed.
 * @param sgrFile The name of the output file produced
 * @param keepSam Boolean telling whether intermediate .sam file should besaved.
 * @param genomeVersion Version of genome, not used at the moment.
 * @param referenceGenome Path to reference genome.
 * @param filepathRaw File path to experiment raw file directory
 * @param filepathProfile File path to experiment profile file directory
 * @return Processed files to save to database.
 * @throws ProcessException
 */
public static File[] procedureRaw(String params,String fastqFile,String sgrFile,boolean keepSam,boolean removeDups,String genomeVersion,String referenceGenome,String filepathRaw,String filepathProfile) throws ProcessException, InterruptedException, IOException {
  ArrayList<File> returnFiles=new ArrayList<>();
  new File(filepathProfile).mkdirs();
  Stack<String> toBeRemoved=new Stack<>();
  Stack<Map.Entry<String,String>> filesToSaveToExperiment=new Stack<>();
  String tmpDirPath=tempFolder + "String_Node_Str" + Thread.currentThread().getId()+ "String_Node_Str";
  createDirectory(tmpDirPath);
  filepathRaw=fixEndOfPath(filepathRaw);
  filepathProfile=fixEndOfPath(filepathProfile);
  fastqFile=filepathRaw + fastqFile;
  String samFile=tmpDirPath + FilenameUtils.getBaseName(sgrFile) + "String_Node_Str";
  String sortedSam=FilenameUtils.removeExtension(samFile) + "String_Node_Str";
  String sortedSamWithoutDups=FilenameUtils.removeExtension(samFile) + "String_Node_Str";
  ErrorLogger.log("String_Node_Str","String_Node_Str");
  Bowtie2 bowtieProcess=new Bowtie2(referenceGenome,null,null,fastqFile,samFile,params.split("String_Node_Str"));
  try {
    bowtieProcess.validate();
  }
 catch (  ValidateException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str" + "String_Node_Str" + bowtieProcess.toString() + "String_Node_Str");
    throw new ProcessException(e);
  }
  String bowtieReturnMessage="String_Node_Str";
  try {
    bowtieReturnMessage=bowtieProcess.execute();
    ErrorLogger.log("String_Node_Str","String_Node_Str");
  }
 catch (  InterruptedException|IOException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str" + "String_Node_Str" + bowtieReturnMessage + "String_Node_Str");
    throw e;
  }
  try {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    Picard.runSortSam(samFile,sortedSam);
    toBeRemoved.push(samFile);
    ErrorLogger.log("String_Node_Str","String_Node_Str");
  }
 catch (  ValidateException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    throw new ProcessException(e);
  }
catch (  InterruptedException|IOException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str" + e.getMessage());
    throw e;
  }
  if (removeDups) {
    try {
      ErrorLogger.log("String_Node_Str","String_Node_Str");
      Picard.runRemoveDuplicates(sortedSam,sortedSamWithoutDups);
      ErrorLogger.log("String_Node_Str","String_Node_Str");
      toBeRemoved.push(sortedSam);
    }
 catch (    ValidateException e) {
      ErrorLogger.log("String_Node_Str","String_Node_Str");
      throw new ProcessException(e);
    }
catch (    IOException|InterruptedException e) {
      ErrorLogger.log("String_Node_Str","String_Node_Str");
      ErrorLogger.log("String_Node_Str",e.getMessage());
      throw e;
    }
  }
 else {
    sortedSamWithoutDups=sortedSam;
  }
  try {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    Pyicos.runConvert(sortedSamWithoutDups,tmpDirPath + FilenameUtils.getBaseName(sgrFile) + "String_Node_Str");
    ErrorLogger.log("String_Node_Str","String_Node_Str");
  }
 catch (  ValidateException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    ErrorLogger.log("String_Node_Str",e.getMessage());
    throw new ProcessException(e);
  }
catch (  InterruptedException|IOException e) {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    throw e;
  }
  ErrorLogger.log("String_Node_Str","String_Node_Str");
  ProfileDataConverter pdc=new ProfileDataConverter();
  String testSgrFile=pdc.wigToSgr("String_Node_Str",tmpDirPath + FilenameUtils.getBaseName(sgrFile) + "String_Node_Str");
  ErrorLogger.log("String_Node_Str","String_Node_Str" + testSgrFile + "String_Node_Str"+ sgrFile);
  filesToSaveToExperiment.push(new AbstractMap.SimpleEntry<>(tmpDirPath + sgrFile,filepathProfile + FilenameUtils.getName(sgrFile)));
  if (keepSam) {
    ErrorLogger.log("String_Node_Str","String_Node_Str");
    filesToSaveToExperiment.push(new AbstractMap.SimpleEntry<>(sortedSamWithoutDups,filepathProfile + FilenameUtils.getName(sortedSamWithoutDups)));
  }
 else {
    toBeRemoved.push(sortedSamWithoutDups);
  }
  ErrorLogger.log("String_Node_Str","String_Node_Str");
  ErrorLogger.log("String_Node_Str","String_Node_Str" + filepathProfile + "String_Node_Str");
  for (  Map.Entry<String,String> filePair : filesToSaveToExperiment) {
    try {
      Debug.log("String_Node_Str" + filePair.getKey());
      Files.move(Paths.get(filePair.getKey()),Paths.get(filePair.getValue()));
      returnFiles.add(new File(filePair.getValue()));
    }
 catch (    IOException e) {
      ErrorLogger.log("String_Node_Str","String_Node_Str" + "String_Node_Str" + filePair + "String_Node_Str"+ filepathProfile);
      throw e;
    }
  }
  for (  String fileName : toBeRemoved) {
    File file=new File(fileName);
    Debug.log("String_Node_Str" + file.getCanonicalPath());
    file.delete();
  }
  return returnFiles.toArray(new File[returnFiles.size()]);
}