Skip to content

Commit

Permalink
Access lists of nodes at different depths
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjcroucher committed Apr 18, 2024
1 parent e32c59f commit c7c0f77
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Newickform.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@

#define STR_OUT "out"

// Function to extract nodes relevant for each depth
void get_job_nodes(newick_node** jobNodeArray, newick_node** nodeArray, int* node_depths, int depth, int num_nodes)
{
int j = 0;
for (int i = 0; i < num_nodes; ++i)
{
if (node_depths[i] == depth)
{
jobNodeArray[j] = nodeArray[i];
++j;
}
}
}

// Function to count number of jobs to run at a particular depth
int get_job_counts(int *node_depths, int depth, int num_nodes)
{
int count = 0;
for (int i = 0; i < num_nodes; ++i)
{
if (node_depths[i] == depth)
{
count++;
}
}
return count;
}

// Function to create an array of nodes
void fill_nodeArray(newick_node *root,newick_node** nodeArray, int num_nodes)
{
if (root->childNum != 0)
Expand All @@ -50,6 +79,7 @@ void fill_nodeArray(newick_node *root,newick_node** nodeArray, int num_nodes)
}
}

// Function to count the total number of tree nodes
int count_tree_nodes(newick_node* root) {
if (root == NULL) return 0;
int count = 1; // Count the root node
Expand Down Expand Up @@ -181,6 +211,21 @@ newick_node* build_newick_tree(char * filename, FILE *vcf_file_pointer,int * snp
node_depths[i] = max_distance_to_tips(nodeArray[i]);
}

// iterate through depths and identify batches of analyses to be run
for (int depth = 0; depth <= max_depth; ++depth)
{
int num_jobs = get_job_counts(node_depths,depth,num_nodes);
newick_node** jobNodeArray = malloc(num_jobs * sizeof(newick_node*));
get_job_nodes(jobNodeArray,nodeArray,node_depths,depth,num_nodes);
printf("Depth is %d\n",depth);
for (int i = 0; i < num_nodes; ++i) {
if (jobNodeArray[i] != NULL) {
// Print or use jobNodeArray[i] to verify its content
printf("Node is %s\n",jobNodeArray[i]->taxon);
}
}
}

char * root_sequence = NULL;
carry_unambiguous_gaps_up_tree(root);
root_sequence = generate_branch_sequences(root,
Expand Down
2 changes: 2 additions & 0 deletions src/Newickform.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ extern newick_node* build_newick_tree(char * filename, FILE *vcf_file_pointer,in
extern void print_tree(newick_node *root, FILE * outputfile);
void fill_nodeArray(newick_node *root, newick_node** nodeArray);
int count_tree_nodes(newick_node* root);
void get_job_nodes(newick_node** jobNodeArray,newick_node** nodeArray,int* node_depths,int depth,int num_nodes);
void get_job_counts(int *node_depths, int depth, int num_nodes);
extern char* strip_quotes(char *taxon);
#endif

Expand Down

0 comments on commit c7c0f77

Please sign in to comment.