How To Set Validation_Stringency In The Picard Api Directly From Java
2
1
Entering edit mode
11.0 years ago
William ★ 5.3k

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 • 5.3k views
ADD COMMENT
2
Entering edit mode
11.0 years ago

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 )
(....)
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
11.0 years ago
William ★ 5.3k

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.

ADD COMMENT

Login before adding your answer.

Traffic: 2699 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6