Better configuration support. Now supports everything that people have expressed interest in except edit distance.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2021 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
6c9f86bb4d
commit
0c2a957ae0
|
|
@ -76,6 +76,14 @@ void BWA::load_default_options()
|
|||
options.trim_qual = 0;
|
||||
}
|
||||
|
||||
void BWA::set_max_edit_distance(int edit_distance) { options.max_diff = edit_distance; }
|
||||
void BWA::set_max_gap_opens(int max_gap_opens) { options.max_gapo = max_gap_opens; }
|
||||
void BWA::set_max_gap_extensions(int max_gap_extensions) { options.max_gape = max_gap_extensions; }
|
||||
void BWA::set_disallow_indel_within_range(int indel_range) { options.indel_end_skip = indel_range; printf("set indel end skip to %d\n", options.indel_end_skip);}
|
||||
void BWA::set_mismatch_penalty(int penalty) { options.s_mm = penalty; }
|
||||
void BWA::set_gap_open_penalty(int penalty) { options.s_gapo = penalty; }
|
||||
void BWA::set_gap_extension_penalty(int penalty) { options.s_gape = penalty; }
|
||||
|
||||
/**
|
||||
* Create a sequence with a set of reasonable initial defaults.
|
||||
* Will leave seq and rseq empty.
|
||||
|
|
|
|||
|
|
@ -30,6 +30,17 @@ class BWA {
|
|||
const char* reverse_bwt_filename,
|
||||
const char* reverse_sa_filename);
|
||||
~BWA();
|
||||
|
||||
// Parameterize the aligner.
|
||||
void set_max_edit_distance(int edit_distance);
|
||||
void set_max_gap_opens(int max_gap_opens);
|
||||
void set_max_gap_extensions(int max_gap_extensions);
|
||||
void set_disallow_indel_within_range(int indel_range);
|
||||
void set_mismatch_penalty(int penalty);
|
||||
void set_gap_open_penalty(int penalty);
|
||||
void set_gap_extension_penalty(int penalty);
|
||||
|
||||
// Perform the alignment
|
||||
void align(const char* bases, const unsigned read_length, Alignment*& alignments, unsigned& num_alignments);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,23 +12,28 @@ static jclass java_alignment_array_class = NULL;
|
|||
static jclass java_alignment_class = NULL;
|
||||
static jmethodID java_alignment_constructor = NULL;
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_broadinstitute_sting_alignment_bwa_BWACAligner_create(JNIEnv* env,
|
||||
jobject instance,
|
||||
jstring java_ann,
|
||||
jstring java_amb,
|
||||
jstring java_pac,
|
||||
jstring java_forward_bwt,
|
||||
jstring java_forward_sa,
|
||||
jstring java_reverse_bwt,
|
||||
jstring java_reverse_sa)
|
||||
typedef void (BWA::*int_setter)(int value);
|
||||
|
||||
static jstring get_configuration_string(JNIEnv* env, jobject configuration, const char* field_name);
|
||||
static void set_int_configuration_param(JNIEnv* env, jobject configuration, const char* field_name, BWA* bwa, int_setter setter);
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_broadinstitute_sting_alignment_bwa_BWACAligner_create(JNIEnv* env, jobject instance, jobject configuration)
|
||||
{
|
||||
const char* ann_filename = env->GetStringUTFChars(java_ann, JNI_FALSE);
|
||||
const char* amb_filename = env->GetStringUTFChars(java_amb, JNI_FALSE);
|
||||
const char* pac_filename = env->GetStringUTFChars(java_pac, JNI_FALSE);
|
||||
const char* forward_bwt_filename = env->GetStringUTFChars(java_forward_bwt, JNI_FALSE);
|
||||
const char* forward_sa_filename = env->GetStringUTFChars(java_forward_sa, JNI_FALSE);
|
||||
const char* reverse_bwt_filename = env->GetStringUTFChars(java_reverse_bwt, JNI_FALSE);
|
||||
const char* reverse_sa_filename = env->GetStringUTFChars(java_reverse_sa, JNI_FALSE);
|
||||
jstring java_ann = get_configuration_string(env,configuration,"annFileName");
|
||||
jstring java_amb = get_configuration_string(env,configuration,"ambFileName");
|
||||
jstring java_pac = get_configuration_string(env,configuration,"pacFileName");
|
||||
jstring java_forward_bwt = get_configuration_string(env,configuration,"forwardBWTFileName");
|
||||
jstring java_forward_sa = get_configuration_string(env,configuration,"forwardSAFileName");
|
||||
jstring java_reverse_bwt = get_configuration_string(env,configuration,"reverseBWTFileName");
|
||||
jstring java_reverse_sa = get_configuration_string(env,configuration,"reverseSAFileName");
|
||||
|
||||
const char* ann_filename = env->GetStringUTFChars(java_ann,JNI_FALSE);
|
||||
const char* amb_filename = env->GetStringUTFChars(java_amb,JNI_FALSE);
|
||||
const char* pac_filename = env->GetStringUTFChars(java_pac,JNI_FALSE);
|
||||
const char* forward_bwt_filename = env->GetStringUTFChars(java_forward_bwt,JNI_FALSE);
|
||||
const char* forward_sa_filename = env->GetStringUTFChars(java_forward_sa,JNI_FALSE);
|
||||
const char* reverse_bwt_filename = env->GetStringUTFChars(java_reverse_bwt,JNI_FALSE);
|
||||
const char* reverse_sa_filename = env->GetStringUTFChars(java_reverse_sa,JNI_FALSE);
|
||||
|
||||
BWA* bwa = new BWA(ann_filename,
|
||||
amb_filename,
|
||||
|
|
@ -38,6 +43,15 @@ JNIEXPORT jlong JNICALL Java_org_broadinstitute_sting_alignment_bwa_BWACAligner_
|
|||
reverse_bwt_filename,
|
||||
reverse_sa_filename);
|
||||
|
||||
//set_int_configuration_param(env, configuration, "maximumEditDistance", bwa, &BWA::set_max_edit_distance);
|
||||
set_int_configuration_param(env, configuration, "maximumGapOpens", bwa, &BWA::set_max_gap_opens);
|
||||
set_int_configuration_param(env, configuration, "maximumGapExtensions", bwa, &BWA::set_max_gap_extensions);
|
||||
set_int_configuration_param(env, configuration, "disallowIndelWithinRange", bwa, &BWA::set_disallow_indel_within_range);
|
||||
set_int_configuration_param(env, configuration, "mismatchPenalty", bwa, &BWA::set_mismatch_penalty);
|
||||
set_int_configuration_param(env, configuration, "gapOpenPenalty", bwa, &BWA::set_gap_open_penalty);
|
||||
set_int_configuration_param(env, configuration, "gapExtensionPenalty", bwa, &BWA::set_gap_extension_penalty);
|
||||
|
||||
|
||||
env->ReleaseStringUTFChars(java_ann,ann_filename);
|
||||
env->ReleaseStringUTFChars(java_amb,amb_filename);
|
||||
env->ReleaseStringUTFChars(java_pac,pac_filename);
|
||||
|
|
@ -120,3 +134,21 @@ JNIEXPORT jobjectArray JNICALL Java_org_broadinstitute_sting_alignment_bwa_BWACA
|
|||
|
||||
return java_alignments;
|
||||
}
|
||||
|
||||
static jstring get_configuration_string(JNIEnv* env, jobject configuration, const char* field_name) {
|
||||
jclass configuration_class = env->GetObjectClass(configuration);
|
||||
jfieldID configuration_field = env->GetFieldID(configuration_class, field_name, "Ljava/lang/String;");
|
||||
return (jstring)env->GetObjectField(configuration,configuration_field);
|
||||
}
|
||||
|
||||
static void set_int_configuration_param(JNIEnv* env, jobject configuration, const char* field_name, BWA* bwa, int_setter setter) {
|
||||
jclass configuration_class = env->GetObjectClass(configuration);
|
||||
jfieldID configuration_field = env->GetFieldID(configuration_class, field_name, "Ljava/lang/Integer;");
|
||||
jobject boxed_value = env->GetObjectField(configuration,configuration_field);
|
||||
if(boxed_value != NULL) {
|
||||
jclass int_box_class = env->FindClass("java/lang/Integer");
|
||||
jmethodID int_extractor = env->GetMethodID(int_box_class,"intValue", "()I");
|
||||
jint value = env->CallIntMethod(boxed_value,int_extractor);
|
||||
(bwa->*setter)(value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ extern "C" {
|
|||
/*
|
||||
* Class: org_broadinstitute_sting_alignment_bwa_BWACAligner
|
||||
* Method: create
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J
|
||||
* Signature: (Lorg/broadinstitute/sting/alignment/bwa/BWACConfiguration;)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_org_broadinstitute_sting_alignment_bwa_BWACAligner_create
|
||||
(JNIEnv *, jobject, jstring, jstring, jstring, jstring, jstring, jstring, jstring);
|
||||
(JNIEnv *, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: org_broadinstitute_sting_alignment_bwa_BWACAligner
|
||||
|
|
|
|||
|
|
@ -40,13 +40,8 @@ public class AlignmentValidationWalker extends ReadWalker<Integer,Integer> {
|
|||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
aligner = new BWACAligner(prefix + ".ann",
|
||||
prefix + ".amb",
|
||||
prefix + ".pac",
|
||||
prefix + ".bwt",
|
||||
prefix + ".sa",
|
||||
prefix + ".rbwt",
|
||||
prefix + ".rsa");
|
||||
BWACConfiguration configuration = new BWACConfiguration(prefix);
|
||||
aligner = new BWACAligner(configuration);
|
||||
}
|
||||
|
||||
/** Must return true for reads that need to be processed. Reads, for which this method return false will
|
||||
|
|
|
|||
|
|
@ -31,13 +31,8 @@ public class AlignmentWalker extends ReadWalker<Integer,Integer> {
|
|||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
aligner = new BWACAligner(prefix + ".ann",
|
||||
prefix + ".amb",
|
||||
prefix + ".pac",
|
||||
prefix + ".bwt",
|
||||
prefix + ".sa",
|
||||
prefix + ".rbwt",
|
||||
prefix + ".rsa");
|
||||
BWACConfiguration configuration = new BWACConfiguration(prefix);
|
||||
aligner = new BWACAligner(configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -27,22 +27,10 @@ public class BWACAligner {
|
|||
|
||||
/**
|
||||
* Create a pointer to the BWA/C thunk.
|
||||
* @param annFileName Name of the ann file?
|
||||
* @param ambFileName Name of the amb file?
|
||||
* @param pacFileName Packed representation of the forward reference.
|
||||
* @param forwardBWTFileName Name of the file where the forward BWT is stored.
|
||||
* @param forwardSAFileName Name of te file where the forward suffix array is stored.
|
||||
* @param reverseBWTFileName Name of the file where the reverse BWT is stored.
|
||||
* @param reverseSAFileName Name of the file where the reverse SA is stored.
|
||||
* @param configuration Configuration of the aligner.
|
||||
* @return Pointer to the BWA/C thunk.
|
||||
*/
|
||||
protected native long create(String annFileName,
|
||||
String ambFileName,
|
||||
String pacFileName,
|
||||
String forwardBWTFileName,
|
||||
String forwardSAFileName,
|
||||
String reverseBWTFileName,
|
||||
String reverseSAFileName);
|
||||
protected native long create(BWACConfiguration configuration);
|
||||
|
||||
/**
|
||||
* Destroy the
|
||||
|
|
@ -50,22 +38,10 @@ public class BWACAligner {
|
|||
*/
|
||||
protected native void destroy(long thunkPointer);
|
||||
|
||||
public BWACAligner(String annFileName,
|
||||
String ambFileName,
|
||||
String pacFileName,
|
||||
String forwardBWTFileName,
|
||||
String forwardSAFileName,
|
||||
String reverseBWTFileName,
|
||||
String reverseSAFileName) {
|
||||
public BWACAligner(BWACConfiguration configuration) {
|
||||
if(thunkPointer != 0)
|
||||
throw new StingException("BWA/C attempting to reinitialize.");
|
||||
thunkPointer = create(annFileName,
|
||||
ambFileName,
|
||||
pacFileName,
|
||||
forwardBWTFileName,
|
||||
forwardSAFileName,
|
||||
reverseBWTFileName,
|
||||
reverseSAFileName);
|
||||
thunkPointer = create(configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,98 @@
|
|||
package org.broadinstitute.sting.alignment.bwa;
|
||||
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
||||
/**
|
||||
* Configuration for the BWA/C aligner.
|
||||
*
|
||||
* @author mhanna
|
||||
* @version 0.1
|
||||
*/
|
||||
public class BWACConfiguration {
|
||||
/**
|
||||
* ANN (?) file name.
|
||||
*/
|
||||
public String annFileName = null;
|
||||
|
||||
/**
|
||||
* AMB (?) file name.
|
||||
*/
|
||||
public String ambFileName = null;
|
||||
|
||||
/**
|
||||
* Packed reference sequence file.
|
||||
*/
|
||||
public String pacFileName = null;
|
||||
|
||||
/**
|
||||
* Forward BWT file.
|
||||
*/
|
||||
public String forwardBWTFileName = null;
|
||||
|
||||
/**
|
||||
* Forward suffix array file.
|
||||
*/
|
||||
public String forwardSAFileName = null;
|
||||
|
||||
/**
|
||||
* Reverse BWT file.
|
||||
*/
|
||||
public String reverseBWTFileName = null;
|
||||
|
||||
/**
|
||||
* Reverse suffix array file.
|
||||
*/
|
||||
public String reverseSAFileName = null;
|
||||
|
||||
/**
|
||||
* The maximum edit distance used by BWA.
|
||||
*/
|
||||
public Float maximumEditDistance = null;
|
||||
|
||||
/**
|
||||
* How many gap opens are acceptable within this alignment?
|
||||
*/
|
||||
public Integer maximumGapOpens = null;
|
||||
|
||||
/**
|
||||
* How many gap extensions are acceptable within this alignment?
|
||||
*/
|
||||
public Integer maximumGapExtensions = null;
|
||||
|
||||
/**
|
||||
* Do we disallow indels within a certain range from the start / end?
|
||||
*/
|
||||
public Integer disallowIndelWithinRange = null;
|
||||
|
||||
/**
|
||||
* What is the scoring penalty for a mismatch?
|
||||
*/
|
||||
public Integer mismatchPenalty = null;
|
||||
|
||||
/**
|
||||
* What is the scoring penalty for a gap open?
|
||||
*/
|
||||
public Integer gapOpenPenalty = null;
|
||||
|
||||
/**
|
||||
* What is the scoring penalty for a gap extension?
|
||||
*/
|
||||
public Integer gapExtensionPenalty = null;
|
||||
|
||||
/**
|
||||
* Create a new BWA configuration file using the given prefix.
|
||||
* @param prefix Prefix to use when creating the configuration. Must not be null.
|
||||
*/
|
||||
public BWACConfiguration(String prefix) {
|
||||
if(prefix == null)
|
||||
throw new StingException("Prefix must not be null.");
|
||||
annFileName = prefix + ".ann";
|
||||
ambFileName = prefix + ".amb";
|
||||
pacFileName = prefix + ".pac";
|
||||
forwardBWTFileName = prefix + ".bwt";
|
||||
forwardSAFileName = prefix + ".sa";
|
||||
reverseBWTFileName = prefix + ".rbwt";
|
||||
reverseSAFileName = prefix + ".rsa";
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue