Heng Li からこのライブラリについてはしばらく前から知っていましたが、これまでは Python が十分に高速だったため、今まで使用しようとはしていませんでした。
ヘッダーへのリンクは次のとおりです: http://lh3lh3.users.sourceforge.net/kseq.shtml
以下を使用して fasta ファイルを解析しようとすると、シーケンス行の長さとして -1 が返されます。Li のコードを調べたところ、これは主に FASTQ 解析用に設計されているようですが、彼の Web ページでは FASTA 形式もサポートしていると述べています。
これが私のコードです:
#include <stdio.h>
#include <stdlib.h>
#include "kseq.h"
// STEP 1: declare the type of file handler and the read() function
KSEQ_INIT(FILE*, read)
int main(int argc, char** argv) {
FILE* fp = fopen(argv[1], "r"); // STEP 2: open the file handler
kseq_t *seq = kseq_init(fp); // STEP 3: initialize seq
int l;
while ((l = kseq_read(seq)) >= 0) { // STEP 4: read sequence
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); // STEP 5: destroy seq
fclose(fp);
return (0);
}
私がテストに使用した FASTA は、Broad Institute を含む複数のソースから入手できる Hg19 GRCH37 ChrY.fa ファイルです。
どんな助けでも大歓迎です。