This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Set Validation_Stringency In The Picard Api Directly From Java

I am trying to run the Picard MergeSamFiles API directly from java .

    File outputDir = bamFiles.get(0).getParentFile();
    String baseName = FilenameUtils.getBaseName(bamFiles.get(0).getName());        
    File mergedBamFile = new File(outputDir, baseName+ "_merged.bam");

    MergeSamFiles mergeSamFiles = new MergeSamFiles();
    mergeSamFiles.INPUT = bamFiles;
    mergeSamFiles.OUTPUT = mergedBamFile;
    mergeSamFiles.USE_THREADING = true;
    List<File> tmpDir = new ArrayList<File>(0);
    tmpDir.add(outputDir);
    mergeSamFiles.TMP_DIR = tmpDir;
    mergeSamFiles.CREATE_INDEX = true;
    mergeSamFiles.SORT_ORDER = SAMFileHeader.SortOrder.coordinate; 
    mergeSamFiles.VALIDATION_STRINGENCY = SAMFileReader.ValidationStringency.LENIENT;      
    if(mergeSamFiles.doWork() != 0 )
    {
        throw new IOException("Could not merge bam files using Picard " + bamFiles.toString());
    }       

    return mergedBamFile;

I need the validation stringency to be lenient because is need to ignore "MAPQ should be 0 for unmapped read" which is an artifact of our version of BWA (0.5.9, last version that support colorspace.)

Picard however keeps crashing on "MAPQ should be 0 for unmapped read", as if the validation stringency still is set to strict. Am I missing something here? Debugging shows that the inherited variable VALIDATION_STRINGENCY is set to Lenient on the mergeSamFiles object.

picard java api

2 answers

Hum, I think the variables like VALIDATION_STRINGENCY are filled using the java annotations (?)

try to set it the global way using setDefaultValidationStringency:

SAMFileReader.setDefaultValidationStringency(ValidationStringency.LENIENT);
 if(mergeSamFiles.doWork() != 0 )
(....)

This also works and I don't need to go via a string arguments array. Thanks!

I don't know why but replacing the if statement with

   String[] arguments = new String[] { "VALIDATION_STRINGENCY=LENIENT" };        
    mergeSamFiles.instanceMain(arguments);

seems to have solved the problem. Any info on why the solved the problem and what the preferred way is to use / run Picard API still is appreciated.

Log in to answer this question.