Skip to content

Commit

Permalink
Set values by index not name
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjcroucher committed Apr 24, 2024
1 parent 15fabaa commit e298ad3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 42 deletions.
32 changes: 16 additions & 16 deletions src/branch_sequences.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ void fill_in_recombinations_with_gaps(newick_node ** nodeArray, int node_index,
sequence_index = find_sequence_index_from_sample_name(node->taxon);

// Set sample statistics for printing using information from node
set_number_of_recombinations_for_sample(node->taxon,node->num_recombinations);
set_number_of_snps_for_sample(node->taxon,node->number_of_snps);
set_number_of_recombinations_for_sample(sequence_index,node->num_recombinations);
set_number_of_snps_for_sample(sequence_index,node->number_of_snps);

// Set root-specific values
if (parent_node_index == -1)
{
set_number_of_bases_in_recombinations(node->taxon,0);
set_number_of_branch_bases_in_recombinations(node->taxon,0);
set_number_of_bases_in_recombinations(sequence_index,0);
set_number_of_branch_bases_in_recombinations(sequence_index,0);
set_internal_node(1,sequence_index);
set_genome_length_excluding_blocks_and_gaps_for_sample(node->taxon,
set_genome_length_excluding_blocks_and_gaps_for_sample(sequence_index,
length_of_original_genome);
}
else
Expand All @@ -135,7 +135,7 @@ void fill_in_recombinations_with_gaps(newick_node ** nodeArray, int node_index,
// Get parental sequence
newick_node * parent = nodeArray[parent_node_index];
char * node_sequence = (char *) calloc((length_of_original_genome +1),sizeof(char));
get_sequence_for_sample_name(node_sequence, node->taxon);
get_sequence_for_sample_index(node_sequence, sequence_index);

// Calculate clonal frame remaining at the parental node
int ** current_block_coordinates = parent->block_coordinates;
Expand All @@ -144,7 +144,7 @@ void fill_in_recombinations_with_gaps(newick_node ** nodeArray, int node_index,
current_block_coordinates,
num_blocks[parent_node_index]);

set_genome_length_excluding_blocks_and_gaps_for_sample(node->taxon,
set_genome_length_excluding_blocks_and_gaps_for_sample(sequence_index,
genome_length_excluding_blocks_and_gaps);

// Identify the recombinations leading to this node from the root
Expand Down Expand Up @@ -172,7 +172,7 @@ void fill_in_recombinations_with_gaps(newick_node ** nodeArray, int node_index,

// Set number of branch bases in recombination by iterating through
// the first part of merged blocks (i.e. only blocks on the branch to this node)
set_number_of_branch_bases_in_recombinations(node->taxon,
set_number_of_branch_bases_in_recombinations(sequence_index,
calculate_number_of_bases_in_recombinations_excluding_gaps(merged_block_coordinates,
node->number_of_blocks,
node_sequence,
Expand All @@ -182,7 +182,7 @@ void fill_in_recombinations_with_gaps(newick_node ** nodeArray, int node_index,

// Set number of total bases in recombination by iterating through
// all merged blocks leading to this node
set_number_of_bases_in_recombinations(node->taxon,
set_number_of_bases_in_recombinations(sequence_index,
calculate_number_of_bases_in_recombinations_excluding_gaps(merged_block_coordinates,
(num_blocks[parent_node_index] + node->number_of_blocks),
node_sequence,
Expand Down Expand Up @@ -212,15 +212,15 @@ void fill_in_recombinations_with_gaps(newick_node ** nodeArray, int node_index,

if (node->childNum > 0)
{
set_internal_node(1,sequence_index);
// Update number of SNPs
current_total_snps[node_index] = current_total_snps[parent_node_index] + node->num_recombinations + node->number_of_snps;
num_blocks[node_index] = num_blocks[parent_node_index] + node->number_of_blocks;
nodeArray[node_index]->block_coordinates = merged_block_coordinates;
set_internal_node(1,sequence_index);
// Update number of SNPs
current_total_snps[node_index] = current_total_snps[parent_node_index] + node->num_recombinations + node->number_of_snps;
num_blocks[node_index] = num_blocks[parent_node_index] + node->number_of_blocks;
nodeArray[node_index]->block_coordinates = merged_block_coordinates;
}
else
{
set_internal_node(0,sequence_index);
set_internal_node(0,sequence_index);
}
}

Expand Down Expand Up @@ -305,7 +305,7 @@ void generate_branch_sequences(newick_node *node, FILE *vcf_file_pointer,int * s

// Get sequence reconstructed at node
branch_genome_size = calculate_size_of_genome_without_gaps(node_sequence, 0,number_of_snps, length_of_original_genome);
set_genome_length_without_gaps_for_sample(node->taxon,branch_genome_size);
set_genome_length_without_gaps_for_sample(node_sequence_index,branch_genome_size);

if (node->childNum == 0)
{
Expand Down
29 changes: 9 additions & 20 deletions src/parse_phylip.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,8 @@ void filter_sequence_bases_and_rotate(char * reference_bases, char ** filtered_b
}


void set_number_of_recombinations_for_sample(char * sample_name, int number_of_recombinations)
void set_number_of_recombinations_for_sample(int sample_index, int number_of_recombinations)
{
int sample_index ;
sample_index = find_sequence_index_from_sample_name( sample_name);
if( sample_index == -1)
{
return;
Expand All @@ -253,15 +251,12 @@ void set_number_of_recombinations_for_sample(char * sample_name, int number_of_r
}


void set_number_of_snps_for_sample(char * sample_name, int number_of_snps)
void set_number_of_snps_for_sample(int sample_index, int number_of_snps)
{
int sample_index ;
sample_index = find_sequence_index_from_sample_name( sample_name);
if( sample_index == -1)
{
return;
}

((sample_statistics *) statistics_for_samples[sample_index])->number_of_snps = number_of_snps;
}

Expand All @@ -279,10 +274,8 @@ void set_number_of_blocks_for_sample(char * sample_name,int num_blocks)



void set_genome_length_without_gaps_for_sample(char * sample_name, int genome_length_without_gaps)
void set_genome_length_without_gaps_for_sample(int sample_index, int genome_length_without_gaps)
{
int sample_index ;
sample_index = find_sequence_index_from_sample_name( sample_name);
if( sample_index == -1)
{
return;
Expand All @@ -291,33 +284,29 @@ void set_genome_length_without_gaps_for_sample(char * sample_name, int genome_le
((sample_statistics *) statistics_for_samples[sample_index])->genome_length_without_gaps = genome_length_without_gaps;
}

void set_genome_length_excluding_blocks_and_gaps_for_sample(char * sample_name, int genome_length_excluding_blocks_and_gaps)
void set_genome_length_excluding_blocks_and_gaps_for_sample(int sample_index, int genome_length_excluding_blocks_and_gaps)
{
int sample_index ;
sample_index = find_sequence_index_from_sample_name( sample_name);
if( sample_index == -1)

if( sample_index == -1)
{
return;
}

((sample_statistics *) statistics_for_samples[sample_index])->genome_length_excluding_blocks_and_gaps = genome_length_excluding_blocks_and_gaps;
}

void set_number_of_branch_bases_in_recombinations(char * sample_name, int bases_in_recombinations)
void set_number_of_branch_bases_in_recombinations(int sample_index, int bases_in_recombinations)
{
int sample_index ;
sample_index = find_sequence_index_from_sample_name( sample_name);

if( sample_index == -1)
{
return;
}
((sample_statistics *) statistics_for_samples[sample_index])->branch_bases_in_recombinations = bases_in_recombinations;
}

void set_number_of_bases_in_recombinations(char * sample_name, int bases_in_recombinations)
void set_number_of_bases_in_recombinations(int sample_index, int bases_in_recombinations)
{
int sample_index ;
sample_index = find_sequence_index_from_sample_name( sample_name);
if( sample_index == -1)
{
return;
Expand Down
12 changes: 6 additions & 6 deletions src/parse_phylip.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ int does_column_contain_snps(int snp_column, char reference_base);
int number_of_samples_from_parse_phylip(void);
void get_sample_names_from_parse_phylip(char ** sample_names);
char convert_reference_to_real_base_in_column(int snp_column, char reference_base);
void set_genome_length_without_gaps_for_sample(char * sample_name, int genome_length_without_gaps);
void set_number_of_snps_for_sample(char * sample_name, int number_of_snps);
void set_number_of_recombinations_for_sample(char * sample_name, int number_of_recombinations);
void set_genome_length_without_gaps_for_sample(int sample_index, int genome_length_without_gaps);
void set_number_of_snps_for_sample(int sample_index, int number_of_snps);
void set_number_of_recombinations_for_sample(int sample_index, int number_of_recombinations);
void set_number_of_blocks_for_sample(char * sample_name,int num_blocks);
sample_statistics ** get_sample_statistics(void);
int number_of_snps_in_phylip(void);
Expand All @@ -54,10 +54,10 @@ int get_internal_node(int sequence_index);
void fill_in_unambiguous_bases_in_parent_from_children_where_parent_has_a_gap(int parent_sequence_index, int * child_sequence_indices, int num_children);
void fill_in_unambiguous_gaps_in_parent_from_children(int parent_sequence_index, int * child_sequence_indices, int num_children);
void freeup_memory(void);
void set_number_of_branch_bases_in_recombinations(char * sample_name, int bases_in_recombinations);
void set_number_of_bases_in_recombinations(char * sample_name, int bases_in_recombinations);
void set_number_of_branch_bases_in_recombinations(int sample_index, int bases_in_recombinations);
void set_number_of_bases_in_recombinations(int sample_index, int bases_in_recombinations);
void filter_sequence_bases_and_rotate(char * reference_bases, char ** filtered_bases_for_snps, int number_of_filtered_snps);
void set_genome_length_excluding_blocks_and_gaps_for_sample(char * sample_name, int genome_length_excluding_blocks_and_gaps);
void set_genome_length_excluding_blocks_and_gaps_for_sample(int sample_index, int genome_length_excluding_blocks_and_gaps);

#define MAX_READ_BUFFER 65536
#define MAX_SAMPLE_NAME_SIZE 1024
Expand Down

0 comments on commit e298ad3

Please sign in to comment.