daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "khash.h" // khash.h from samtools/bwa/seqtk/klib
  5. KHASH_SET_INIT_STR(s)
  6.  
  7. #define BUF_SIZE 4096
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11.     char buf[BUF_SIZE];
  12.     FILE *fp;
  13.     int lineno = 0, flag = 0, ret;
  14.     khash_t(s) *h;
  15.     if (argc == 1) {
  16.         fprintf(stderr, "Usage: cat in.fq | fqextract <name.lst>\n");
  17.         return 1;
  18.     }
  19.     h = kh_init(s);
  20.     fp = fopen(argv[1], "rb"); // FIXME: check fp
  21.     while (fgets(buf, BUF_SIZE, fp))
  22.         kh_put(s, h, strdup(buf), &ret); // FIXME: check ret
  23.     fclose(fp);
  24.     while (fgets(buf, BUF_SIZE, stdin)) {
  25.         if (++lineno%4 == 1)
  26.             flag = (kh_get(s, h, buf + 1) != kh_end(h));
  27.         if (flag) fputs(buf, stdout);
  28.     }
  29.     kh_destroy(s, h); // FIXME: free keys before destroy
  30.     return 0;
  31. }
RAW Paste Data
Top