This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Check if a BAM file is corrupt in Java

Hi!

I am building a program in java and part of it would be creating and handling BAM files. My problem is the following: before writing I would like to check if a BAM file with the same name already exists and if yes, is it corrupt. I have found solutions for checking BAM files using samtools and picard, but these seem to be command-line based. Is there a way to check in java? My only option so far seems to be calling either samtools or picard using ProcessBuilder, but I would like to avoid this if possible, as I plan to have lot of BAMs and this doesn't seem to be an efficient solution.

Thanks in advance

bam java

1 answer

well you can use picard itself as a library.

java -cp /path/to/picard.jar:path/to/your.jar your.package.Main

and in your java code:

     // see https://github.com/broadinstitute/picard/blob/master/src/main/java/picard/sam/ValidateSamFile.java
     picard.sam.ValidateSamFile prog = new  picard.sam.ValidateSamFile();
     int returnValue = prog.instanceMain(new String[]{"-I","/path/to/your/bam", etc... etc..};

Log in to answer this question.