Giter VIP home page Giter VIP logo

readfq's Introduction

Readfq is a collection of routines for parsing the FASTA/FASTQ format. It
seamlessly parses both FASTA and multi-line FASTQ with a simple interface.

Readfq is first implemented in a single C header file and then ported to Lua,
Perl and Python as a single function less than 50 lines. For users of scripting
languages, I encourage to copy-and-paste the function instead of using readfq
as a library. It is always good to avoid unnecessary library dependencies.

Readfq also strives for efficiency. The C implementation is among the fastest
(if not the fastest). The Python and Perl implementations are several to tens
of times faster than the official Bio* implementations. If you can speed up
readfq further, please let me know. I am not good at optimizing programs in
scripting languages. Thank you.

As to licensing, the C implementation is distributed under the MIT license.
Implementations in other languages are released without a license. Just copy
and paste. You do not need to acknowledge me. The following shows a brief
example for each programming language:


  # Perl
  my @aux = undef; # this is for keeping intermediate data
  while (my ($name, $seq, $qual) = readfq(\*STDIN, \@aux)) { print "$seq\n"; }


  # Python: generator function
  for name, seq, qual in readfq(sys.stdin): print seq


  -- Lua: closure
  for name, seq, qual in readfq(io.stdin) do print seq end

  /* Go */
  package main

  import (
    "fmt"
    "bufio"
    "github.com/drio/drio.go/bio/fasta"
  )

  func main() {
    var fqr fasta.FqReader
    fqr.Reader = bufio.NewReader(os.Stdin)
    for r, done := fqr.Iter(); !done; r, done = fqr.Iter() {
      fmt.Println(r.Seq)
    }
  }

  /* C */
  #include <zlib.h>
  #include <stdio.h>
  #include "kseq.h"
  KSEQ_INIT(gzFile, gzread)

  int main() {
    gzFile fp;
    kseq_t *seq;
    fp = gzdopen(fileno(stdin), "r");
    seq = kseq_init(fp);
    while (kseq_read(seq) >= 0) puts(seq->seq.s);
    kseq_destroy(seq);
    gzclose(fp);
    return 0;
  }


Some naive benchmarks. To convert a FASTQ containing 25 million 100bp reads to FASTA,
FASTX-Toolkit (parsing 4-line FASTQ only) takes 325.0 CPU seconds and EMBOSS' seqret
247.8 seconds. My seqtk, which uses the kseq.h library, finishes the task in 24.6
seconds, 10X faster. For retrieving 25k sequences by name from the same FASTQ,
BioPython takes 963 seconds, while readfq.py takes 136 seconds; BioPerl takes more
than 40 minutes (killed), while readfq.pl 273 seconds. Seqtk takes 29 seconds.

readfq's People

Contributors

drio avatar brentp avatar lh3 avatar vals avatar

Watchers

Albert Yu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.