Commit 51d0f376 authored by Yannis Duffourd's avatar Yannis Duffourd

Adding cpp version

parent 35e59a9c
// cnvCaller.cu
// Version : 1.1.0
// Description : C++/CUDA kernels to compute information needed by cnvcallerGPU
// Author: Theo.Serralta@u-bourgogne.fr ; yannis.duffourd@u-bourgogne.fr ; anthony.auclair@u-bourgogne.fr
#include <cuda_runtime.h>
// Kernel to compute raw average depth
__global__ void computeDepthKernel(int *depth_data, int seq_length, int window_size, int step_size, float *depth_results) {
int idx = threadIdx.x + blockIdx.x * blockDim.x;
if (idx < seq_length - window_size + 1) {
int pos_start = (idx * step_size);
int pos_end = pos_start + window_size;
int count_reads = 0;
for (int i = pos_start; i < pos_end; i++) {
count_reads += depth_data[i];
}
depth_results[idx] = static_cast<float>(count_reads) / window_size;
}
}
// NEED TO OPTIMIZE WITH 3RD DEGREE POLYNOME
// Kernel to normalize depth using GC content and mappability
__global__ void normalizeDepthKernel(float *depth_correction, float *gc_results, float *map_results,
float mean_depth, float *gc_to_median, int seq_length,
int window_size, int step_size, float *normalized_depth) {
int idx = threadIdx.x + blockIdx.x * blockDim.x;
if (idx < seq_length - window_size + 1) {
float gc_value = gc_results[idx];
float map_value = map_results[idx];
float depth_value = depth_correction[idx];
// Récupérer la médiane du GC content
float gc_median = gc_to_median[(int)gc_value];
// Vérifier les valeurs pour éviter des erreurs (division par zéro)
if (gc_median != 0.0f && map_value != 0.0f) {
normalized_depth[idx] = (depth_value / map_value) * (mean_depth / gc_median);
} else {
normalized_depth[idx] = 0.0f;
}
}
}
// Kernel to compute GC content in a sliding window
__global__ void computeGCKernel(char *seq_data, int seq_length, int window_size, int step_size, float *gc_results) {
int idx = threadIdx.x + blockIdx.x * blockDim.x;
if (idx < seq_length - window_size + 1) {
int pos_start = (idx * step_size);
int pos_end = pos_start + window_size;
int gc_count = 0;
for (int i = pos_start; i < pos_end; ++i) {
char base = seq_data[i];
if (base == 'G' || base == 'C' || base == 'g' || base == 'c') {
gc_count++;
}
}
gc_results[idx] = (static_cast<float>(gc_count) / window_size) * 100.0f;
}
}
// Kernel to compute weighted average mappability
__global__ void computeMappabilityKernel(float *map_data, int seq_length, int window_size, int step_size, float *map_results) {
int idx = threadIdx.x + blockIdx.x * blockDim.x;
if (idx < seq_length - window_size + 1) {
int pos_start = (idx * step_size);
int pos_end = pos_start + window_size;
float weighted_sum = 0.0f;
float total_weight = 0.0f;
for (int i = pos_start; i < pos_end; ++i) {
float weight = map_data[i];
weighted_sum += weight;
total_weight += 1.0f;
}
map_results[idx] = (total_weight > 0.0f) ? (weighted_sum / total_weight) : 0.0f;
}
}
// Kernel to compute Z-score
__global__ void computeZScoreKernel(float *normalized_depth, float mean_ratio, float std_ratio, int seq_length, float *z_score_results) {
int idx = threadIdx.x + blockIdx.x * blockDim.x;
if (idx < seq_length) {
float value = normalized_depth[idx];
if (isinf(value) || isnan(value)) {
value = 0.0f;
}
z_score_results[idx] = (value - mean_ratio) / std_ratio;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment