Skip to content

Commit

Permalink
Changes to make package compatible with R 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuSetty committed May 25, 2015
1 parent d4813da commit cbc3813
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
16 changes: 11 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
Package: ChIPKernels
Type: Package
Title: String kernels for ChIP-Seq
Version: 1.0
Date: 2013-06-21
Version: 1.1
Date: 2015-05-25
Author: Manu Setty
Maintainer: Manu Setty <[email protected]>
Depends:
IRanges,
XVector,
Biostrings,
BSgenome,
gtools,
GenomicRanges,
sfsmisc,
parallel,
kernlab,
Matrix
Matrix,
S4Vectors
Imports:
IRanges,
XVector,
graphics,
methods,
stats,
utils,
BiocGenerics,
IRanges,
Biostrings,
XVector
LinkingTo: IRanges, Biostrings, XVector
XVector,
S4Vectors
LinkingTo: IRanges, Biostrings, XVector, S4Vectors
Description: Collection of methods for building different string kernels used
for ChIP-Seq
License: GPL (>= 2)
Expand Down
79 changes: 40 additions & 39 deletions src/hamming_distance.c
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@

#include <Rdefines.h>
#include "Biostrings_interface.h"


/************************************************************************
Adding code for y (Hamming distance)
*******************************************************/
static int nmismatch_at_Pshift_fixedPfixedS(const cachedCharSeq *P,
const cachedCharSeq *S, int Pshift, int max_nmis)
static int nmismatch_at_Pshift_fixedPfixedS(const Chars_holder *P,
const Chars_holder *S, int Pshift, int max_nmis)
{
int nmis, i, j;
const char *p, *s;

nmis = 0;
for (i = 0, j = Pshift, p = P->seq, s = S->seq + Pshift;
i < P->length;
i++, j++, p++, s++)
{
if (j >= 0 && j < S->length && *p == *s)
continue;
if (nmis++ >= max_nmis)
break;
}
return nmis;
int nmis, i, j;
const char *p, *s;

nmis = 0;
for (i = 0, j = Pshift, p = P->ptr, s = S->ptr + Pshift;
i < P->length;
i++, j++, p++, s++)
{
if (j >= 0 && j < S->length && *p == *s)
continue;
if (nmis++ >= max_nmis)
break;
}
return nmis;
}


static int nmismatch_at_Pshift_fixedPnonfixedS(const cachedCharSeq *P,
const cachedCharSeq *S, int Pshift, int max_nmis)
static int nmismatch_at_Pshift_fixedPnonfixedS(const Chars_holder *P,
const Chars_holder *S, int Pshift, int max_nmis)
{
int nmis, i, j;
const char *p, *s;

nmis = 0;
for (i = 0, j = Pshift, p = P->seq, s = S->seq + Pshift;
for (i = 0, j = Pshift, p = P->ptr, s = S->ptr + Pshift;
i < P->length;
i++, j++, p++, s++)
{
Expand All @@ -51,8 +52,8 @@ SEXP XStringSet_dist_hamming_xy (SEXP x, SEXP y, SEXP max_nmis, SEXP fixed)

static int block_size = 250000;

cachedCharSeq x_j, y_i;
cachedXStringSet X, Y;
Chars_holder x_j, y_i;
XStringSet_holder X, Y;
int X_length, Y_length, i, j, val, index, prev_index=-1;
SEXP ans;
int *ans_elt;
Expand All @@ -66,45 +67,45 @@ SEXP XStringSet_dist_hamming_xy (SEXP x, SEXP y, SEXP max_nmis, SEXP fixed)
int *accumulator = (int *)Calloc (block_size, int);
int acc_count = 0;

X = cache_XStringSet(x);
Y = cache_XStringSet(y);
X = hold_XStringSet(x);
Y = hold_XStringSet(y);

X_length = get_cachedXStringSet_length(&X);
Y_length = get_cachedXStringSet_length(&Y);
x_j = get_cachedXStringSet_elt(&X, 0);
X_length = get_length_from_XStringSet_holder(&X);
Y_length = get_length_from_XStringSet_holder(&Y);
x_j = get_elt_from_XStringSet_holder(&X, 0);

for (i = 0; i < Y_length; i++) {

y_i = get_cachedXStringSet_elt(&Y, i);
y_i = get_elt_from_XStringSet_holder(&Y, i);
for (j = 0; j < X_length; j++) {

// Reallocate memory if necessary
if (acc_count % block_size >= block_size - 3) {
index = (int)ceil (acc_count/block_size);
if (index != prev_index) {
accumulator = (int *)Realloc(accumulator, (index + 2) * block_size, int);
prev_index = index;
}
index = (int)ceil (acc_count/block_size);
if (index != prev_index) {
accumulator = (int *)Realloc(accumulator, (index + 2) * block_size, int);
prev_index = index;
}

}

if (y_i.length != x_j.length) {
Free (accumulator);
error("Hamming distance requires equal length strings");
Free (accumulator);
error("Hamming distance requires equal length strings");
}

// Determine score
x_j = get_cachedXStringSet_elt(&X, j);
x_j = get_elt_from_XStringSet_holder(&X, j);
if (fix)
val = nmismatch_at_Pshift_fixedPfixedS (&y_i, &x_j, 0, max_nmis0);
else
val = nmismatch_at_Pshift_fixedPnonfixedS (&x_j, &y_i, 0, max_nmis0);

// Accumulate only if distance > 0
if (val <= max_nmis0 ) {
accumulator[acc_count++] = j + 1;
accumulator[acc_count++] = i + 1;
accumulator[acc_count++] = val;
accumulator[acc_count++] = j + 1;
accumulator[acc_count++] = i + 1;
accumulator[acc_count++] = val;
}
}

Expand Down

0 comments on commit cbc3813

Please sign in to comment.