Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jarwulf
    Junior Member
    • Apr 2012
    • 9

    #1

    modified Bam to bed algorithm

    I changed the Bam to Bed code I found here http://sourceforge.net/apps/mediawik...s_.28Picard.29 removing the commandline stuff to make it into simple conversion function that takes and passes a file back. Anything wrong with it? I'm new to Java so it may be riddled with errors.

    Calling code

    Code:
           //ALT if BAM 
            if (bamButton.isSelected())
            	File selectedFileBamHolder = BamToBed.doWork(selectedFile); //selectedFileBamHolder holds BAM since dunno if selectedFile could equal itself being processed by doWork
            	File selectedFile = selectedFileBamHolder;
            
            //ALT if not BAM just continue with other stuff


    Conversion code

    Code:
    package gui;
    
    
    import net.sf.picard.io.IoUtil;
    import net.sf.samtools.*;
    
    import java.io.File;
    import java.util.Iterator;
    
    /**
     * method for converting bam or sam files to bed files.
     */
    public class BamToBed {
    
        File convertedBAM; //ALT File to pass back
        
        /** Whether the user provided sequence, start, and end args on the command line */
        protected boolean rangeArgsProvided = false;
    
        /** This method contains the main logic of the application */
        protected File doWork(File INPUT) { //ALT takes the (BAM) file inputted and processes it
            IoUtil.assertFileIsReadable(INPUT);
    
            final SAMFileReader reader = new SAMFileReader(INPUT);
    
            Iterator<SAMRecord> iterator = null;
            if(!rangeArgsProvided )
            {
                iterator = reader.iterator();
            }
            else
            {
                iterator = reader.queryOverlapping(SEQUENCE, START, END);
            }
    
            
            while (iterator.hasNext()) {
                final SAMRecord record = iterator.next();
                if (record.getReadUnmappedFlag()) {
                    continue;
                }
    
                //Output is redirected from System.out to a File to be passed back to calling function
                FileWriter fstream = new FileWriter(convertedBAM);
                BufferedWriter out = new BufferedWriter(fstream);
                out.write(record.getReferenceName() + "\t" +
                        (record.getAlignmentStart() - 1) + "\t" + //subtract 1 to shift from one-based to zero-based
                        (record.getAlignmentEnd() - 1 + 1) + "\t" + //subtract 1 to shift from one-based to zero-based, and
                                                                    // then add 1 to shift from inclusive to exclusive
                        record.getReadName() + "\t" +
                        record.getMappingQuality() + "\t" +
                        (record.getReadNegativeStrandFlag()? "-": "+") );
                out.close();
                   
                
            }
            reader.close();
    
            return convertedBAM;
        }
    
    
    }
  • sdriscoll
    I like code
    • Sep 2009
    • 436

    #2
    It seems like you should have to deal with the cigar notation stuff in there. Spliced alignments, deletions, etc. bed files have a way of annotating those as well. Either that or sometimes a single BAM line will have to be split into multiple BED lines.
    /* Shawn Driscoll, Gene Expression Laboratory, Pfaff
    Salk Institute for Biological Studies, La Jolla, CA, USA */

    Comment

    Latest Articles

    Collapse

    • SEQadmin2
      Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
      by SEQadmin2



      Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

      Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
      ...
      10-14-2026, 09:55 AM
    • SEQadmin2
      New Genomics Technologies Take Aim at Long-Standing Limits
      by SEQadmin2


      Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

      We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
      ...
      09-28-2026, 10:25 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by SEQadmin2, Yesterday, 11:13 AM
    0 responses
    19 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, Yesterday, 10:48 AM
    0 responses
    18 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-15-2026, 10:52 AM
    0 responses
    36 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-14-2026, 05:39 AM
    0 responses
    42 views
    0 reactions
    Last Post SEQadmin2  
    Working...