diff --git a/src/Newickform.c b/src/Newickform.c index e5ff9a28..fe64de64 100644 --- a/src/Newickform.c +++ b/src/Newickform.c @@ -162,7 +162,7 @@ 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; @@ -170,7 +170,7 @@ newick_node* build_newick_tree(char * filename, FILE *vcf_file_pointer,int * snp char *pcOutputFile; char acStrArray[256]; newick_node *root; - char *returnchar; + char *returnchar; FILE *f; @@ -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]; diff --git a/src/Newickform.h b/src/Newickform.h index 6c3f8375..7cf4e356 100644 --- a/src/Newickform.h +++ b/src/Newickform.h @@ -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); diff --git a/src/gubbins.c b/src/gubbins.c index cdc7cdea..4d29ea14 100644 --- a/src/gubbins.c +++ b/src/gubbins.c @@ -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"); @@ -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)); diff --git a/src/gubbins.h b/src/gubbins.h index 10c00d95..94c3dc5a 100644 --- a/src/gubbins.h +++ b/src/gubbins.h @@ -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); diff --git a/src/main.c b/src/main.c index 8d6ca4af..fd184037 100644 --- a/src/main.c +++ b/src/main.c @@ -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) @@ -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} }; @@ -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; @@ -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 {