Beispiel #1
0
 public boolean isLocal() {
   return dbURL == null && !FileUtils.isRemote(path) && !Ga4ghAPIHelper.RESOURCE_TYPE.equals(type);
 }
Beispiel #2
0
  private void loadAlignmentsTrack(ResourceLocator locator, List<Track> newTracks, Genome genome)
      throws IOException {

    try {
      String dsName = locator.getTrackName();

      // If the user tried to load the index,  look for the file (this is a common mistake)
      if (locator.getTypeString().endsWith(".sai") || locator.getTypeString().endsWith(".bai")) {
        MessageUtils.showMessage(
            "<html><b>ERROR:</b> Loading SAM/BAM index files are not supported:  "
                + locator.getPath()
                + "<br>Load the SAM or BAM file directly. ");
        return;
      }

      AlignmentDataManager dataManager = new AlignmentDataManager(locator, genome);

      // Check that alignments we loaded actually match some data.  Many BAM files will contain some
      // sequences
      // not represented in the genome, buf if there are no matches warn the user.
      List<String> seqNames = dataManager.getSequenceNames();
      if (seqNames != null && seqNames.size() > 0) {
        if (!checkSequenceNames(locator.getPath(), genome, seqNames)) {
          return;
        }
      }

      if (locator.getTypeString().endsWith("bam") || locator.getTypeString().endsWith("cram")) {
        if (!dataManager.hasIndex()) {
          MessageUtils.showMessage(
              "<html>Could not load index file for: "
                  + locator.getPath()
                  + "<br>  An index file is required for SAM & BAM files.");
          return;
        }
      }

      AlignmentTrack alignmentTrack =
          new AlignmentTrack(locator, dataManager, genome); // parser.loadTrack(locator, dsName);
      alignmentTrack.setName(dsName);
      alignmentTrack.setVisible(
          PreferenceManager.getInstance().getAsBoolean(PreferenceManager.SAM_SHOW_ALIGNMENT_TRACK));

      // Create coverage track
      CoverageTrack covTrack =
          new CoverageTrack(locator, dsName + " Coverage", alignmentTrack, genome);
      covTrack.setVisible(
          PreferenceManager.getInstance().getAsBoolean(PreferenceManager.SAM_SHOW_COV_TRACK));
      newTracks.add(covTrack);
      covTrack.setDataManager(dataManager);
      dataManager.setCoverageTrack(covTrack);

      alignmentTrack.setCoverageTrack(covTrack);

      // Search for precalculated coverage data
      // Skip for GA4GH & SU2C resources
      if (!(Ga4ghAPIHelper.RESOURCE_TYPE.equals(locator.getType())
          || locator.getPath().contains("dataformat=.bam")
          || OAuthUtils.isGoogleCloud(locator.getPath()))) {

        String covPath = locator.getCoverage();
        if (covPath == null) {
          boolean bypassFileAutoDiscovery =
              PreferenceManager.getInstance()
                  .getAsBoolean(PreferenceManager.BYPASS_FILE_AUTO_DISCOVERY);
          String path = locator.getPath();
          if (!bypassFileAutoDiscovery && !path.contains("/query.cgi?")) {
            covPath = path + ".tdf";
          }
        }
        if (covPath != null) {
          if (FileUtils.resourceExists(covPath)) {
            log.debug("Loading TDF for coverage: " + covPath);
            try {
              TDFReader reader = TDFReader.getReader(covPath);
              TDFDataSource ds = new TDFDataSource(reader, 0, dsName + " coverage", genome);
              covTrack.setDataSource(ds);
            } catch (Exception e) {
              log.error("Error loading coverage TDF file", e);
            }
          }
        }
      }

      boolean showSpliceJunctionTrack =
          PreferenceManager.getInstance().getAsBoolean(PreferenceManager.SAM_SHOW_JUNCTION_TRACK);

      SpliceJunctionTrack spliceJunctionTrack =
          new SpliceJunctionTrack(
              locator,
              dsName + " Junctions",
              dataManager,
              alignmentTrack,
              SpliceJunctionTrack.StrandOption.BOTH);
      spliceJunctionTrack.setHeight(60);
      spliceJunctionTrack.setVisible(showSpliceJunctionTrack);
      newTracks.add(spliceJunctionTrack);

      alignmentTrack.setSpliceJunctionTrack(spliceJunctionTrack);

      newTracks.add(alignmentTrack);

      log.debug("Alignment track loaded");

    } catch (IndexNotFoundException e) {
      MessageUtils.showMessage(
          "<html>Could not find the index file for  <br><br>&nbsp;&nbsp;"
              + e.getSamFile()
              + "<br><br>Note: The index file can be created using igvtools and must be in the same directory as the .sam file.");
    }
  }