int main(int argc, char *argv[]) { int ret = 0; tmap_command_t *c = NULL; if(argc < 2) { return tmap_usage(argc, argv); } else { tmap_file_stderr = tmap_file_fdopen(fileno(stderr), "w", TMAP_FILE_NO_COMPRESSION); // set stderr tmap_progress_set_command(argv[1]); // set output progress tmap_progress_set_start_time(); // set start time bam_verbose = 0; // No verbosity in SAMtools c = commands; while(0 <= c->type) { if (0 == strcmp(c->name, argv[1])) { ret = c->func(argc-1, argv+1); break; } c++; } if(c->type < 0) { tmap_help_unknown_cmd(argv[1]); tmap_error1(PACKAGE, "Unknown command", Exit, CommandLineArgument); } // NB: do not close the underlying stderr stream! tmap_file_fclose1(tmap_file_stderr, 0); } return ret; }
int tmap_refseq_refinfo_main(int argc, char *argv[]) { int c, help=0; tmap_refseq_t *refseq = NULL; tmap_file_t *fp_anno = NULL; char *fn_anno = NULL; char *fn_fasta = NULL; while((c = getopt(argc, argv, "vh")) >= 0) { switch(c) { case 'v': tmap_progress_set_verbosity(1); break; case 'h': help = 1; break; default: return 1; } } if(1 != argc - optind || 1 == help) { tmap_file_fprintf(tmap_file_stderr, "Usage: %s %s [-vh] <in.fasta>\n", PACKAGE, argv[0]); return 1; } fn_fasta = argv[optind]; // Note: 'tmap_file_stdout' should not have been previously modified tmap_file_stdout = tmap_file_fdopen(fileno(stdout), "wb", TMAP_FILE_NO_COMPRESSION); // allocate some memory refseq = tmap_calloc(1, sizeof(tmap_refseq_t), "refseq"); refseq->is_rev = 0; refseq->is_shm = 0; // read the annotation file fn_anno = tmap_get_file_name(fn_fasta, TMAP_ANNO_FILE); fp_anno = tmap_file_fopen(fn_anno, "rb", TMAP_ANNO_COMPRESSION); tmap_refseq_read_anno(fp_anno, refseq); tmap_file_fclose(fp_anno); free(fn_anno); // no need to read in the pac refseq->seq = NULL; // print the header tmap_refseq_print_header(tmap_file_stdout, refseq); // destroy tmap_refseq_destroy(refseq); // close the output tmap_file_fclose(tmap_file_stdout); return 0; }
int main(int argc, char *argv[]) { int ret = 0; if(argc < 2) { return usage(); } else { tmap_file_stderr = tmap_file_fdopen(fileno(stderr), "w", TMAP_FILE_NO_COMPRESSION); // set stderr tmap_progress_set_command(argv[1]); // set output progress tmap_progress_set_start_time(); // set start time if (0 == strcmp("index", argv[1])) ret = tmap_index(argc-1, argv+1); else if (0 == strcmp("server", argv[1])) ret = tmap_server_main(argc-1, argv+1); else if (0 == strcmp("map1", argv[1])) ret = tmap_map1_main(argc-1, argv+1); else if (0 == strcmp("map2", argv[1])) ret = tmap_map2_main(argc-1, argv+1); else if (0 == strcmp("map3", argv[1])) ret = tmap_map3_main(argc-1, argv+1); else if (0 == strcmp("mapvsw", argv[1])) ret = tmap_map_vsw_main(argc-1, argv+1); else if (0 == strcmp("mapall", argv[1])) ret = tmap_map_all_main(argc-1, argv+1); else if (0 == strcmp("fasta2pac", argv[1])) ret = tmap_refseq_fasta2pac_main(argc-1, argv+1); else if (0 == strcmp("pac2bwt", argv[1])) ret = tmap_bwt_pac2bwt_main(argc-1, argv+1); else if (0 == strcmp("bwt2sa", argv[1])) ret = tmap_sa_bwt2sa_main(argc-1, argv+1); else if (0 == strcmp("sff2fq", argv[1])) ret = tmap_seq_io_sff2fq_main(argc-1, argv+1); else if (0 == strcmp("refinfo", argv[1])) ret = tmap_refseq_refinfo_main(argc-1, argv+1); else if (0 == strcmp("pac2fasta", argv[1])) ret = tmap_refseq_pac2fasta_main(argc-1, argv+1); #ifdef HAVE_SAMTOOLS else if (0 == strcmp("sam2fs", argv[1])) ret = tmap_sam2fs_main(argc-1, argv+1); #endif #ifdef ENABLE_TMAP_DEBUG_FUNCTIONS else if (0 == strcmp("exact", argv[1])) ret = tmap_debug_exact(argc-1, argv+1); else if (0 == strcmp("fsw", argv[1])) ret = tmap_fsw_main(argc-1, argv+1); else if (0 == strcmp("indexspeed", argv[1])) ret = tmap_index_speed(argc-1, argv+1); else if (0 == strcmp("vswbm", argv[1])) ret = tmap_vswbm_main(argc-1, argv+1); #endif else if (0 == strcmp("--version", argv[1]) || 0 == strcmp("-v", argv[1])) ret = version(); else if (0 == strcmp("--help", argv[1]) || 0 == strcmp("-h", argv[1])) ret = usage(); else { tmap_error1(PACKAGE, "Unknown command", Exit, CommandLineArgument); } // NB: do not close the underlying stderr stream! tmap_file_fclose1(tmap_file_stderr, 0); } return ret; }
int tmap_index(int argc, char *argv[]) { int c; tmap_index_opt_t opt; opt.fn_fasta = NULL; opt.occ_interval = TMAP_BWT_OCC_INTERVAL; opt.hash_width = INT32_MAX; opt.sa_interval = TMAP_SA_INTERVAL; opt.is_large = -1; opt.check_hash = 1; if(2 == argc && 0 == strcmp("--version", argv[1])) { tmap_file_stdout = tmap_file_fdopen(fileno(stdout), "wb", TMAP_FILE_NO_COMPRESSION); tmap_file_fprintf(tmap_file_stdout, "%s\n", tmap_refseq_get_version_format(PACKAGE_VERSION)); tmap_file_fclose(tmap_file_stdout); return 0; } while((c = getopt(argc, argv, "f:o:i:w:a:hvH")) >= 0) { switch(c) { case 'f': opt.fn_fasta = tmap_strdup(optarg); break; case 'o': opt.occ_interval = atoi(optarg); break; case 'i': opt.sa_interval = atoi(optarg); break; case 'w': opt.hash_width = atoi(optarg); break; case 'a': if(0 == strcmp("is", optarg)) opt.is_large = 0; else if(0 == strcmp("bwtsw", optarg)) opt.is_large = 1; else tmap_error("Option -a value not correct", Exit, CommandLineArgument); break; case 'v': tmap_progress_set_verbosity(1); break; case 'h': return usage(&opt); case 'H': opt.check_hash = 0; break; default: return usage(&opt); } } if(argc != optind || 1 == argc) { return usage(&opt); } if(NULL == opt.fn_fasta) { tmap_error("required option -f", Exit, CommandLineArgument); } if(opt.occ_interval < TMAP_BWT_OCC_MOD || 0 != (opt.occ_interval % 2) || 0 != (opt.occ_interval % TMAP_BWT_OCC_MOD)) { tmap_error("option -o out of range", Exit, CommandLineArgument); } if(opt.hash_width < 0) { tmap_error("option -w out of range", Exit, CommandLineArgument); } if(opt.sa_interval <= 0 || (1 < opt.sa_interval && 0 != (opt.sa_interval % 2))) { tmap_error("option -i out of range", Exit, CommandLineArgument); } tmap_index_core(&opt); free(opt.fn_fasta); tmap_progress_print2("terminating successfully"); return 0; }
int tmap_refseq_pac2fasta_main(int argc, char *argv[]) { int c, help=0, amb=0; uint32_t i, j, k; char *fn_fasta = NULL; tmap_refseq_t *refseq = NULL; while((c = getopt(argc, argv, "avh")) >= 0) { switch(c) { case 'a': amb = 1; break; case 'v': tmap_progress_set_verbosity(1); break; case 'h': help = 1; break; default: return 1; } } if(1 != argc - optind || 1 == help) { tmap_file_fprintf(tmap_file_stderr, "Usage: %s %s [-avh] <in.fasta>\n", PACKAGE, argv[0]); return 1; } fn_fasta = argv[optind]; // Note: 'tmap_file_stdout' should not have been previously modified tmap_file_stdout = tmap_file_fdopen(fileno(stdout), "wb", TMAP_FILE_NO_COMPRESSION); // read in the reference sequence refseq = tmap_refseq_read(fn_fasta, 0); for(i=0;i<refseq->num_annos;i++) { tmap_file_fprintf(tmap_file_stdout, ">%s", refseq->annos[i].name->s); // new line handled later for(j=k=0;j<refseq->annos[i].len;j++) { if(0 == (j % TMAP_REFSEQ_FASTA_LINE_LENGTH)) { tmap_file_fprintf(tmap_file_stdout, "\n"); } if(1 == amb && 0 < refseq->annos[i].num_amb) { // move the next ambiguous region while(k < refseq->annos[i].num_amb && refseq->annos[i].amb_positions_end[k] < j+1) { k++; } // check for the ambiguous region if(k < refseq->annos[i].num_amb && 0 == tmap_interval_overlap(j+1, j+1, refseq->annos[i].amb_positions_start[k], refseq->annos[i].amb_positions_end[k])) { tmap_file_fprintf(tmap_file_stdout, "%c", tmap_iupac_int_to_char[refseq->annos[i].amb_bases[k]]); } else { tmap_file_fprintf(tmap_file_stdout, "%c", "ACGTN"[(int)tmap_refseq_seq_i(refseq, j + refseq->annos[i].offset)]); } } else { tmap_file_fprintf(tmap_file_stdout, "%c", "ACGTN"[(int)tmap_refseq_seq_i(refseq, j + refseq->annos[i].offset)]); } } tmap_file_fprintf(tmap_file_stdout, "\n"); } // destroy tmap_refseq_destroy(refseq); // close the output tmap_file_fclose(tmap_file_stdout); return 0; }