예제 #1
0
파일: seqlist.c 프로젝트: Qiugoodboy/mycode
int main(int argc, const char *argv[])
{
	int num,ret;
	seq_plist l;

	seqlist_init(&l);

	while(1)
	{
		printf("pls input num:");
		ret = scanf("%d",&num);
		if(1 == ret)
		{
			if(num > 0)
				seqlist_insert(l,num);
#if 1
			else 
				seqlist_del(l,-num);
#endif
		}else 
			break;
		seqlist_show(l);
	}
	return 0;
}
예제 #2
0
int main(int argc, char **argv){
 
  FILE *IN, *OUT;
  seqlist_t IDs;
  sequence_t *seq;

  int i, keep, excl;
  char *prog, *list, *f, *out, *id;
  /* todo convert to uint_64 */
  uint64_t n, total;

  /* default values */
  prog = basename(*argv);
  list = NULL;
  out = NULL;
  OUT = stdout; 
  excl = keep = 0;

  /* Check command line */
  while ((i = getopt(argc, argv, "hl:o:x")) != -1) {
    switch (i) {
    case 'h':
      usage(prog, EXIT_SUCCESS); break;
	 case 'l':
		list = optarg; break;
	 case 'o':
		out = optarg; break;
	 case 'x':
		excl = 1; break;
	 default:
		usage(prog, EXIT_FAILURE); 
	 }
  }
  /* some files to deal with ? */
  if (argc - optind < 1) { usage(prog,  EXIT_FAILURE); }

  /* get ids from list */
  if (list != NULL) {
	 if ((IN = fopen(list, "r")) == NULL) 
		err(EXIT_FAILURE, "%s", list);

	 seqlist_init(&IDs);
	 i = seqlist_populate(&IDs, IN);
	 if (i == 0) errx(EXIT_FAILURE, "file: %s no identifier found", list); 
	 
	 if (fclose(IN) == EOF) err(EXIT_FAILURE, "%s: close failed", list);

    seqlist_sort(&IDs); 
  }

  /* open output file */
  if ((out != NULL) && ((OUT = fopen(out, "w")) == NULL))
	 err(EXIT_FAILURE, "%s", out);

  total = n = 0;

  /* start filtering all argument file*/
  for (i = optind; i < argc; i++) {
    f = *(argv+i);
	 if ((IN = fopen(f, "r")) == NULL) err(EXIT_FAILURE, "%s", f);
	 
	 while ((seq = sequence_parse(IN, SEQFMT_FASTA)) != NULL) {
		total++;
		id = seq->nam;
		keep = 1;
		if (list != NULL) { keep = 1 - seqlist_chk(&IDs, id); }
		if (excl == 1)   { keep = 1 - keep; }
		if (keep == 1) { n++; sequence_print(OUT, seq, SEQFMT_FASTA); }
		sequence_free(seq);
	 }//end while
	 
	  /* check for parsing error vs EOF */
	 if ((feof(IN) == 0) || (total == 0)){
		errx(1, "%s: unable to read sequence %d", f, total+1);
	 }
	 
	 if (fclose(IN) == EOF) err(EXIT_FAILURE, "%s: close failed", f);
  }//end for files
  
  if ((out != NULL) && (fclose(OUT) == EOF)) err(EXIT_FAILURE, "%s", out);
  if (list != NULL) seqlist_fini(&IDs);
  
  /*display resume on stderr */
  fprintf(stderr, "file %s: Extracted %"PRI_U64" from %"PRI_U64" sequences (%.2f %%)\n" ,
          basename(f), n , total, (float)(n)/total*100.0);

  return EXIT_SUCCESS; 
}