Skip to content

Commit

Permalink
Enable spectification of thread number
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjcroucher committed Apr 23, 2024
1 parent 0f2658d commit a88692e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/Newickform.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ int max_distance_to_tips(newick_node *root) {
return max_distance;
}

newick_node* build_newick_tree(char * filename, FILE *vcf_file_pointer,int * snp_locations, int number_of_snps, char** column_names, int number_of_columns,int length_of_original_genome,int min_snps, int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag)
newick_node* build_newick_tree(char * filename, FILE *vcf_file_pointer,int * snp_locations, int number_of_snps, char** column_names, int number_of_columns,int length_of_original_genome,int min_snps, int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag, int num_threads)
{
int iLen, iMaxLen;
char *pcTreeStr;
char *pcInputFile;
char *pcOutputFile;
char acStrArray[256];
newick_node *root;
char *returnchar;
char *returnchar;

FILE *f;

Expand Down Expand Up @@ -249,7 +249,6 @@ newick_node* build_newick_tree(char * filename, FILE *vcf_file_pointer,int * snp
}

// Initiate multithreading
int num_threads = 1; // Adjust as needed
pthread_t threads[num_threads];
struct ThreadData threadData[num_threads];

Expand Down
4 changes: 2 additions & 2 deletions src/Newickform.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ struct ThreadData {

#ifdef __NEWICKFORM_C__
newick_node* parseTree(char *str);
newick_node* build_newick_tree(char * filename, FILE *vcf_file_pointer,int * snp_locations, int number_of_snps, char** column_names, int number_of_columns, int length_of_original_genome,int min_snps, int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag);
newick_node* build_newick_tree(char * filename, FILE *vcf_file_pointer,int * snp_locations, int number_of_snps, char** column_names, int number_of_columns, int length_of_original_genome,int min_snps, int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag, int num_threads);
void print_tree(newick_node *root, FILE * outputfile);
char* strip_quotes(char *taxon);
#else
extern newick_node* parseTree(char *str);
extern newick_node* build_newick_tree(char * filename, FILE *vcf_file_pointer,int * snp_locations, int number_of_snps, char** column_names, int number_of_columns, int length_of_original_genome,int min_snps, int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag);
extern newick_node* build_newick_tree(char * filename, FILE *vcf_file_pointer,int * snp_locations, int number_of_snps, char** column_names, int number_of_columns, int length_of_original_genome,int min_snps, int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag, int num_threads);
void* threadFunction(void* arg);
extern void print_tree(newick_node *root, FILE * outputfile);
void fill_nodeArray(newick_node *root, newick_node** nodeArray);
Expand Down
8 changes: 4 additions & 4 deletions src/gubbins.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
// given a sample name extract the sequences from the vcf
// compare two sequences to get pseudo sequnece and fill in with difference from reference sequence

void run_gubbins(char vcf_filename[], char tree_filename[],char multi_fasta_filename[], int min_snps, char original_multi_fasta_filename[], int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag)
void run_gubbins(char vcf_filename[], char tree_filename[],char multi_fasta_filename[], int min_snps, char original_multi_fasta_filename[], int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag, int num_threads)
{
load_sequences_from_multifasta_file(multi_fasta_filename);
extract_sequences(vcf_filename, tree_filename, multi_fasta_filename,min_snps,original_multi_fasta_filename,window_min, window_max, uncorrected_p_value, trimming_ratio, extensive_search_flag);
extract_sequences(vcf_filename, tree_filename, multi_fasta_filename,min_snps,original_multi_fasta_filename,window_min, window_max, uncorrected_p_value, trimming_ratio, extensive_search_flag, num_threads);
create_tree_statistics_file(tree_filename,get_sample_statistics(),number_of_samples_from_parse_phylip());
freeup_memory();
}


void extract_sequences(char vcf_filename[], char tree_filename[],char multi_fasta_filename[],int min_snps, char original_multi_fasta_filename[], int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag)
void extract_sequences(char vcf_filename[], char tree_filename[],char multi_fasta_filename[],int min_snps, char original_multi_fasta_filename[], int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag, int num_threads)
{
FILE *vcf_file_pointer;
vcf_file_pointer=fopen(vcf_filename, "r");
Expand All @@ -74,7 +74,7 @@ void extract_sequences(char vcf_filename[], char tree_filename[],char multi_fast

get_integers_from_column_in_vcf(vcf_file_pointer, snp_locations, number_of_snps, column_number_for_column_name(column_names, "POS", number_of_columns));

root_node = build_newick_tree(tree_filename, vcf_file_pointer,snp_locations, number_of_snps, column_names, number_of_columns, length_of_original_genome,min_snps,window_min, window_max, uncorrected_p_value, trimming_ratio, extensive_search_flag);
root_node = build_newick_tree(tree_filename, vcf_file_pointer,snp_locations, number_of_snps, column_names, number_of_columns, length_of_original_genome,min_snps,window_min, window_max, uncorrected_p_value, trimming_ratio, extensive_search_flag, num_threads);
fclose(vcf_file_pointer);

int* filtered_snp_locations = calloc((number_of_snps+1), sizeof(int));
Expand Down
4 changes: 2 additions & 2 deletions src/gubbins.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include "seqUtil.h"
#include "Newickform.h"

void run_gubbins(char vcf_filename[], char tree_filename[], char multi_fasta_filename[], int min_snps, char original_multi_fasta_filename[], int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag);
void extract_sequences(char vcf_filename[], char tree_filename[],char multi_fasta_filename[], int min_snps, char original_multi_fasta_filename[], int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag);
void run_gubbins(char vcf_filename[], char tree_filename[], char multi_fasta_filename[], int min_snps, char original_multi_fasta_filename[], int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag, int num_threads);
void extract_sequences(char vcf_filename[], char tree_filename[],char multi_fasta_filename[], int min_snps, char original_multi_fasta_filename[], int window_min, int window_max, float uncorrected_p_value, float trimming_ratio, int extensive_search_flag, int n_threads);
char find_first_real_base(int base_position, int number_of_child_sequences, char ** child_sequences);


Expand Down
8 changes: 7 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ int main (int argc, char ** argv)
float uncorrected_p_value = 0.05;
float trimming_ratio = 1.0;
int extensive_search_flag = 0;
int num_threads = 1;
program_name = argv[0];

while (1)
Expand All @@ -103,6 +104,7 @@ int main (int argc, char ** argv)
{"p_value", required_argument, 0, 'p'},
{"trimming_ratio", required_argument, 0, 'i'},
{"extended_search", required_argument, 0, 'x'},
{"ncpu", required_argument, 0, 'n'},

{0, 0, 0, 0}
};
Expand Down Expand Up @@ -157,6 +159,9 @@ int main (int argc, char ** argv)
case 't':
memcpy(tree_filename, optarg, size_of_string(optarg) +1);
break;
case 'n':
num_threads = atoi(optarg);
break;
case '?':
/* getopt_long already printed an error message. */
break;
Expand Down Expand Up @@ -188,7 +193,8 @@ int main (int argc, char ** argv)
window_max,
uncorrected_p_value,
trimming_ratio,
extensive_search_flag);
extensive_search_flag,
num_threads);
}
else
{
Expand Down

0 comments on commit a88692e

Please sign in to comment.