Skip to content

Commit

Permalink
aligner: create file/folder structure to the hpg-aligner and add the …
Browse files Browse the repository at this point in the history
…jni functions. #8
  • Loading branch information
jtarraga committed May 28, 2015
1 parent cd3e2b7 commit 21dc109
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 32 deletions.
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ mkdir -p build/libs
if [[ "Darwin" == "$PLATFORM" ]]; then
cp hpg-bigdata-core/native/third-party/htslib/libhts.*dylib build/libs/
cp hpg-bigdata-core/native/third-party/avro-c-1.7.7/build/src/libavro.*dylib build/libs/
cp hpg-bigdata-core/native/libhpgbigdata.dylib build/libs/
cp hpg-bigdata-core/native/*.dylib build/libs/
else
cp hpg-bigdata-core/native/third-party/htslib/libhts.so* build/libs/
cp hpg-bigdata-core/native/third-party/avro-c-1.7.7/build/src/libavro.so* build/libs/
cp hpg-bigdata-core/native/libhpgbigdata.so build/libs/
cp hpg-bigdata-core/native/*.so build/libs/
fi

cp README.md build/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import org.opencb.biodata.models.sequence.Read;
import org.opencb.commons.io.DataReader;
import org.opencb.commons.run.ParallelTaskRunner;
import org.opencb.hpg.bigdata.core.NativeSupport;
import org.opencb.hpg.bigdata.core.NativeConverter;
import org.opencb.hpg.bigdata.core.converters.FastqRecord2ReadConverter;
import org.opencb.hpg.bigdata.core.converters.FullVcfCodec;
import org.opencb.hpg.bigdata.core.converters.SAMRecord2ReadAlignmentConverter;
Expand All @@ -83,8 +83,6 @@
import org.opencb.hpg.bigdata.core.utils.PathUtils;
import org.opencb.hpg.bigdata.core.utils.ReadUtils;

import static org.opencb.hpg.bigdata.tools.converters.mr.Fastq2AvroMR.*;

/**
* Created by imedina on 16/03/15.
*/
Expand Down Expand Up @@ -352,7 +350,7 @@ private void sam2avro(String input, String output, String codecName) throws IOEx
System.out.println("\tjava.libary.path = " + System.getProperty("java.library.path"));
System.loadLibrary("hpgbigdata");
System.out.println("...done!");
new NativeSupport().bam2ga(in, out, convertCommandOptions.compression == null ? "snappy" : convertCommandOptions.compression);
new NativeConverter().bam2ga(in, out, convertCommandOptions.compression == null ? "snappy" : convertCommandOptions.compression);
return;
}

Expand Down
12 changes: 11 additions & 1 deletion hpg-bigdata-core/native/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ fi
echo
echo "Building the dynamic library $olib"

gcc -O3 -std=gnu99 ./converters/bam2ga.c jni/org_opencb_hpg_bigdata_core_NativeSupport.c -o $olib -shared -fPIC -I third-party/avro-c-1.7.7/src/ -I $JAVA_HOME/include -I $JAVA_HOME/include/linux -I $JAVA_HOME/include/darwin -I third-party/ -I third-party/htslib/ -L third-party/avro-c-1.7.7/build/src/ -L third-party/htslib/ -lhts -lavro -lpthread
gcc -O3 -std=gnu99 ./converters/bam2ga.c jni/org_opencb_hpg_bigdata_core_NativeConverter.c -o $olib -shared -fPIC -I third-party/avro-c-1.7.7/src/ -I jni/ -I $JAVA_HOME/include -I $JAVA_HOME/include/linux -I $JAVA_HOME/include/darwin -I third-party/ -I third-party/htslib/ -L third-party/avro-c-1.7.7/build/src/ -L third-party/htslib/ -lhts -lavro -lpthread

olib="libhpgaligner.so"
if [[ "Darwin" == "$PLATFORM" ]]; then
olib="libhpgaligner.dylib"
fi

echo
echo "Building the dynamic library $olib"

gcc -O3 -std=gnu99 ./third-party/hpg-aligner/index.c ./third-party/hpg-aligner/mapper.c -o $olib -shared -fPIC -I jni/
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "org_opencb_hpg_bigdata_core_NativeAligner.h"

//------------------------------------------------------------------------------//

void *load_index(char *index_path);
void free_index(void *index);

char *map(char *fastq, void *index);

//------------------------------------------------------------------------------//

JNIEXPORT jlong JNICALL Java_org_opencb_hpg_bigdata_core_NativeAligner_load_1index
(JNIEnv *env, jobject this, jstring index_path) {

const char *path = (*env)->GetStringUTFChars(env, index_path, NULL);
void *index = load_index(path);
return ((long) index);
}

//------------------------------------------------------------------------------//

JNIEXPORT void JNICALL Java_org_opencb_hpg_bigdata_core_NativeAligner_free_1index
(JNIEnv *env, jobject this, jlong index) {

free_index((void *) index);
}

//------------------------------------------------------------------------------//

JNIEXPORT jstring JNICALL Java_org_opencb_hpg_bigdata_core_NativeAligner_map
(JNIEnv *env, jobject this, jstring fastq, jlong index) {

const char *reads = (*env)->GetStringUTFChars(env, fastq, NULL);
char *sam = map(reads, (void *)index);

jstring res = (*env)->NewStringUTF(env, sam);

// free memory
if (sam) free(sam);

// return
return res;
}

//------------------------------------------------------------------------------//
//------------------------------------------------------------------------------//

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "org_opencb_hpg_bigdata_core_NativeSupport.h"
#include "org_opencb_hpg_bigdata_core_NativeConverter.h"

//------------------------------------------------------------------------------//

void bam2ga(const char *bam_filename, const char *avro_filename, const char *codec_name);

JNIEXPORT void JNICALL Java_org_opencb_hpg_bigdata_core_NativeSupport_bam2ga(JNIEnv *env, jobject this,
jstring bamFilename, jstring gaFilename, jstring compression) {
JNIEXPORT void JNICALL Java_org_opencb_hpg_bigdata_core_NativeConverter_bam2ga(JNIEnv *env, jobject this,
jstring bamFilename, jstring gaFilename,
jstring compression) {

const char *bam_filename = (*env)->GetStringUTFChars(env, bamFilename, NULL);
const char *ga_filename = (*env)->GetStringUTFChars(env, gaFilename, NULL);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

7 changes: 7 additions & 0 deletions hpg-bigdata-core/native/third-party/hpg-aligner/comp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

#gcc -O3 -std=gnu99 ./converters/bam2ga.c jni/org_opencb_hpg_bigdata_core_NativeSupport.c -o $olib -shared -fPIC -I third-party/avro-c-1.7.7/src/ -I $JAVA_HOME/include -I $JAVA_HOME/include/linux -I $JAVA_HOME/include/darwin -I third-party/ -I third-party/htslib/ -L third-party/avro-c-1.7.7/build/src/ -L third-party/htslib/ -lhts -lavro -lpthread
gcc -O3 -std=gnu99 hpg-aligner.c index.c mapper.c -o hpg-aligner

olib="libhpgaligner.so"
gcc -O3 -std=gnu99 hpg-aligner.c index.c mapper.c -o $olib -shared -fPIC
Binary file not shown.
30 changes: 30 additions & 0 deletions hpg-bigdata-core/native/third-party/hpg-aligner/hpg-aligner.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

//----------------------------------------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------------------------------------

void *load_index(char *index_path);
void free_index(void *index);

char *map(char *fastq, void *index);

//----------------------------------------------------------------------------------------------------------------------
// main
//----------------------------------------------------------------------------------------------------------------------

void main() {
// load index
char *index_path = "/toto/index.sa";
void *index = load_index(index_path);

// mapping
char *fastq = "@read1\nACTACTACTACTGG\n+\n22222222222222\n@read2\nGAGTTCCAAAGGGG\n+\n22222222222222\n";
char *sam = map(fastq, index);

printf("fastq:\n%s\n", fastq);
printf("sam:\n%s\n", sam);

// free memory
free(sam);
free_index(index);
}
24 changes: 24 additions & 0 deletions hpg-bigdata-core/native/third-party/hpg-aligner/index.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>

//----------------------------------------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------------------------------------

void *load_index(char *index_path) {
char *index = (char *) calloc(100, sizeof(char));
sprintf(index, "index located at %s", index_path);
printf("Loading index...\n\t%s\n...done!\n", index);
return (void *) index;
}

//----------------------------------------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------------------------------------

void free_index(void *index) {
if (index) {
printf("Freeing index...\n\t%s\n...done!\n", (char *) index);
free((char *) index);
}
}
13 changes: 13 additions & 0 deletions hpg-bigdata-core/native/third-party/hpg-aligner/mapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>

//----------------------------------------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------------------------------------

char *map(char *fastq, char *index_path) {
char *sam = (char *) calloc(100, sizeof(char));
sprintf(sam, "read1\t10\t20\t100M\tATAAATTACGGGGGAGA\nread2\t10\t20\t100M\tATAAATTACGGGGGAGA\n");
//printf("Mapping...\n%s\n%s\n...done!\n", fastq, sam);
return sam;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2015 OpenCB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.opencb.hpg.bigdata.core;

public class NativeAligner {
// index
public native long load_index(String indexPath);
public native void free_index(long index);

// map
public native String map(String sequences, long index);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

package org.opencb.hpg.bigdata.core;

public class NativeSupport {
public class NativeConverter {
public native void bam2ga(String bamFilename, String gaFilename, String compression);
}

0 comments on commit 21dc109

Please sign in to comment.