Skip to content

Commit

Permalink
redesign SmithWaterman code (#17)
Browse files Browse the repository at this point in the history
the initial design of the SmithWaterman API caused a lot of unecessary
complexity in GATK, so we've redesigned it to pass the parameters to the
alignment call instead of in an initialization method
  • Loading branch information
lbergelson authored Sep 21, 2017
1 parent be32186 commit 65f20d1
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 86 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@

import org.broadinstitute.gatk.nativebindings.NativeLibrary;

import java.io.Closeable;

/**
* Provides access to the native kernel of the Smith-Waterman computation.
* GATK will call {@link #initialize(SWAlignerArguments)} to set the
* parameter values and will call {@link #align(byte[], byte[])} to perform
* GATK will call {@link #align(byte[], byte[], SWParameters, SWOverhangStrategy)} to perform
* an alignment.
*
* Subclasses may override {@link #close()} if they need to release resources.
*
* Only one thread will call methods on any given object of classes that implement this interface.
*/
public interface SWAlignerNativeBinding extends NativeLibrary {

/**
* Initialize the native Smith-Waterman
*
* @param args arguments used for Smith-Waterman
*/
void initialize(SWAlignerArguments args);
public interface SWAlignerNativeBinding extends NativeLibrary, Closeable {

/**
* Perform a Smith-Waterman alignment and return the result
Expand All @@ -27,6 +23,17 @@ public interface SWAlignerNativeBinding extends NativeLibrary {
* @param alt alternate sequence
* @return alignment result
*/
SWAlignmentResult align(byte[] ref, byte[] alt);
SWNativeAlignerResult align(byte[] ref, byte[] alt, SWParameters parameters, SWOverhangStrategy overhangStrategy);


/**
* Subclasses may optionally implement close in order to release any native resources that they are holding.
* Subclasses that rely on close to recover resources should fail with {@link IllegalStateException} if
* {@link #align(byte[], byte[], SWParameters, SWOverhangStrategy)} is called after close.
*/
@Override
default void close() {
//do nothing by default
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.broadinstitute.gatk.nativebindings.smithwaterman;

/**
* Struct used to hold results of the Smith-Waterman alignment result
* Struct used to hold results of the Smith-Waterman alignment
*/
public final class SWAlignmentResult {
public final class SWNativeAlignerResult {
// CIGAR string of the alignment
public final String cigar;

// offset of the alignment
public final int alignment_offset;


public SWAlignmentResult(final String cigar, final int alignment_offset)
public SWNativeAlignerResult(final String cigar, final int alignment_offset)
{
this.cigar = cigar;
this.alignment_offset = alignment_offset;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.broadinstitute.gatk.nativebindings.smithwaterman;

/**
* How overhangs should be treated during Smith-Waterman alignment
*/
public enum SWOverhangStrategy {
/*
* Add softclips for the overhangs
*/
SOFTCLIP,

/*
* Treat the overhangs as proper insertions/deletions
*/
INDEL,

/*
* Treat the overhangs as proper insertions/deletions for leading (but not trailing) overhangs.
* This is useful e.g. when we want to merge dangling tails in an assembly graph: because we don't
* expect the dangling tail to reach the end of the reference path we are okay ignoring trailing
* deletions - but leading indels are still very much relevant.
*/
LEADING_INDEL,

/*
* Just ignore the overhangs
*/
IGNORE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.broadinstitute.gatk.nativebindings.smithwaterman;

/**
* a set of parameters to configure Smith-Waterman assembly
*/
public class SWParameters {
private final int matchValue;
private final int mismatchPenalty;
private final int gapOpenPenalty;
private final int gapExtendPenalty;

/**
* Create a new set of parameters for Smith-Waterman alignment
* @param matchValue how much to reward a match during alignment >= 0
* @param mismatchPenalty how much to penalize a mismatch during alignment <= 0
* @param gapOpenPenalty how much penalize the creation of a new gap in the alignment <= 0
* @param gapExtendPenalty how much to penalize extending an already open gap in the alignment <= 0
*/
public SWParameters(final int matchValue, final int mismatchPenalty, final int gapOpenPenalty, final int gapExtendPenalty) {
if( matchValue < 0 ) {
throw new IllegalArgumentException("matchValue must be >= 0 but was passed as " + matchValue);
}
if( mismatchPenalty > 0 ) {
throw new IllegalArgumentException("mismatchPenalty must be <= 0 but was passed as " + mismatchPenalty);
}
if( gapOpenPenalty > 0 ) {
throw new IllegalArgumentException("gapOpenPenalty must be <= 0 but was passed as " + gapOpenPenalty);
}
if( gapExtendPenalty > 0 ) {
throw new IllegalArgumentException("gapExtendPenalty must be <= 0 but was passed as " + gapExtendPenalty);
}
this.matchValue = matchValue;
this.mismatchPenalty = mismatchPenalty;
this.gapOpenPenalty = gapOpenPenalty;
this.gapExtendPenalty = gapExtendPenalty;
}

/** gap extension penalty **/
public int getGapExtendPenalty() {
return gapExtendPenalty;
}

/** match value **/
public int getMatchValue() {
return matchValue;
}

/** mismatch penalty **/
public int getMismatchPenalty() {
return mismatchPenalty;
}

/** gap open penalty **/
public int getGapOpenPenalty() {
return gapOpenPenalty;
}
}

0 comments on commit 65f20d1

Please sign in to comment.