2010-02-04 03:48:15 +08:00
|
|
|
package org.broadinstitute.sting.gatk.datasources;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.utils.cmdLine.CommandLineProgram;
|
|
|
|
|
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
|
|
|
|
import org.broadinstitute.sting.utils.StingException;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.PrintStream;
|
|
|
|
|
import java.nio.channels.FileChannel;
|
2010-02-10 06:14:37 +08:00
|
|
|
import java.util.List;
|
2010-02-04 03:48:15 +08:00
|
|
|
|
|
|
|
|
import net.sf.samtools.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @author mhanna
|
|
|
|
|
* @version 0.1
|
|
|
|
|
*/
|
|
|
|
|
public class BAMFileStat extends CommandLineProgram {
|
|
|
|
|
public enum CommandType { ShowBlocks, ShowIndex }
|
|
|
|
|
|
|
|
|
|
@Argument(doc="Which operation to run.",required=true)
|
|
|
|
|
private CommandType command;
|
|
|
|
|
|
|
|
|
|
@Argument(doc="The BAM file to inspect.",required=true)
|
2010-02-05 10:48:02 +08:00
|
|
|
private String bamFileName;
|
2010-02-04 03:48:15 +08:00
|
|
|
|
|
|
|
|
@Argument(doc="The range of blocks to inspect.",required=false)
|
|
|
|
|
private String range;
|
|
|
|
|
|
|
|
|
|
public int execute() {
|
|
|
|
|
Integer startPosition = null, stopPosition = null;
|
|
|
|
|
if(range != null) {
|
|
|
|
|
int dashPosition = range.indexOf('-');
|
|
|
|
|
if(dashPosition > 0) {
|
|
|
|
|
if(dashPosition > 0)
|
|
|
|
|
startPosition = Integer.valueOf(range.substring(0,dashPosition));
|
|
|
|
|
if(dashPosition < range.length()-1)
|
|
|
|
|
stopPosition = Integer.valueOf(range.substring(dashPosition+1));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
startPosition = Integer.valueOf(range);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(command) {
|
|
|
|
|
case ShowBlocks:
|
2010-02-27 05:41:55 +08:00
|
|
|
throw new StingException("The BAM block inspector has been disabled.");
|
2010-02-04 03:48:15 +08:00
|
|
|
case ShowIndex:
|
2010-02-05 10:48:02 +08:00
|
|
|
showIndexBins(new File(bamFileName+".bai"));
|
2010-02-04 03:48:15 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Required main method implementation.
|
|
|
|
|
* @param argv Command-line arguments.
|
|
|
|
|
*/
|
|
|
|
|
public static void main(String[] argv) {
|
|
|
|
|
try {
|
|
|
|
|
BAMFileStat instance = new BAMFileStat();
|
|
|
|
|
start(instance, argv);
|
|
|
|
|
System.exit(CommandLineProgram.result);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
exitSystemWithError(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showIndexBins(File bamFile) {
|
|
|
|
|
BAMFileIndexContentInspector inspector = new BAMFileIndexContentInspector(bamFile);
|
|
|
|
|
inspector.inspect(System.out,null,null);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-31 03:28:14 +08:00
|
|
|
private class BAMFileIndexContentInspector extends CachingBAMFileIndex {
|
2010-02-04 03:48:15 +08:00
|
|
|
public BAMFileIndexContentInspector(File bamFileIndex) {
|
|
|
|
|
super(bamFileIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void inspect(PrintStream outputStream, Integer startPosition, Integer stopPosition) {
|
2010-03-24 06:02:28 +08:00
|
|
|
/*
|
2010-02-04 03:48:15 +08:00
|
|
|
outputStream.printf("Number of reference sequences: %d%n", this.referenceToBins.size());
|
|
|
|
|
for(int referenceSequence: referenceToBins.keySet()) {
|
|
|
|
|
Bin[] bins = referenceToBins.get(referenceSequence);
|
|
|
|
|
outputStream.printf("Reference sequence: %d%n",referenceSequence);
|
|
|
|
|
outputStream.printf("number of bins: %d%n",bins.length);
|
|
|
|
|
for(Bin bin: bins) {
|
2010-02-10 06:14:37 +08:00
|
|
|
List<Chunk> chunks = binToChunks.get(bin);
|
|
|
|
|
outputStream.printf("\tBin: %d, number of chunks: %d%n", bin.binNumber, chunks.size());
|
|
|
|
|
for(Chunk chunk: chunks)
|
2010-02-04 03:48:15 +08:00
|
|
|
outputStream.printf("\t\tChunk: %s%n", chunk);
|
|
|
|
|
}
|
|
|
|
|
LinearIndex linearIndex = referenceToLinearIndices.get(referenceSequence);
|
|
|
|
|
outputStream.printf("\t\tIndex entries: %d", linearIndex.indexEntries.length);
|
|
|
|
|
for(long indexEntry: linearIndex.indexEntries)
|
|
|
|
|
outputStream.printf("%d,",indexEntry);
|
|
|
|
|
outputStream.printf("%n");
|
|
|
|
|
}
|
2010-03-24 06:02:28 +08:00
|
|
|
*/
|
2010-02-04 03:48:15 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|