Skip to content

Commit

Permalink
Converting to use Beta API
Browse files Browse the repository at this point in the history
  • Loading branch information
lbergelson committed Nov 22, 2024
1 parent 7584853 commit 196e2df
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/main/java/picard/sam/AddOATag.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@

package picard.sam;

import htsjdk.beta.codecs.reads.cram.CRAMDecoderOptions;
import htsjdk.beta.codecs.reads.cram.CRAMEncoderOptions;
import htsjdk.beta.exception.HtsjdkException;
import htsjdk.beta.plugin.reads.ReadsDecoder;
import htsjdk.beta.plugin.reads.ReadsDecoderOptions;
import htsjdk.beta.plugin.reads.ReadsEncoder;
import htsjdk.beta.plugin.reads.ReadsEncoderOptions;
import htsjdk.beta.plugin.registry.HtsCodecRegistry;
import htsjdk.beta.plugin.registry.HtsCodecResolver;
import htsjdk.beta.plugin.registry.HtsDefaultRegistry;
import htsjdk.io.IOPath;
import htsjdk.samtools.*;
import htsjdk.samtools.util.*;
Expand Down Expand Up @@ -75,19 +85,27 @@ public class AddOATag extends CommandLineProgram {

@Override
protected int doWork() {
try (final SamReader reader = SamReaderFactory.makeDefault().referenceSequence(referenceSequence.getReferencePath()).open(INPUT.toPath());
final SAMFileWriter writer = new SAMFileWriterFactory().makeWriter(reader.getFileHeader(), true, OUTPUT.toPath(), referenceSequence.getReferencePath())) {
writer.setProgressLogger(
new ProgressLogger(log, (int) 1e7, "Wrote", "records"));
ReadsDecoderOptions readsDecoderOptions = new ReadsDecoderOptions()
.setCRAMDecoderOptions(new CRAMDecoderOptions()
.setReferencePath(referenceSequence.getHtsPath()));
ReadsEncoderOptions readsEncoderOptions = new ReadsEncoderOptions()
.setPreSorted(true)
.setCRAMEncoderOptions(new CRAMEncoderOptions()
.setReferencePath(referenceSequence.getHtsPath()));

try (ReadsDecoder reader = HtsDefaultRegistry.getReadsResolver().getReadsDecoder(INPUT, readsDecoderOptions);
ReadsEncoder writer = HtsDefaultRegistry.getReadsResolver().getReadsEncoder(OUTPUT, readsEncoderOptions)) {
// unsupported writer.setProgressLogger(new ProgressLogger(log, (int) 1e7, "Wrote", "records"));
writer.setHeader(reader.getHeader());

final OverlapDetector<?> overlapDetector = getOverlapDetectorFromIntervalListFile(INTERVAL_LIST);
for (final SAMRecord rec : reader) {
if (overlapDetector == null || overlapDetector.overlapsAny(rec)) {
setOATag(rec);
}
writer.addAlignment(rec);
writer.write(rec);
}
} catch (IOException e) {
} catch (HtsjdkException e) {
log.error(e);
return 1;
}
Expand Down

0 comments on commit 196e2df

Please sign in to comment.