This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Fq file to table

Hello all!

I am looking for different ways to convert fq file to tabular format. I mean from this:

@name
AGTC
some_text
HHJH

to this:

@some_name   AGTC   +   HHHH

every four strings in one row

How can I do it with Python/R and in bash/awk?

fastq

3 answers

man paste

cat fastq | paste  - - - -

In Python:

#!/usr/bin/env python

import sys

record = []
for line in sys.stdin:
    record.append(line.rstrip())
    if len(record) == 4:
        sys.stdout.write('{}\n'.format('\t'.join(record)))
        record.clear()

Then: python ./linearize_fastq.py < in.fastq > out.txt

$ awk -v OFS="\t" -v RS="@" 'NR > 1 {print "@"$1,$2,$3,$4}' test.fq
$ awk -v OFS="\t" -v RS="@" 'NR > 1 {gsub("\n","\t"); print "@"$0}' test.fq
$ bioawk -c fastx '{print $seq, $name, $qual}' test.fq
$ seqkit fx2tab test.fq
$ tr -s "\n" "\t" < test.fq | sed -r 's/\t@/\n@/g'

Log in to answer this question.