Class XNucleobaseCounting

java.lang.Object
tnx.lab.executor.XNucleobaseCounting

public class XNucleobaseCounting extends Object
A parallel nucleobase counter that uses Java's ExecutorService interface to count different sections of the chromosome in parallel.
Author:
__STUDENT_NAME__, Finn Voichick
  • Constructor Details

    • XNucleobaseCounting

      public XNucleobaseCounting()
  • Method Details

    • countLowerUpperSplit

      public static int countLowerUpperSplit​(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase) throws InterruptedException, ExecutionException
      Should count all of the instances of a specific nucleobase in parallel. The chromosome should be split into two halves, and the "lower" half should be counted in parallel with the "upper" half.
      Parameters:
      executor - an ExecutorService that you should use to submit tasks
      chromosome - the chromosome to examine, represented as an array of bytes
      nucleobase - the nucleobase to look for in the chromosome
      Returns:
      the total number of times that the given nucleobase occurs in the given chromosome
      Throws:
      InterruptedException - if the computation was cancelled
      ExecutionException - if the computation threw an exception
    • countNWaySplit

      public static int countNWaySplit​(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int numTasks) throws InterruptedException, ExecutionException
      Should asynchronously count all of the instances of a specific nucleobase, creating the given number of tasks. For example, if numTasks is 8, the chromosome should be divided into 8 slices, and each slice should be counted in a separate task. NOTE: You are required to use the ExecutorService.invokeAll(Collection) method for this part of the assignment.
      Parameters:
      executor - an ExecutorService that you should use to invoke tasks
      chromosome - the chromosome to examine, represented as an array of bytes
      nucleobase - the nucleobase to look for in the chromosome
      numTasks - the number of tasks to create
      Returns:
      the total number of times that the given nucleobase occurs in the given chromosome
      Throws:
      InterruptedException - if the computation was cancelled
      ExecutionException - if the computation threw an exception
    • countDivideAndConquer

      public static int countDivideAndConquer​(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, IntPredicate isParallelPredicate) throws InterruptedException, ExecutionException
      Should use a divide-and-conquer approach to count all of the instances of a specific nucleobase.
      Parameters:
      executor - an ExecutorService that you should use to submit tasks
      chromosome - the chromosome to examine, represented as an array of bytes
      nucleobase - the nucleobase to look for in the chromosome
      isParallelPredicate - Predicate whose test method will return whether or not the current range length is large enough to justify running in parallel.
      Returns:
      the total number of times that the given nucleobase occurs in the given chromosome
      Throws:
      InterruptedException - if the computation was cancelled
      ExecutionException - if the computation threw an exception