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
See: https://github.com/samtools/htsjdk/blob/master/src/main/java/htsjdk/samtools/BAMFileReader.java
don't use a BAMFileReader directly, use a SAMReaderFactory : https://www.javadoc.io/doc/com.github.samtools/htsjdk/1.132/htsjdk/samtools/SamReaderFactory.html