Fq file to table
3
0
Entering edit mode
2.4 years ago
poltora4enko ▴ 10

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 • 940 views
ADD COMMENT
4
Entering edit mode
2.4 years ago

man paste

cat fastq | paste  - - - -
ADD COMMENT
2
Entering edit mode
2.4 years ago

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

ADD COMMENT
2
Entering edit mode
2.4 years ago
$ 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'
ADD COMMENT

Login before adding your answer.

Traffic: 1532 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6