Skip to content
Snippets Groups Projects
Commit 8497c589 authored by tcarver's avatar tcarver
Browse files

if the BAM index is not present try to use picard to index the file

parent 2b360d64
No related branches found
No related tags found
No related merge requests found
...@@ -92,6 +92,7 @@ import javax.swing.text.JTextComponent; ...@@ -92,6 +92,7 @@ import javax.swing.text.JTextComponent;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import net.sf.picard.sam.BuildBamIndex;
import net.sf.samtools.AlignmentBlock; import net.sf.samtools.AlignmentBlock;
import net.sf.samtools.SAMFileHeader; import net.sf.samtools.SAMFileHeader;
import net.sf.samtools.SAMFileReader; import net.sf.samtools.SAMFileReader;
...@@ -410,6 +411,16 @@ public class BamView extends JPanel ...@@ -410,6 +411,16 @@ public class BamView extends JPanel
return samFileReaderHash.get(bam); return samFileReaderHash.get(bam);
File bamIndexFile = getBamIndexFile(bam); File bamIndexFile = getBamIndexFile(bam);
if(!bamIndexFile.exists())
{
System.out.println("Index file not found so using picard to index the BAM...");
System.out.println("(requires BAM to be sorted by coordinate and for the sort order to be in the header line, HD)");
// Use Picard to index the file
// requires reads to be sorted by coordinate
new BuildBamIndex().instanceMain(
new String[]{ "I="+bam, "O="+bamIndexFile.getAbsolutePath() });
}
final SAMFileReader samFileReader; final SAMFileReader samFileReader;
if(bam.startsWith("ftp")) if(bam.startsWith("ftp"))
...@@ -1487,7 +1498,7 @@ public class BamView extends JPanel ...@@ -1487,7 +1498,7 @@ public class BamView extends JPanel
continue; continue;
g2.setStroke(originalStroke); g2.setStroke(originalStroke);
g2.setColor(Color.LIGHT_GRAY); g2.setColor(Color.gray);
if(pr.sam2 != null) if(pr.sam2 != null)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment