/* usage: extract-seqs ID-file|- seq-file */ #include main (argc, argv) int argc; char *argv []; { FILE *finp_ID, *finp_seq; char ID[20], seq_ID[20], seq[10000]; argv++; if (argc == 3) { if (*argv[0] == '-') finp_ID = stdin; else if (!(finp_ID = fopen(*argv, "r"))) { fprintf(stderr, "ERROR: File \"%s\" not found !!\n", *argv); exit(1); } argv++; if (!(finp_seq = fopen(*argv, "r"))) { fprintf(stderr, "ERROR: File \"%s\" not found !!\n", *argv); exit(1); } } else { fprintf(stderr, "Usage: extract-seqs ID-file seq-file\n"); exit(1); } while (fscanf(finp_ID, "%s", ID) != EOF) { do { if (fscanf(finp_seq, "%s %s", seq_ID, seq) == EOF) { fprintf(stderr, "ERROR: locus \"%s\" NOT found !!; continuing ...\n", ID); rewind(finp_seq); if (fscanf(finp_ID, "%s", ID) == EOF) exit(1); } } while (strcmp(ID, seq_ID)); fprintf(stdout, "%s\t%s\n", ID, seq); fflush(stdout); } }