Fq file to table
3
0
Entering edit mode
6 weeks ago
poltora4enko ▴ 10

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

  1. @name
  2. AGTC
  3. some_text
  4. 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?

convert Fq • 317 views
ADD COMMENT
4
Entering edit mode
6 weeks ago

man paste

cat fastq | paste  - - - -
ADD COMMENT
2
Entering edit mode
6 weeks 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
6 weeks 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: 2351 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