Skip to content
Snippets Groups Projects
BamView.java 91.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • tjc's avatar
    tjc committed
      protected SAMRecordMapQPredicate getSamRecordMapQPredicate()
      {
        return samRecordMapQPredicate;
      }
    
      protected void setSamRecordMapQPredicate(
          SAMRecordMapQPredicate samRecordMapQPredicate)
      {
        laststart = -1;
        lastend = -1;
        this.samRecordMapQPredicate = samRecordMapQPredicate;
      }
      
    
      class PairedRead
      {
        SAMRecord sam1;
        SAMRecord sam2;
    
    tjc's avatar
    tjc committed
      public static void main(String[] args)
      {
    
    tjc's avatar
    tjc committed
        BamFrame frame = new BamFrame();
    
    tjc's avatar
    tjc committed
        
        if(args.length == 0 && BamFrame.isMac())
        {
          try
          {
            Thread.sleep(1000);
          }
          catch (InterruptedException e1) {}
    
    tjc's avatar
    tjc committed
          if(frame.getBamFile() != null)
    
    tjc's avatar
    tjc committed
            args = new String[]{ frame.getBamFile() };
        }
    
    tjc's avatar
    tjc committed
          
        List<String> bam = new Vector<String>();
    
    tjc's avatar
    tjc committed
        String reference = null;
    
        if(args.length == 0)
        {
    
    tjc's avatar
    tjc committed
          System.setProperty("default_directory", System.getProperty("user.dir"));
    
          FileSelectionDialog fileSelection = new FileSelectionDialog(
              null, true, "BamView", "BAM");
    
          bam = fileSelection.getFiles(".*\\.bam$");
    
          reference = fileSelection.getReferenceFile();
          if(reference == null || reference.equals(""))
            reference = null;
    
    tjc's avatar
    tjc committed
          
          if(bam == null || bam.size() < 1)
    
          {
            System.err.println("No files found.");
    
    tjc's avatar
    tjc committed
            System.exit(0);
    
        else if(!args[0].startsWith("-"))
        {
          for(int i=0; i< args.length; i++)
            bam.add(args[i]);
        }
    
        int nbasesInView = 1000;
    
    
    tjc's avatar
    tjc committed
        for(int i=0;i<args.length; i++)
        {
          if(args[i].equals("-a"))
    
          {
            while(i < args.length-1 && !args[++i].startsWith("-"))
    
            {
              String filename = args[i];
              if(FileSelectionDialog.isListOfFiles(filename))
                bam.addAll(FileSelectionDialog.getListOfFiles(filename));
              else
                bam.add(filename);
            }
    
    tjc's avatar
    tjc committed
          else if(args[i].equals("-r"))
            reference = args[++i];
          else if(args[i].equals("-v"))
            nbasesInView = Integer.parseInt(args[++i]);
          else if(args[i].equals("-s"))
            System.setProperty("samtoolDir", args[++i]);
          else if(args[i].startsWith("-h"))
          { 
            System.out.println("-h\t show help");
            
            System.out.println("-a\t BAM/SAM file to display");
            System.out.println("-r\t reference file (optional)");
            System.out.println("-v\t number of bases to display in the view (optional)");
    
            /*System.out.println("-s\t samtool directory");*/
    
    tjc's avatar
    tjc committed
    
            System.exit(0);
          }
        }
    
    
        final BamView view = new BamView(bam, reference, nbasesInView);
    
    tjc's avatar
    tjc committed
        frame.setTitle("BamView v"+view.getVersion());
    
    tjc's avatar
    tjc committed
        
    
        // translucent
        //frame.getRootPane().putClientProperty("Window.alpha", new Float(0.9f));
    
    
    tjc's avatar
    tjc committed
        frame.addWindowFocusListener(new WindowFocusListener()
        {
          public void windowGainedFocus(WindowEvent e)
          {
            view.requestFocus();
          }
          public void windowLostFocus(WindowEvent e){}
        });
        
    
    tjc's avatar
    tjc committed
        view.addJamToPanel((JPanel)frame.getContentPane(), frame, false, null);
    
    tjc's avatar
    tjc committed
        frame.pack();
    
    tjc's avatar
    tjc committed
        view.jspView.getVerticalScrollBar().setValue(
            view.jspView.getVerticalScrollBar().getMaximum());
    
        frame.setVisible(true);
    
    tjc's avatar
    tjc committed
      }
    }