Skip to content

Commit

Permalink
Merge pull request #35 from andrewjpage/master
Browse files Browse the repository at this point in the history
resize read line buffer
  • Loading branch information
andrewjpage committed Jun 11, 2012
2 parents 17ec31b + ed1db06 commit 6646d3f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/alignment_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ int read_line(char sequence[], FILE * pFilePtr)


while((pcRes = fgets(current_line_buffer, sizeof(current_line_buffer), pFilePtr)) != NULL){
//append string to line buffer
if( strlen(current_line_buffer) > MAX_READ_BUFFER - 10 )
{
realloc(sequence, strlen(sequence) + MAX_READ_BUFFER + 10 );
}

strcat(sequence, current_line_buffer);
strcpy(current_line_buffer, "");
lineLength = strlen(sequence) - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/alignment_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void get_bases_for_each_snp(char filename[], int snp_locations[], char ** bases_
int read_first_few_characters_of_line(char sequence[], FILE * pFilePtr, int max_characters);


#define MAX_READ_BUFFER 1048576
#define MAX_READ_BUFFER 262144
#define MAX_READ_BUFFER_SMALL 1024
#define MAX_SAMPLE_NAME_SIZE 1024

Expand Down
4 changes: 3 additions & 1 deletion src/parse_phylip.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ int number_of_snps_in_phylib()
void load_sequences_from_phylib(FILE * phylip_file_pointer)
{
rewind(phylip_file_pointer);
char line_buffer[MAX_READ_BUFFER] = {0};
char * line_buffer;
line_buffer = (char *) malloc(MAX_READ_BUFFER*sizeof(char));

int i;

// The first line contains the number of samples and snps
Expand Down
2 changes: 1 addition & 1 deletion src/parse_phylip.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void set_number_of_blocks_for_sample(char * sample_name,int num_blocks);
sample_statistics ** get_sample_statistics();
int number_of_snps_in_phylib();

#define MAX_READ_BUFFER 1048576
#define MAX_READ_BUFFER 262144
#define MAX_SAMPLE_NAME_SIZE 1024


Expand Down
8 changes: 5 additions & 3 deletions src/parse_vcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,15 @@ int get_number_of_columns(char * column_header)
int get_number_of_columns_from_file(FILE * vcf_file_pointer)
{
rewind(vcf_file_pointer);
char szBuffer[100000] = {0};
char result[100] = {0};

char * szBuffer;
szBuffer = (char *) malloc(MAX_READ_BUFFER*sizeof(char));

do{
strcpy(szBuffer,"");
// check the first character of the line to see if its in the header
read_line(szBuffer, vcf_file_pointer);

if(szBuffer[0] == '\0' || szBuffer[0] != '#')
{
break;
Expand All @@ -195,7 +196,8 @@ int get_number_of_columns_from_file(FILE * vcf_file_pointer)
void get_column_names(FILE * vcf_file_pointer, char ** column_names, int number_of_columns)
{
rewind(vcf_file_pointer);
char szBuffer[100000] = {0};
char * szBuffer;
szBuffer = (char *) malloc(MAX_READ_BUFFER*sizeof(char));
char result[100] = {0};
int i;

Expand Down
2 changes: 1 addition & 1 deletion src/parse_vcf.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ void get_column_names(FILE * vcf_file_pointer, char ** column_names, int number_
int column_number_for_column_name(char ** column_names, char * column_name, int number_of_columns);

void get_integers_from_column_in_vcf(FILE * vcf_file_pointer, int * integer_values, int number_of_snps, int column_number);

#define MAX_READ_BUFFER 262144

#endif

0 comments on commit 6646d3f

Please sign in to comment.