Skip to content
Snippets Groups Projects
BamView.java 93.4 KiB
Newer Older
  • Learn to ignore specific revisions
  •            !mouseOverSAMRecord.getMateUnmappedFlag() )
            {
              final SAMRecord thisSAMRecord = mouseOverSAMRecord;
              gotoMateMenuItem = new JMenuItem("Go to mate of : "+
                  thisSAMRecord.getReadName());
              gotoMateMenuItem.addActionListener(new ActionListener()
              {
    			public void actionPerformed(ActionEvent e) 
    			{
    			  String name = thisSAMRecord.getMateReferenceName();
    			  if(name.equals("="))
    			    name = thisSAMRecord.getReferenceName();
    			  int offset = getSequenceOffset(name);
    			  if(feature_display != null)
    			    feature_display.makeBaseVisible(
    			        thisSAMRecord.getMateAlignmentStart()+offset);
    			  else
    			    scrollBar.setValue(
    			        thisSAMRecord.getMateAlignmentStart()+offset-
    			        (nbasesInView/2));
    			  
    			  highlightSAMRecord = thisSAMRecord; 
    			}  
              });
              popup.add(gotoMateMenuItem);
    
            }  
              
            if( mouseOverSAMRecord != null)
            {
              final SAMRecord thisSAMRecord = mouseOverSAMRecord;
              showDetails = new JMenuItem("Show details of : "+
                  thisSAMRecord.getReadName());
              showDetails.addActionListener(new ActionListener()
              {
                public void actionPerformed(ActionEvent e) 
                {
                  FileViewer viewDetail = new FileViewer(thisSAMRecord.getReadName(), true, false);
                  appendToDetailView(thisSAMRecord, viewDetail);
                }  
              });
              popup.add(showDetails);
    
            popup.show(e.getComponent(),
                    e.getX(), e.getY());
    
    tjc's avatar
    tjc committed
          }
    
      private void appendToDetailView(SAMRecord thisSAMRecord, FileViewer viewDetail)
      {
        viewDetail.appendString("Read Name             "+thisSAMRecord.getReadName()+"\n", Level.INFO);
        viewDetail.appendString("Coordinates           "+thisSAMRecord.getAlignmentStart()+".."+
                                                         thisSAMRecord.getAlignmentEnd()+"\n", Level.DEBUG);
        viewDetail.appendString("Length                "+thisSAMRecord.getReadLength()+"\n", Level.DEBUG);
        viewDetail.appendString("Reference Name        "+thisSAMRecord.getReferenceName()+"\n", Level.DEBUG);
        viewDetail.appendString("Inferred Size         "+thisSAMRecord.getInferredInsertSize()+"\n", Level.DEBUG);
    
    tjc's avatar
    tjc committed
        viewDetail.appendString("Mapping Quality       "+thisSAMRecord.getMappingQuality()+"\n", Level.DEBUG);
    
    tjc's avatar
    tjc committed
        if(thisSAMRecord.getReadPairedFlag() && thisSAMRecord.getProperPairFlag() && !thisSAMRecord.getMateUnmappedFlag())
    
        {
          viewDetail.appendString("Mate Reference Name   "+thisSAMRecord.getMateReferenceName()+"\n", Level.DEBUG);
          viewDetail.appendString("Mate Start Coordinate "+thisSAMRecord.getMateAlignmentStart()+"\n", Level.DEBUG);
          viewDetail.appendString("Strand (read/mate)    "+
            (thisSAMRecord.getReadNegativeStrandFlag() ? "-" : "+")+" / "+
            (thisSAMRecord.getMateNegativeStrandFlag() ? "-" : "+"), Level.DEBUG);
        }
        else
        {
          viewDetail.appendString("Strand (read)         "+
              (thisSAMRecord.getReadNegativeStrandFlag() ? "-" : "+"), Level.DEBUG);
        }
        
        viewDetail.appendString("\n\nCigar String          "+thisSAMRecord.getCigarString(), Level.DEBUG);
        
        viewDetail.appendString("\n\nFlags:", Level.INFO);
        viewDetail.appendString("\nDuplicate Read    "+
            (thisSAMRecord.getDuplicateReadFlag() ? "yes" : "no"), Level.DEBUG);
    
    tjc's avatar
    tjc committed
        
        viewDetail.appendString("\nRead Paired       "+
            (thisSAMRecord.getReadPairedFlag() ? "yes" : "no"), Level.DEBUG);
        if(thisSAMRecord.getReadPairedFlag())
        {
          viewDetail.appendString("\nFirst of Pair     "+
    
            (thisSAMRecord.getFirstOfPairFlag() ? "yes" : "no"), Level.DEBUG);
    
    tjc's avatar
    tjc committed
          viewDetail.appendString("\nMate Unmapped     "+
    
            (thisSAMRecord.getMateUnmappedFlag() ? "yes" : "no"), Level.DEBUG);  
    
    tjc's avatar
    tjc committed
          viewDetail.appendString("\nProper Pair       "+
    
            (thisSAMRecord.getProperPairFlag() ? "yes" : "no"), Level.DEBUG);
    
        viewDetail.appendString("\nRead Fails Vendor\nQuality Check     "+
            (thisSAMRecord.getReadFailsVendorQualityCheckFlag() ? "yes" : "no"), Level.DEBUG);
        viewDetail.appendString("\nRead Unmapped     "+
            (thisSAMRecord.getReadUnmappedFlag() ? "yes" : "no"), Level.DEBUG);
    
    tjc's avatar
    tjc committed
        
        if(thisSAMRecord.getReadPairedFlag())
          viewDetail.appendString("\nSecond Of Pair    "+
    
            (thisSAMRecord.getSecondOfPairFlag() ? "yes" : "no"), Level.DEBUG);
    
        
        viewDetail.appendString("\n\nRead Bases:\n", Level.INFO);
        viewDetail.appendString(new String(thisSAMRecord.getReadBases()), Level.DEBUG);
    
    
      protected SAMRecordFlagPredicate getSamRecordFlagPredicate()
      {
        return samRecordFlagPredicate;
      }
    
      protected void setSamRecordFlagPredicate(
          SAMRecordFlagPredicate samRecordFlagPredicate)
      {
        laststart = -1;
        lastend = -1;
        this.samRecordFlagPredicate = samRecordFlagPredicate;
      }
    
    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
      }
    }