Skip to content

Instantly share code, notes, and snippets.

@soh-i
Created May 21, 2015 01:18
Show Gist options
  • Select an option

  • Save soh-i/b142924ef2a6d34ecd0b to your computer and use it in GitHub Desktop.

Select an option

Save soh-i/b142924ef2a6d34ecd0b to your computer and use it in GitHub Desktop.
read fasta in C (kseq.h)
#include <stdio.h>
#include <stdlib.h>
#include "kseq.h"
KSEQ_INIT(FILE*, read)
int main(int argc, char** argv)
{
FILE* fp = fopen(argv[1], "r");
if (fp == 0)
{
perror("fopen");
exit(1);
}
kseq_t *seq = kseq_init(fileno(fp));
int l;
while ((l = kseq_read(seq)) >= 0 )
{
printf("name: %s\n", seq->name.s);
printf("seq: %s\n", seq->seq.s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment