@Override
    public int compare(String o1, String o2) {
      if (Extractors.isHeaderLine(o1)) {
        return -1;
      } else if (Extractors.isHeaderLine(o2)) {
        return 1;
      }

      String[] splitLine1 = Utils.splitWithTab(o1);
      String[] splitLine2 = Utils.splitWithTab(o2);
      int cmp;
      try {
        cmp =
            chromosomeComparator.compareChromosomeName(
                splitLine1[chromoFieldIndex], splitLine2[chromoFieldIndex]);
      } catch (Exception e) {
        // if the chromosome comparator doesn't work we use a string cpmparator
        cmp =
            new StringComparator()
                .compare(splitLine1[chromoFieldIndex], splitLine2[chromoFieldIndex]);
      }
      // if the chromosomes are equals we compare the positions
      if (cmp == 0) {
        try {
          ChromosomeWindow cw1 =
              new SimpleChromosomeWindow(splitLine1[startFieldIndex], splitLine1[stopFieldIndex]);
          ChromosomeWindow cw2 =
              new SimpleChromosomeWindow(splitLine2[startFieldIndex], splitLine2[stopFieldIndex]);
          cmp = cw1.compareTo(cw2);
        } catch (Exception e) {
          new StringComparator().compare(splitLine1[startFieldIndex], splitLine2[startFieldIndex]);
        }
      }
      return cmp;
    }
 /**
  * @param inputFile input file
  * @return a new File with prefix ".sorted" added before the extension
  */
 public static File generateOutputFile(File inputFile) {
   String extension = Utils.getExtension(inputFile);
   String nameWithoutExtension = Utils.getFileNameWithoutExtension(inputFile);
   String newFileName = nameWithoutExtension + ".sorted." + extension;
   File parentDirectory = inputFile.getParentFile();
   return new File(parentDirectory, newFileName);
 }
 /**
  * @param inputFile
  * @return a string comparator adapted that compares the lines of the input file
  * @throws InvalidParameterException
  */
 private static Comparator<String> generateComparator(File inputFile)
     throws InvalidParameterException {
   String fileExtension = Utils.getExtension(inputFile);
   if (fileExtension == null) {
     throw new InvalidParameterException(
         "Cannot sort the specified file: "
             + inputFile.getName()
             + "\n"
             + "Files without extension are not recognized by the sorting function");
   } else if (fileExtension.equalsIgnoreCase("gff")) {
     return new GenomicFileLineComparator(0, 3, 4);
   } else if (fileExtension.equalsIgnoreCase("gr")) {
     return new GenomicFileLineComparator(0, 1, 2);
   } else if (fileExtension.equalsIgnoreCase("bed")) {
     return new GenomicFileLineComparator(0, 1, 2);
   } else if (fileExtension.equalsIgnoreCase("bgr")) {
     return new GenomicFileLineComparator(0, 1, 2);
   } else if (fileExtension.equalsIgnoreCase("pair")) {
     return new GenomicFileLineComparator(0, 4, 4);
   } else if (fileExtension.equalsIgnoreCase("psl")) {
     return new GenomicFileLineComparator(13, 15, 16);
   } else if (fileExtension.equalsIgnoreCase("sam")) {
     return new GenomicFileLineComparator(0, 3, 3);
   } else {
     throw new InvalidParameterException(
         "Cannot sort the specified file: "
             + inputFile.getName()
             + "\n"
             + "Files with "
             + fileExtension
             + " extension are not recognized by the sorting function");
   }
 }
 /**
  * Sorts a genomic file per chromosome, start and then stop position
  *
  * @param inputFile
  * @throws IOException
  */
 public static void externalSortGenomicFile(File inputFile) throws IOException {
   Comparator<String> comparator = generateComparator(inputFile);
   int maxTmpFiles = ExternalSort.DEFAULTMAXTEMPFILES;
   Charset charset = Charset.defaultCharset();
   File tmpDir = new File(Utils.getTmpDirectoryPath());
   File outputFile = generateOutputFile(inputFile);
   List<File> l =
       ExternalSort.sortInBatch(
           inputFile, comparator, maxTmpFiles, charset, tmpDir, false, 0, false);
   ExternalSort.mergeSortedFiles(l, outputFile, comparator, charset, false, false, false);
 }
Beispiel #5
0
 private void setTrackLock(boolean lock) {
   // Update tracks
   LayerType[] filter = {LayerType.VARIANT_LAYER};
   List<Layer<?>> allLayers =
       MainFrame.getInstance().getTrackListPanel().getModel().getAllLayers();
   List<Layer<?>> layers = Utils.getLayers(allLayers, filter);
   for (Layer<?> layer : layers) {
     if (lock) {
       ((VariantLayer) layer).getGenomeDrawer().lockPainting();
     } else {
       ((VariantLayer) layer).getGenomeDrawer().unlockPainting();
     }
   }
 }
Beispiel #6
0
    @Override
    public void run() {
      // Lock the painting
      setTrackLock(true);

      // Create and start the filter thread
      FilterThread filterThread = new FilterThread();
      filterThread.setPreviousFilterList(previousFilterList);
      if (filterThread.hasToBeStarted()) {
        CountDownLatch filterLatch = new CountDownLatch(1);
        filterThread.setLatch(filterLatch);
        filterThread.start();

        // The current thread is waiting for the filter thread to finish
        try {
          filterLatch.await();
        } catch (InterruptedException e) {
          ExceptionManager.getInstance().caughtException(e);
        }
      }

      // Update tracks
      TrackThread trackThread = new TrackThread();
      CountDownLatch trackLatch = new CountDownLatch(1); // one for the track update action
      trackThread.setLatch(trackLatch);
      trackThread.start();

      // The current thread is waiting for the filter thread to finish
      try {
        trackLatch.await();
      } catch (InterruptedException e) {
        ExceptionManager.getInstance().caughtException(e);
      }

      // Many data has been loaded, removed, garbage collecting free some memory
      Utils.garbageCollect();

      // Unlock the painting and force the repaint
      setTrackLock(false);
      repaintTrack();
    }