Last active
August 29, 2015 14:19
-
-
Save wckdouglas/8f858c9f38604f6143ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <zlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include "kseq.h" | |
#include "khash.h" | |
KSEQ_INIT(gzFile, gzread); | |
KHASH_SET_INIT_STR(s) | |
#define BUF_SIZE 2048 | |
char *strstrip(char *s) | |
{ | |
size_t size; | |
char *end; | |
size = strlen(s); | |
if (!size) | |
return s; | |
end = s + size - 1; | |
while (end >= s && isspace(*end)) | |
end--; | |
*(end + 1) = '\0'; | |
while (*s && isspace(*s)) | |
s++; | |
return s; | |
} | |
int main(int argc , char *argv[]) | |
{ | |
//declare variable | |
char buf[BUF_SIZE]; | |
gzFile fp; | |
kseq_t *seq; | |
int lineno = 0, flag = 0, ret,l; | |
char *id, *sequence, *qual, *comment; | |
khash_t(s) *h; | |
khint_t k; | |
// print usage if not enough argumnets | |
if (argc != 3) | |
{ | |
fprintf(stderr,"Usage: %s <fastq file> <idFile>\n",argv[0]); | |
return 1; | |
} | |
printf("Reading file: %s...\n" ,argv[2] ); | |
//idFile read | |
h = kh_init(s); | |
fp = fopen(argv[2], "rb"); // FIXME: check fp | |
while (fgets(buf, BUF_SIZE, fp)) | |
{ | |
kh_put(s, h, strstrip(strdup(buf)), &ret); // FIXME: check ret | |
} | |
fclose(fp); | |
//open fastq file | |
fp = gzopen(argv[1],"r"); | |
seq = kseq_init(fp); | |
// start reading sequecne | |
while ((l = kseq_read(seq)) >= 0) | |
{ | |
id = seq -> name.s; | |
comment = seq -> comment.s; | |
qual = seq -> qual.s; | |
sequence = seq -> seq.s; | |
flag = (kh_get(s, h, id) == kh_end(h)); | |
if (flag==1){ | |
printf("@%s\t%s\n%s\n+\n%s\n", id,comment,sequence,qual); | |
} | |
} | |
kh_destroy(s,h); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment