Hi,
When trimming reads I found Perl to be really slow for large files.
I wrote this C program to trim at the left and right ends.
Does this look OK to you?
#include<stdio.h>
void main(int argc, char *argv[])
{
FILE *fp_in, *fp_out;
char buffer[1000];
int count_lines;
int left_cut;
int right_cut;
if (argc!=4)
{
printf("Need input and output files and cuts, here's the order:\n");
printf("Input, output, left cut, right cut (reference from the left)\n");
return;
}
fp_in = fopen(argv[1], "r");
fp_out = fopen(argv[2], "w");
sscanf(argv[3],"%d",&left_cut);
sscanf(argv[4],"%d",&right_cut);
//printf("\n%d, %d\n", left_cut, right_cut);
count_lines = 0;
while(!feof(fp_in))
{
fgets(buffer, 1000, fp_in);
if ((count_lines%2)==0)
{
fputs(buffer,fp_out);
}
else
{
buffer[right_cut]=0;
fputs(&buffer[left_cut],fp_out);
fputc('\n',fp_out);
}
count_lines++;
}
fclose(fp_in);
fflush(fp_out);
fclose(fp_out);
}
When trimming reads I found Perl to be really slow for large files.
I wrote this C program to trim at the left and right ends.
Does this look OK to you?
#include<stdio.h>
void main(int argc, char *argv[])
{
FILE *fp_in, *fp_out;
char buffer[1000];
int count_lines;
int left_cut;
int right_cut;
if (argc!=4)
{
printf("Need input and output files and cuts, here's the order:\n");
printf("Input, output, left cut, right cut (reference from the left)\n");
return;
}
fp_in = fopen(argv[1], "r");
fp_out = fopen(argv[2], "w");
sscanf(argv[3],"%d",&left_cut);
sscanf(argv[4],"%d",&right_cut);
//printf("\n%d, %d\n", left_cut, right_cut);
count_lines = 0;
while(!feof(fp_in))
{
fgets(buffer, 1000, fp_in);
if ((count_lines%2)==0)
{
fputs(buffer,fp_out);
}
else
{
buffer[right_cut]=0;
fputs(&buffer[left_cut],fp_out);
fputc('\n',fp_out);
}
count_lines++;
}
fclose(fp_in);
fflush(fp_out);
fclose(fp_out);
}
Comment