I have to read a text file which can begin with optional comments. In practice I have to skip any line at the beginning of the file that doesn’t begin with ‘@’ or ‘>’.
In my test case the file looks like:
# Sun Jul 12 22:04:52 2009 /share/apps/corona/bin/filter_fasta.pl --output=/data/results/solid0065/primary.20090712170542775
# Cwd: /state/partition1/home/pipeline
# Title: solid0065_20090629_FC1_Tomate_Heinz_4_5_Kb_Tomate_Heinz_4_5_Kb_01
>125_963_316_F3
T1230330231223011323010013
So I have to skip the first 3 line (but in general I have to skip n lines). I have to repeat this with 2 or 4 files [which are inside FILE** inputFiles]. I’ve tried with this loop:
buffer = (char*) malloc (sizeof(char) * 5000);
if (buffer == NULL)
notEnoughMemory();
for (i = 0; i < (cIn-1); i++){
fgetpos(inputFiles[i], &position);
fgets(buffer, 4999, inputFiles[i]);
while ((buffer[0] != '@') && (buffer[0] != '>')){
fgetpos(inputFiles[i], &position);
fgets(buffer, 4999, inputFiles[i]);
}
fsetpos(inputFiles[i], &position);
}
Where cIn is number_of_input_files + 1.
Trying to debug it the loop correctly stops after it reads the fourth line. But when I use setpos it doesn’t go back to the beginning of the fourth line as I’d expect, but at the middle of the third.
In fact if, exactly after the fsetpos(), I print buffer after these operations:
fgets(buffer, 4999, inputFiles[i]);
fgets(buffer, 4999, inputFiles[i]);
I get:
FC1_Tomate_Heinz_4_5_Kb_Tomate_Heinz_4_5_Kb_01
>125_963_316_F3
Any idea?
Thanks in advance
You could just skip processing the lines you are not interrested in:
Then you just replace the
puts(buffer);with the code you need to handle the valid lines.(allthough, from your example it sounds like you rather want to only ignore lines starting with a
#, ?)