www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Fastq reader

Dear,
I have wrote anither fastq reader: http://dpaste.dzfl.pl/2a7885dd

--------Example of Fastq File----------------------
 H8:C16L5ACXX:8:1101:1168:2103/1
TCTGAAGGCATGCTGCAATTGTGAATGGCAGAAATGT
+
?  DD>DBDAFDF 4CFGICFHHECHEEBF;E FFFG
 H8:C16L5ACXX:8:1101:1223:2104/1
CTCACTTTTGTACTTTAGACAAGCGCTTTTAGTAGTGCT
+
  ;DD;?DHFFHFG9FAFCEGFGBFE1EFFGFGGHG9D*
 H8:C16L5ACXX:8:1101:1166:2142/1
ATCTGGGAAGACGCCGCCGGGTTCAAA TCACCTTGGTCGGCATCGTCGATCCGC
+
;=?DDDDD3C??) :E1CDD)?B?B<99BB8=<8)8.=A88<8)56;9/>2=??
------------------------------------------------

A fastq file contains a:
- identifier line
- sequence line
- comment line
- quality line

when you loop over Fastq with  following code it will yied each 
turn the type ( identifier, sequence, comment, quality ) and the 
letter

As:

IDENTIFIER  
IDENTIFIER H
IDENTIFIER 8
IDENTIFIER :
IDENTIFIER C
...
IDENTIFIER /
IDENTIFIER 1
SEQUENCE T
SEQUENCE C
SEQUENCE T
SEQUENCE G
...
SEQUENCE A
SEQUENCE T
SEQUENCE G
SEQUENCE T
COMMENT +
QUALITY ?
QUALITY  
QUALITY  
...
QUALITY F
QUALITY F
QUALITY F
QUALITY G

So I would like by example compute in one pass
- number of ACGT in sequence
- count number of quality letter with  
This into distinct function as

------------------------------------------------
     foreach( state, letter; file.Fastq ){
         countBase( state, letter );
         countQuality( state, letter, ' ' );
     }
------------------------------------------------

goal is to be able to add dynamicaly some function while reading 
file

I do not want somethink like
------------------------------------------------
     foreach( state, letter; file.Fastq ){
         if( state == State.SEQUENCE ) stat[letter]++;
         if( state == State.QUALITY &&  letter == ' ' ) count++;
     }
------------------------------------------------

because in this case i can not to write some basics tool

I think delegate i do not know if it is the way to go

Thanks a lot,

I hope my problem is enough clear
Jan 30 2013