I am trying to check if a fastq file has single or paired end reads. How can I achieve this with an error-proof method?

I checked wikipedia and MAQ but I want to know if is there a reliable document that describes all possible variants in sequence ID to check for single/paired end reads.

I am searching also for a library, better in Python, to achieve this.


  • 1
    $\begingroup$ You might be better off asking this question on biostars.org $\endgroup$
    – jarlemag
    Commented Mar 5, 2014 at 17:34
  • $\begingroup$ See for example this question: biostars.org/p/45961 $\endgroup$
    – jarlemag
    Commented Mar 5, 2014 at 17:49
  • $\begingroup$ Thanks @jarlemag. I did some research earlier and I noticed that answer. However there are two problems: first I am not fluent in Perl and it is hard to me to deciphers the content of the accepted answer (not to mention that not being able to check the code could lead to run into bugs that you cannot predict). Second, I read the answer and wikipedia page for FASTQ format but I am searching for the real reference. So I decided to ask a new question not to have a script (related but not main question) but the idea behind that, that could possibly cover all possible variants in this scenario. $\endgroup$
    – gc5
    Commented Mar 5, 2014 at 23:40
  • 1
    $\begingroup$ I see. I found some info on the read identifiers, but held off from answering since it seemed you wanted a complete script. Have you checked out the SeqIO interface in BioPython? $\endgroup$
    – jarlemag
    Commented Mar 5, 2014 at 23:47
  • $\begingroup$ Not yet, sorry.. I am quite a noob in BioPython.. now I'll try it. Thanks $\endgroup$
    – gc5
    Commented Mar 5, 2014 at 23:49

2 Answers 2


By now I got some interesting answers in this question on Biostars

Basically what I did is the following:

  • First of all, I checked if Sequence Id contains paired end notation. As described in this wikipedia page, for Illumina reads there are two possible notation for single/paired end reads:


    If the last number is /2 in some reads then the reads are paired end; otherwise they can be single end.

    The second notation is:

    @EAS139:136:FC706VJ:2:2104:15343:197393 1:Y:18:ATCACG

    If the first number in the second group is 2 in some reads then the reads are paired end; otherwise they can be single end;

  • Then I checked for multiple files. If a sample has two fastq files it is likely that the reads are paired end. It is to note however that with a single file it is not possible to exclude that paired end reads can be interleaved in one single file, even if it is not common (in my opinion);

  • The most general method is to cross check each single reads with the whole set of reads. If the first part of the sequence ID (in this case the field starting from @ and ending before the # - in the first notation - or the whitespace - in the second notation) is unique among all the reads (for each read) it is likely that the reads are single reads, otherwise - if can be found a duplicate for each reads - the reads are paired end. In this case, on *nix systems it can be achieved with the following command (thanks to the biostars answers):

    grep --no-filename @HWUSI-EAS100R:6:73:941:1973 *.fastq | cut -d' ' -f1 | sort | uniq -c | sort -rgk 1,1 | head

    If the result shows in the first lines a result like this:

    1 read1_ID

    1 read2_ID


    It is likely it is single end. Otherwise:

    2 read1_ID

    2 read2_ID


    it is paired end.

I skim read BioPython API documentation but I cannot find something useful to do it.

Suggestions and corrections are welcomed.



This is complementary answer to what @gc5 provided.

For cases that are using "the second notation" which looks like:

@EAS139:136:FC706VJ:2:2104:15343:197393 1:Y:18:ATCACG`
                                        |________________what we are
                                                         trying to extract

The following code will go through all the files iteratively and produce one output per file:

grep -P "^@" *.fastq | grep -oP "\s\d+" | sort | uniq -c

or if you have .fastq.gz files:

zgrep -e "^@" *.fastq.gz | grep -oP "\s\d+" | sort | uniq -c

if you have single-end you will only see ones and if you have paired-end you will see ones and twos. Also as sanity check, you can see how many of each you have:

zgrep --max-count=10000 -e "^@" *.fastq.gz | grep -oP "\s\d+" | sort | uniq -c
6333652  1
6333652  2

Note that I added --max-count=10000 to the last one. This is particularly useful if you have paired-ends in separate files as you will get all ones form one and all twos from the other. This will only go through the first 10'000 lines which makes this one-liner much much faster.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .