Giter Club home page Giter Club logo

kseq's Introduction

kseq

Functionality: a generic stream buffer & FASTA/FASTQ file parser

This kseq is download from https://github.com/mengyao/Complete-Striped-Smith-Waterman-Library/blob/master/src/kseq.h.

gz mode usage

This content is from http://attractivechaos.github.io/klib/#Kseq%3A%20stream%20buffer%20and%20FASTA%2FQ%20parser.

Synopsis

Examples

Example 1: parse FASTA/Q file, optionally compressed with zlib

// to compile: gcc this_prog.c -lz
#include <zlib.h>
#include <stdio.h>
#include "kseq.h"
KSEQ_INIT(gzFile, gzread)

int main(int argc, char *argv[])
{
  gzFile fp;
  kseq_t *seq;
  int l;
  if (argc == 1) {
    fprintf(stderr, "Usage: %s <in.fasta>\n", argv[0]);
    return 1;
  }
  fp = gzopen(argv[1], "r");
  seq = kseq_init(fp);
  while ((l = kseq_read(seq)) >= 0) {
    printf("name: %s\n", seq->name.s);
    if (seq->comment.l) printf("comment: %s\n", seq->comment.s);
    printf("seq: %s\n", seq->seq.s);
    if (seq->qual.l) printf("qual: %s\n", seq->qual.s);
  }
  printf("return value: %d\n", l);
  kseq_destroy(seq);
  gzclose(fp);
  return 0;
}

Example 2: read a text file line-by-line

#include <zlib.h>
#include <stdio.h>
#include <stdlib.h>
#include "kseq.h"
KSTREAM_INIT(gzFile, gzread, 16384)
 
int main(int argc, char *argv[])
{
    gzFile fp;
    kstream_t *ks;
    kstring_t str = {0,0,0};
    if (argc == 1) {
        fprintf(stderr, "Usage: %s <in.txt>\n", argv[0]);
        return 1;
    }
    fp = gzopen(argv[1], "r");
    ks = ks_init(fp);
    while (ks_getuntil(ks, '\n', &str, 0) >= 0)
        printf("%s\n", str.s);
    ks_destroy(ks);
    gzclose(fp);
    free(str.s);
    return 0;
}

Common file usage

See fileread.c for using kseq.h.

I made a simple solution for fileread.c in Visual Studio 2022, called kseq.sln.

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.