Skip to content

Commit

Permalink
tajima survivability bias
Browse files Browse the repository at this point in the history
  • Loading branch information
DeshanPerera committed Sep 25, 2024
1 parent e2e14b1 commit 6849f3c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 26 deletions.
6 changes: 5 additions & 1 deletion cancer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ void cancer::node_Master_Manager(functions_library &functions)
{
cout << "Metastatic migration: Activated\n";

viral_Migration_Values = functions.create_Fill_2D_array_FLOAT(num_tissues_per_Node * (num_tissues_per_Node - 1), 2, -1);
viral_Migration_Values = functions.create_Fill_2D_array_FLOAT(num_tissues_per_Node * (num_tissues_per_Node - 1), 3, -1);
migration_start_Generation = (int *)malloc(num_tissues_per_Node * (num_tissues_per_Node - 1) * sizeof(int));

for (int fill_mig = 0; fill_mig < num_tissues_per_Node * (num_tissues_per_Node - 1); fill_mig++)
Expand Down Expand Up @@ -1316,6 +1316,10 @@ void cancer::node_Master_Manager(functions_library &functions)
{
migration_start_Generation[migration_Check] = Parameters.get_INT(block_Migration[i].second);
}
else if (Parameters.get_STRING(block_Migration[i].first) == "Preference")
{
viral_Migration_Values[migration_Check][2] = Parameters.get_FLOAT(block_Migration[i].second);
}
else
{
cout << "ERROR INVALID ENTRY AT " << check_source_destination << endl;
Expand Down
106 changes: 83 additions & 23 deletions cancer_Host.cu
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void cancer_Host::simulate_Generations(functions_library &functions,
// {
// columns_Tajima = columns_Tajima + "\tRegion_" + to_string(region + 1);
// }
functions.create_File(output_Tajima_File, "Generation\tTissue\tN_cells\tseg_Sites\tpairwise_Diff\tCombinations\tPi\ttajima_D");
functions.create_File(output_Tajima_File, "Type\tGeneration\tTissue\tN_cells\tseg_Sites\tpairwise_Diff\tCombinations\tPi\ttajima_D");
}
// functions.create_File(sequence_parent_Progeny_relationships, "Source\tTarget\tType");

Expand Down Expand Up @@ -765,18 +765,28 @@ void cancer_Host::calculate_Tajima(functions_library &functions,
// exit(-1);

string sequence_String = "";
vector<string> line_Data;
string dead_or_Alive = "";

int count_Track = 0;

int *per_Region = (int *)malloc(num_Regions * sizeof(int));
int *per_Region_ALIVE = (int *)malloc(num_Regions * sizeof(int));

for (int region = 0; region < num_Regions; region++)
{
per_Region[region] = 0;
per_Region_ALIVE[region] = 0;
}

int *cuda_per_Region;
cudaMallocManaged(&cuda_per_Region, num_Regions * sizeof(int));
cudaMemcpy(cuda_per_Region, per_Region, num_Regions * sizeof(int), cudaMemcpyHostToDevice);

int *cuda_per_Region_ALIVE;
cudaMallocManaged(&cuda_per_Region_ALIVE, num_Regions * sizeof(int));
cudaMemcpy(cuda_per_Region_ALIVE, per_Region_ALIVE, num_Regions * sizeof(int), cudaMemcpyHostToDevice);

cout << "\nReading files\n";

for (int file = 0; file < indexed_Source_Folder.size(); file++)
Expand All @@ -796,9 +806,15 @@ void cancer_Host::calculate_Tajima(functions_library &functions,
if (count_Track == max_Cells_at_a_time)
{
process_Tajima_String(sequence_String, count_Track, num_Regions, cuda_tajima_regions_Start_Stop,
cuda_full_Char, cuda_per_Region, functions);
cuda_full_Char, cuda_per_Region, functions, dead_or_Alive,
cuda_per_Region_ALIVE);
}
}
else
{
functions.split(line_Data, line, '_');
dead_or_Alive.append(line_Data[1]);
}
}
nfasta.close();
}
Expand All @@ -813,16 +829,47 @@ void cancer_Host::calculate_Tajima(functions_library &functions,
if (count_Track > 0)
{
process_Tajima_String(sequence_String, count_Track, num_Regions, cuda_tajima_regions_Start_Stop,
cuda_full_Char, cuda_per_Region, functions);
cuda_full_Char, cuda_per_Region, functions, dead_or_Alive, cuda_per_Region_ALIVE);
}

cout << "Completed reading files\n";

cudaMemcpy(per_Region, cuda_per_Region, num_Regions * sizeof(int), cudaMemcpyDeviceToHost);
cudaFree(cuda_per_Region);

cout << "\nCalculating Tajima's D: \n";
// functions.create_File(output_Tajima_File, "Generation\tTissue\tN_cells\tseg_Sites\tpairwise_Diff\tCombinations\tPi\ttajima_D");
cudaMemcpy(per_Region_ALIVE, cuda_per_Region_ALIVE, num_Regions * sizeof(int), cudaMemcpyDeviceToHost);
cudaFree(cuda_per_Region_ALIVE);

write_Tajima("ALL", per_Region, output_Tajima_File, overall_Generations, tissue_Name,
num_Regions, N, N_float, out_a_1, e1, e2);
write_Tajima("ALIVE", per_Region_ALIVE, output_Tajima_File, overall_Generations, tissue_Name,
num_Regions, N, N_float, out_a_1, e1, e2);

// cout << "DONE\n";
for (int row = 0; row < num_Regions; row++)
{
cudaFree(cuda_tajima_regions_Start_Stop[row]);
}
// cout << "DONE\n";
cudaFree(cuda_tajima_regions_Start_Stop);
cudaFree(cuda_full_Char);
// cout << "DONE\n";
free(per_Region);
free(per_Region_ALIVE);
// cout << "DONE\n";

cout << "Completed Tajima calculation for generation: " << overall_Generations << endl;

// exit(-1);
}

void cancer_Host::write_Tajima(string type, int *per_Region, string &output_Tajima_File, int &overall_Generations, string &tissue_Name,
int &num_Regions, int &N, double &N_float, double &out_a_1, double &e1, double &e2)
{
cout << "\nCalculating Tajima's D for ";
cout << type << endl;
// functions.create_File(output_Tajima_File, "Type\tGeneration\tTissue\tN_cells\tseg_Sites\tpairwise_Diff\tCombinations\tPi\ttajima_D");

double tot_pairwise_Differences = 0;
double seg_sites_Count = 0;
for (int region = 0; region < num_Regions; region++)
Expand Down Expand Up @@ -855,7 +902,7 @@ void cancer_Host::calculate_Tajima(functions_library &functions,
if (tajima_Write.is_open())
{
cout << "Writing to file: " << output_Tajima_File << endl;
tajima_Write << to_string(overall_Generations) << "\t" << tissue_Name << "\t"
tajima_Write << type << "\t" << to_string(overall_Generations) << "\t" << tissue_Name << "\t"
<< to_string(N) << "\t" << seg_sites_Count << "\t" << to_string(tot_pairwise_Differences) << "\t" << to_string(combinations) << "\t" << to_string(pi) << "\t"
<< to_string(D) << endl;
tajima_Write.close();
Expand All @@ -876,7 +923,7 @@ void cancer_Host::calculate_Tajima(functions_library &functions,
if (tajima_Write.is_open())
{
cout << "Writing to file: " << output_Tajima_File << endl;
tajima_Write << to_string(overall_Generations) << "\t" << tissue_Name << "\t"
tajima_Write << type << "\t" << to_string(overall_Generations) << "\t" << tissue_Name << "\t"
<< to_string(N) << "\t0\t" << "NA" << "\t" << "NA" << "\t" << "NA" << "\t"
<< "NA" << endl;
tajima_Write.close();
Expand All @@ -887,19 +934,6 @@ void cancer_Host::calculate_Tajima(functions_library &functions,
exit(-1);
}
}
// cout << "DONE\n";
for (int row = 0; row < num_Regions; row++)
{
cudaFree(cuda_tajima_regions_Start_Stop[row]);
}
// cout << "DONE\n";
cudaFree(cuda_tajima_regions_Start_Stop);
cudaFree(cuda_full_Char);
// cout << "DONE\n";
free(per_Region);
// cout << "DONE\n";

cout << "Completed Tajima calculation for generation: " << overall_Generations << endl;
}

long int cancer_Host::fact_half(int count)
Expand All @@ -922,7 +956,8 @@ long int cancer_Host::combos_N(int count)
}

__global__ void cuda_tajima_calc(int num_Regions, int genome_Length, int **cuda_tajima_regions_Start_Stop,
char *sites, char *cuda_reference_Genome, int *cuda_per_Region, int sequences_Total)
char *sites, char *cuda_reference_Genome, int *cuda_per_Region, int sequences_Total,
char *cuda_char_dead_or_Alive, int *cuda_per_Region_ALIVE)
{
int tid = threadIdx.x + blockIdx.x * blockDim.x;

Expand Down Expand Up @@ -953,6 +988,11 @@ __global__ void cuda_tajima_calc(int num_Regions, int genome_Length, int **cuda_
if (region_Count != 0)
{
atomicAdd(&cuda_per_Region[region], 1);

if (cuda_char_dead_or_Alive[tid] == 'A')
{
atomicAdd(&cuda_per_Region_ALIVE[region], 1);
}
// cuda_per_Region[region] = 1;
}
// else
Expand All @@ -967,9 +1007,15 @@ __global__ void cuda_tajima_calc(int num_Regions, int genome_Length, int **cuda_

void cancer_Host::process_Tajima_String(string &all_Sequences, int &count_Track, int &num_Regions, int **cuda_tajima_regions_Start_Stop,
char *cuda_Reference_Genome, int *cuda_per_Region,
functions_library &functions)
functions_library &functions,
string &dead_or_Alive, int *cuda_per_Region_ALIVE)
{
cout << "Processing MAF for " << count_Track << " cells\n";

// cout << "Dead alive size: " << dead_or_Alive.size() << endl;

// exit(-1);

char *full_Char;
full_Char = (char *)malloc((all_Sequences.size() + 1) * sizeof(char));
strcpy(full_Char, all_Sequences.c_str());
Expand All @@ -980,8 +1026,19 @@ void cancer_Host::process_Tajima_String(string &all_Sequences, int &count_Track,
free(full_Char);
all_Sequences = "";

char *char_dead_or_Alive;
char_dead_or_Alive = (char *)malloc((dead_or_Alive.size() + 1) * sizeof(char));
strcpy(char_dead_or_Alive, dead_or_Alive.c_str());

char *cuda_char_dead_or_Alive;
cudaMallocManaged(&cuda_char_dead_or_Alive, (dead_or_Alive.size() + 1) * sizeof(char));
cudaMemcpy(cuda_char_dead_or_Alive, char_dead_or_Alive, (dead_or_Alive.size() + 1) * sizeof(char), cudaMemcpyHostToDevice);
free(char_dead_or_Alive);
dead_or_Alive = "";

cuda_tajima_calc<<<functions.tot_Blocks_array[0], functions.tot_ThreadsperBlock_array[0]>>>(num_Regions, genome_Length, cuda_tajima_regions_Start_Stop,
cuda_full_Char, cuda_Reference_Genome, cuda_per_Region, count_Track);
cuda_full_Char, cuda_Reference_Genome, cuda_per_Region, count_Track,
cuda_char_dead_or_Alive, cuda_per_Region_ALIVE);
cudaDeviceSynchronize();

cudaError_t err = cudaGetLastError();
Expand All @@ -992,6 +1049,9 @@ void cancer_Host::process_Tajima_String(string &all_Sequences, int &count_Track,
}

cudaFree(cuda_full_Char);
cudaFree(cuda_char_dead_or_Alive);

// exit(-1);

count_Track = 0;
}
Expand Down
6 changes: 5 additions & 1 deletion cancer_Host.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ public:

void process_Tajima_String(string &all_Sequences, int &count_Track, int &num_Regions, int **cuda_tajima_regions_Start_Stop,
char *cuda_Reference_Genome, int *cuda_per_Region,
functions_library &functions);
functions_library &functions,
string &dead_or_Alive, int *cuda_per_Region_ALIVE);

void write_Tajima(string type, int *per_Region, string &output_Tajima_File, int &overall_Generations, string &tissue_Name,
int &num_Regions, int &N, double &N_float, double &out_a_1, double &e1, double &e2);

long int combos_N(int count);
long int fact_half(int count);
Expand Down
Binary file modified main
Binary file not shown.
4 changes: 4 additions & 0 deletions parameters_Cancer/individual_Profiles/node_Master.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@

"1_2":{
"Start generation":0,
"Preference":"1",
"Cell migration Binomial trials":100,
"Cell migration Binomial probability":"0.10",
},

"2_1":{
"Start generation":10,
"Preference":"1",
"Cell migration Binomial trials":100,
"Cell migration Binomial probability":"0.10",
},

"2_3":{
"Start generation":10,
"Preference":"1",
"Cell migration Binomial trials":50,
"Cell migration Binomial probability":"0.01",
},

"3_1":{
"Start generation":2,
"Preference":"1",
"Cell migration Binomial trials":10,
"Cell migration Binomial probability":"0.9",
},
Expand Down
2 changes: 1 addition & 1 deletion parameters_Cancer/sequence_Profiles/sequence_Master.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"Reference_metastatic profile file":"/mnt/d/Deshan/Books/University of Calgary/Experiments/Simulator_Linux/parameters_Cancer/sequence_Profiles/profiles/cancer_Profiles/Reference_metastatic_prob.csv",

"Reference Fitness":"1",
"Reference Survivability":"1",
"Reference Survivability":"0.5",
"Reference Proof Reading":"0.5",

"Tajima's regions":{
Expand Down

0 comments on commit 6849f3c

Please sign in to comment.