2010-04-20 07:00:08 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010 The Broad Institute
|
2010-04-20 23:26:32 +08:00
|
|
|
*
|
2010-04-20 07:00:08 +08:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
2010-04-20 23:26:32 +08:00
|
|
|
* files (the "Software"), to deal in the Software without
|
2010-04-20 07:00:08 +08:00
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
|
* conditions:
|
2010-04-20 23:26:32 +08:00
|
|
|
*
|
2010-04-20 07:00:08 +08:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
2010-04-20 23:26:32 +08:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
2010-04-20 07:00:08 +08:00
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-02-04 03:48:15 +08:00
|
|
|
package org.broadinstitute.sting.gatk.datasources;
|
|
|
|
|
|
2010-04-20 07:00:08 +08:00
|
|
|
import org.broadinstitute.sting.commandline.CommandLineProgram;
|
|
|
|
|
import org.broadinstitute.sting.commandline.Argument;
|
2010-02-04 03:48:15 +08:00
|
|
|
import org.broadinstitute.sting.utils.StingException;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.PrintStream;
|
|
|
|
|
|
|
|
|
|
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-05-08 22:12:22 +08:00
|
|
|
private class BAMFileIndexContentInspector /*extends CachingBAMFileIndex*/ {
|
2010-02-04 03:48:15 +08:00
|
|
|
public BAMFileIndexContentInspector(File bamFileIndex) {
|
2010-05-08 22:12:22 +08:00
|
|
|
// super(bamFileIndex);
|
2010-02-04 03:48:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|