void Datadir_avail_maps (FILE *fp, char *user_mapdir, char *genomesubdir, char *fileroot) { char *mapdir; struct dirent *entry; char *filename; DIR *dp; List_T maps = NULL; char **array; int n, i; mapdir = Datadir_find_mapdir(user_mapdir,genomesubdir,fileroot); fprintf(fp,"Available maps in directory %s:\n",mapdir); if ((dp = opendir(mapdir)) == NULL) { fprintf(stderr,"Unable to open mapdir %s\n",mapdir); exit(9); } while ((entry = readdir(dp)) != NULL) { if (entry->d_name[0] != '.') { filename = (char *) CALLOC(strlen(mapdir)+strlen("/")+strlen(entry->d_name)+1, sizeof(char)); sprintf(filename,"%s/%s",mapdir,entry->d_name); if (Access_file_exists_p(filename) == true) { FREE(filename); filename = (char *) CALLOC(strlen(entry->d_name)+1,sizeof(char)); strcpy(filename,entry->d_name); maps = List_push(maps,(void *) filename); } else { FREE(filename); } } } if (closedir(dp) < 0) { fprintf(stderr,"Unable to close mapdir %s\n",mapdir); } if ((n = List_length(maps)) == 0) { fprintf(fp," (none found)\n"); } else { array = (char **) List_to_array(maps,NULL); qsort(array,n,sizeof(char *),strcmp_cmp); for (i = 0; i < n; i++) { fprintf(fp,"%s\n",array[i]); FREE(array[i]); } FREE(array); List_free(&maps); } FREE(mapdir); return; }
void Datadir_avail_gmap_databases (FILE *fp, char *user_genomedir) { char *genomedir; struct dirent *entry; char *filename; DIR *dp; List_T databases = NULL; char **array; int n, i; genomedir = Datadir_find_genomedir(user_genomedir); fprintf(fp,"Available gmap databases in directory %s:\n",genomedir); if ((dp = opendir(genomedir)) == NULL) { fprintf(stderr,"Unable to open genomedir %s\n",genomedir); exit(9); } while ((entry = readdir(dp)) != NULL) { filename = (char *) CALLOC(strlen(genomedir)+strlen("/")+strlen(entry->d_name)+strlen("/")+ strlen(entry->d_name)+strlen(".version")+1,sizeof(char)); sprintf(filename,"%s/%s/%s.version",genomedir,entry->d_name,entry->d_name); if (Access_file_exists_p(filename) == true) { FREE(filename); filename = (char *) CALLOC(strlen(entry->d_name)+1,sizeof(char)); strcpy(filename,entry->d_name); databases = List_push(databases,(void *) filename); } else { FREE(filename); } } if (closedir(dp) < 0) { fprintf(stderr,"Unable to close genomedir %s\n",genomedir); } if ((n = List_length(databases)) == 0) { fprintf(fp," (none found)\n"); } else { array = (char **) List_to_array(databases,NULL); qsort(array,n,sizeof(char *),strcmp_cmp); for (i = 0; i < n; i++) { fprintf(fp,"%s\n",array[i]); FREE(array[i]); } FREE(array); List_free(&databases); } FREE(genomedir); return; }
static int * get_matches_multiple_typed (int *nmatches, char **divstring, Univcoord_T *coordstart, Univcoord_T *coordend, int **leftflanks, int *nleftflanks, int **rightflanks, int *nrightflanks, char *query, int *types, int ntypes, IIT_T *iit, char *filename) { int *matches; bool revcomp; if (force_label_p == true || (force_coords_p == false && Parserange_query(&(*divstring),&(*coordstart),&(*coordend),&revcomp,query,filename) == false)) { /* Not expecting a label */ abort(); } if ((*iit = IIT_read(filename,/*name*/NULL,true,/*divread*/READ_ONE,*divstring,/*add_iit_p*/true, /*labels_read_p*/false)) == NULL) { if (Access_file_exists_p(filename) == false) { fprintf(stderr,"Cannot read file %s\n",filename); } else { fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename); } exit(9); } else if (fieldstring != NULL) { if ((fieldint = IIT_fieldint(*iit,fieldstring)) < 0) { fprintf(stderr,"No field %s defined in iit file.\n",fieldstring); exit(9); } } matches = IIT_get_multiple_typed(&(*nmatches),*iit,*divstring,*coordstart,*coordend,types,ntypes,sortp); if (nflanking > 0) { IIT_get_flanking_multiple_typed(&(*leftflanks),&(*nleftflanks),&(*rightflanks),&(*nrightflanks),*iit,*divstring, *coordstart,*coordend,nflanking,types,ntypes); } return matches; }
int main (int argc, char *argv[]) { char *filename; char *divstring = NULL, *lasttypestring, *ptr; Univcoord_T univ_coordstart, univ_coordend; Chrpos_T coordstart, coordend, lastcoord = 0U; char Buffer[BUFLEN], nocomment[BUFLEN], query[BUFLEN], typestring[BUFLEN]; int typeint, *types, c; int nargs, ntypes, ndivs; int *value_matches = NULL, *matches = NULL; int n_value_matches = 0, nmatches = 0, i; int *leftflanks, *rightflanks, nleftflanks = 0, nrightflanks = 0; long int total; int n; IIT_T iit = NULL; Univ_IIT_T chromosome_iit = NULL; bool skipp, universalp; int opt; extern int optind; extern char *optarg; const char *long_name; int long_option_index = 0; while ((opt = getopt_long(argc,argv,"a:b:f:LCASUu:c:HRTZN",long_options,&long_option_index)) != -1) { switch (opt) { case 0: long_name = long_options[long_option_index].name; if (!strcmp(long_name,"version")) { print_program_version(); exit(0); } else if (!strcmp(long_name,"help")) { print_program_usage(); exit(0); } else if (!strcmp(long_name,"exact")) { exactp = true; } else { /* Shouldn't reach here */ fprintf(stderr,"Don't recognize option %s. For usage, run 'gsnap --help'",long_name); exit(9); } break; case 'a': lowval = atof(optarg); user_lowvalue_p = true; value_matches_p = true; break; case 'b': highval = atof(optarg); user_highvalue_p = true; value_matches_p = true; break; case 'f': fieldstring = optarg; break; case 'L': force_label_p = true; break; case 'C': force_coords_p = true; break; case 'A': annotationonlyp = true; break; case 'S': sortp = true; break; case 'U': signedp = false; break; case 'u': nflanking = atoi(optarg); break; case 'c': centerp = true; centerlength = atoi(optarg); break; case 'H': centeruc = true; break; case 'R': runlengthp = true; break; case 'T': tallyp = true; break; case 'Z': zeroesp = true; break; case 'N': statsp = true; break; case 'V': print_program_version(); exit(0); case '?': print_program_usage(); exit(0); default: exit(9); } } argc -= (optind - 1); argv += (optind - 1); if (argc <= 1) { fprintf(stderr,"Need to specify an iit file. Type \"iit_get --help\" for help.\n"); exit(9); } else { filename = argv[1]; } if (value_matches_p == true) { if ((iit = IIT_read(filename,/*name*/NULL,true,/*divread*/READ_ALL,/*divstring*/NULL, /*add_iit_p*/true,/*labels_read_p*/true)) == NULL) { if (Access_file_exists_p(filename) == false) { fprintf(stderr,"Cannot read file %s\n",filename); } else { fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename); } exit(9); } else if (fieldstring != NULL) { if ((fieldint = IIT_fieldint(iit,fieldstring)) < 0) { fprintf(stderr,"No field %s defined in iit file.\n",fieldstring); exit(9); } } if (IIT_valuep(iit) == false) { fprintf(stderr,"Error: This IIT file does not have values stored\n"); exit(9); } if (user_lowvalue_p == true && user_highvalue_p == true) { if (lowval > highval) { fprintf(stderr,"Cannot have lowval %f > highval %f\n",lowval,highval); exit(9); } else { value_matches = IIT_get_values_between(&n_value_matches,iit,lowval,highval,/*sortp*/false); } } else if (user_lowvalue_p == true) { value_matches = IIT_get_values_above(&n_value_matches,iit,lowval,/*sortp*/false); } else { /* user_highvalue_p == true */ value_matches = IIT_get_values_below(&n_value_matches,iit,highval,/*sortp*/false); } } if (0 && statsp == true && argc == 2) { /* Want total over entire IIT */ if ((iit = IIT_read(filename,NULL,true,/*divread*/READ_ALL,/*divstring*/NULL,/*add_iit_p*/true, /*labels_read_p*/false)) == NULL) { if (Access_file_exists_p(filename) == false) { fprintf(stderr,"Cannot read file %s\n",filename); } else { fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename); } exit(9); } else if (fieldstring != NULL) { if ((fieldint = IIT_fieldint(iit,fieldstring)) < 0) { fprintf(stderr,"No field %s defined in iit file.\n",fieldstring); exit(9); } } total = 0; n = 0; for (i = 0; i < IIT_total_nintervals(iit); i++) { debug(printf("index = %d\n",matches[i])); compute_totals_tally(&total,&n,/*coordstart*/0,/*coordend*/-1U,i,iit); } printf("counts:%ld non-zero-positions:%u mean-over-nonzero:%.3f\n",total,n,(double) total/(double) n); IIT_free(&iit); return 0; } else if ((universalp = IIT_universalp(filename,/*add_iit_p*/true)) == true) { chromosome_iit = Univ_IIT_read(filename,/*readonlyp*/true,/*add_iit_p*/true); if (argc != 3) { fprintf(stderr,"For chromosome IIT file, need to specify a query on the command line\n"); exit(9); } else { /* Try as 0:<iitfile> 1:<query> */ matches = get_matches_univ(&nmatches,&divstring,&univ_coordstart,&univ_coordend, &leftflanks,&nleftflanks,&rightflanks,&nrightflanks, argv[2],/*typestring*/NULL,&chromosome_iit,filename); for (i = 0; i < nmatches; i++) { debug(printf("\nindex = %d\n",matches[i])); print_interval_univ(univ_coordstart,univ_coordend,matches[i],chromosome_iit); } } if (divstring != NULL) { FREE(divstring); } Univ_IIT_free(&chromosome_iit); return 0; } else if (argc == 2 && value_matches_p == true) { /* Note: Could potentially handle input from stdin, but currently just deal with value_matches */ ndivs = IIT_ndivs(iit); for (i = 0; i < n_value_matches; i++) { debug(printf("\nindex = %d\n",matches[i])); print_interval(&lastcoord,/*total*/0,/*divstring*/NULL,/*coordstart*/0,/*coordend*/0, value_matches[i],iit,ndivs,fieldint); } FREE(value_matches); IIT_free(&iit); return 0; } else if (argc == 2) { debug(printf("Running under argc 2\n")); /* Expecting input from stdin */ if ((iit = IIT_read(filename,NULL,true,/*divread*/READ_ALL,/*divstring*/NULL,/*add_iit_p*/true, /*labels_read_p*/true)) == NULL) { if (Access_file_exists_p(filename) == false) { fprintf(stderr,"Cannot read file %s\n",filename); } else { fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename); } exit(9); } else if (fieldstring != NULL) { if ((fieldint = IIT_fieldint(iit,fieldstring)) < 0) { fprintf(stderr,"No field %s defined in iit file.\n",fieldstring); exit(9); } } while (fgets(Buffer,BUFLEN,stdin) != NULL) { if ((ptr = rindex(Buffer,'\n')) != NULL) { *ptr = '\0'; } strcpy(nocomment,Buffer); if ((ptr = rindex(nocomment,'#')) != NULL) { *ptr = '\0'; } skipp = false; if ((nargs = sscanf(nocomment,"%s %s",query,typestring)) == 2) { debug(printf("typestring is %s\n",typestring)); matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend, &leftflanks,&nleftflanks,&rightflanks,&nrightflanks, query,typestring,&iit,filename); coordstart = (Chrpos_T) univ_coordstart; coordend = (Chrpos_T) univ_coordend; } else if (nargs == 1) { debug(printf("typestring is NULL\n")); matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend, &leftflanks,&nleftflanks,&rightflanks,&nrightflanks, query,/*typestring*/NULL,&iit,filename); coordstart = (Chrpos_T) univ_coordstart; coordend = (Chrpos_T) univ_coordend; } else { fprintf(stderr,"Can't parse line %s. Ignoring.\n",nocomment); skipp = true; } total = 0; if (skipp == false) { fprintf(stdout,"# Query: %s\n",Buffer); ndivs = IIT_ndivs(iit); if (nflanking > 0) { for (i = nleftflanks-1; i >= 0; i--) { debug(printf("\nleft index = %d\n",leftflanks[i])); print_interval(&lastcoord,/*total*/0,divstring,coordstart,coordend,leftflanks[i],iit,ndivs,fieldint); } printf("====================\n"); FREE(leftflanks); } lastcoord = coordstart; for (i = 0; i < nmatches; i++) { debug(printf("\nindex = %d\n",matches[i])); total = print_interval(&lastcoord,total,divstring,coordstart,coordend,matches[i],iit,ndivs,fieldint); } if (nflanking > 0) { printf("====================\n"); for (i = 0; i < nrightflanks; i++) { debug(printf("\nright index = %d\n",rightflanks[i])); print_interval(&lastcoord,/*total*/0,divstring,coordstart,coordend,rightflanks[i],iit,ndivs,fieldint); } FREE(rightflanks); } if (zeroesp == true) { while (lastcoord <= coordend) { printf("%s\t%u\t%d\n",divstring,lastcoord,0); lastcoord++; } } } if (divstring != NULL) { FREE(divstring); } FREE(matches); printf("%ld\n",total); fprintf(stdout,"# End\n"); fflush(stdout); } IIT_free(&iit); return 0; } else { /* Get coordinates/type from command line */ if (argc == 3) { /* Try as 0:<iitfile> 1:<query> */ matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend, &leftflanks,&nleftflanks,&rightflanks,&nrightflanks, argv[2],/*typestring*/NULL,&iit,filename); coordstart = (Chrpos_T) univ_coordstart; coordend = (Chrpos_T) univ_coordend; } else if (argc == 4) { /* Try as 0:<iitfile> 1:<query> 2:<type> */ debug(printf("Running under argc 4\n")); matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend, &leftflanks,&nleftflanks,&rightflanks,&nrightflanks, argv[2],argv[3],&iit,filename); coordstart = (Chrpos_T) univ_coordstart; coordend = (Chrpos_T) univ_coordend; } else { types = (int *) CALLOC(argc-3,sizeof(int)); for (c = 3, ntypes = 0; c < argc; c++) { if ((typeint = IIT_typeint(iit,argv[c])) < 0) { fprintf(stderr,"No such type as %s. Ignoring the type.\n",argv[c]); } else { types[ntypes++] = typeint; lasttypestring = argv[c]; } } if (ntypes == 0) { matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend, &leftflanks,&nleftflanks,&rightflanks,&nrightflanks, argv[2],/*typestring*/NULL,&iit,filename); coordstart = (Chrpos_T) univ_coordstart; coordend = (Chrpos_T) univ_coordend; } else if (ntypes == 1) { matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend, &leftflanks,&nleftflanks,&rightflanks,&nrightflanks, argv[2],lasttypestring,&iit,filename); coordstart = (Chrpos_T) univ_coordstart; coordend = (Chrpos_T) univ_coordend; } else { matches = get_matches_multiple_typed(&nmatches,&divstring,&univ_coordstart,&univ_coordend, &leftflanks,&nleftflanks,&rightflanks,&nrightflanks, argv[2],types,ntypes,&iit,filename); coordstart = (Chrpos_T) univ_coordstart; coordend = (Chrpos_T) univ_coordend; } } if (value_matches_p == true) { matches = match_intersection(&nmatches,/*matches1*/matches,/*nmatches1*/nmatches, /*matches2*/value_matches,/*nmatches2*/n_value_matches); FREE(value_matches); } #if 0 if (centerp == true) { print_spaces(centerlength); printf("*"); print_spaces(centerlength-1); printf("\n"); } #endif if (statsp == true) { total = 0; n = 0; for (i = 0; i < nmatches; i++) { debug(printf("index = %d\n",matches[i])); compute_totals_tally(&total,&n,coordstart,coordend,matches[i],iit); } n = coordend - coordstart + 1; printf("counts:%ld width:%u mean:%.3f\n",total,n,(double)total/(double) n); #if 0 } else if (geomeanp == true) { logtotal = 0.0; total = 0; n = 0; for (i = 0; i < nmatches; i++) { debug(printf("index = %d\n",matches[i])); logtotal = compute_logtotal_tally(&total,&n,coordstart,coordend,matches[i],iit); } printf("geomean:%f totalcounts:%ld posrange:%d\n", exp(logtotal/(double) (coordend - coordstart + 1)) - 1.0,total,n); #endif } else { ndivs = IIT_ndivs(iit); if (nflanking > 0) { for (i = nleftflanks-1; i >= 0; i--) { debug(printf("\nleft index = %d\n",leftflanks[i])); print_interval(&lastcoord,/*total*/0,divstring,coordstart,coordend,leftflanks[i],iit,ndivs,fieldint); } printf("====================\n"); FREE(leftflanks); } lastcoord = coordstart; for (i = 0; i < nmatches; i++) { debug(printf("\nindex = %d\n",matches[i])); print_interval(&lastcoord,/*total*/0,divstring,coordstart,coordend,matches[i],iit,ndivs,fieldint); } if (nflanking > 0) { printf("====================\n"); for (i = 0; i < nrightflanks; i++) { debug(printf("\nright index = %d\n",rightflanks[i])); print_interval(&lastcoord,/*total*/0,divstring,coordstart,coordend,rightflanks[i],iit,ndivs,fieldint); } FREE(rightflanks); } } if (divstring != NULL) { FREE(divstring); } FREE(matches); IIT_free(&iit); return 0; } }
static int * get_matches_univ (int *nmatches, char **divstring, Univcoord_T *coordstart, Univcoord_T *coordend, int **leftflanks, int *nleftflanks, int **rightflanks, int *nrightflanks, char *query, char *typestring, Univ_IIT_T *chromosome_iit, char *filename) { int *matches; bool revcomp; int typeint; debug(printf("Entering get_matches_univ with query %s.\n",query)); if (force_label_p == true || (force_coords_p == false && Parserange_query(&(*divstring),&(*coordstart),&(*coordend),&revcomp,query,filename) == false)) { /* Treat query as a label */ *divstring = (char *) NULL; if (*chromosome_iit == NULL) { /* Read no divs */ if ((*chromosome_iit = Univ_IIT_read(filename,/*readonlyp*/true,/*add_iit_p*/true)) == NULL) { if (Access_file_exists_p(filename) == false) { fprintf(stderr,"Cannot read file %s\n",filename); } else { fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename); } exit(9); } } *nleftflanks = *nrightflanks = 0; matches = Univ_IIT_find(&(*nmatches),*chromosome_iit,query); } else { if (*chromosome_iit == NULL) { if ((*chromosome_iit = Univ_IIT_read(filename,/*readonlyp*/true,/*add_iit_p*/true)) == NULL) { if (Access_file_exists_p(filename) == false) { fprintf(stderr,"Cannot read file %s\n",filename); } else { fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename); } exit(9); } } if (typestring == NULL) { /* Treat query as coordinates, without a typestring */ matches = Univ_IIT_get(&(*nmatches),*chromosome_iit,*coordstart,*coordend); if (nflanking > 0) { fprintf(stderr,"Flanking not supported on chromosome IIT\n"); } *nleftflanks = *nrightflanks = 0; } else if ((typeint = Univ_IIT_typeint(*chromosome_iit,typestring)) < 0) { fprintf(stderr,"No such type as %s.\n",typestring); #if 0 /* Treat query as coordinates, without a typestring */ matches = Univ_IIT_get(&(*nmatches),*chromosome_iit,*coordstart,*coordend); if (nflanking > 0) { fprintf(stderr,"Flanking not supported on chromosome IIT\n"); } *nleftflanks = *nrightflanks = 0; #else matches = (int *) NULL; *nleftflanks = *nrightflanks = 0; *nmatches = 0; #endif } else { /* Treat query as coordinates, with a typestring */ fprintf(stderr,"Ignoring types on chromosome IIT\n"); matches = Univ_IIT_get(&(*nmatches),*chromosome_iit,*coordstart,*coordend); *nleftflanks = *nrightflanks = 0; } } return matches; }
static int * get_matches (int *nmatches, char **divstring, Univcoord_T *coordstart, Univcoord_T *coordend, int **leftflanks, int *nleftflanks, int **rightflanks, int *nrightflanks, char *query, char *typestring, IIT_T *iit, char *filename) { int *matches; bool revcomp; int typeint; debug(printf("Entering get_matches with query %s.\n",query)); if (force_label_p == true || (force_coords_p == false && Parserange_query(&(*divstring),&(*coordstart),&(*coordend),&revcomp,query,filename) == false)) { /* Treat query as a label */ *divstring = (char *) NULL; if (*iit == NULL) { /* Read no divs */ if ((*iit = IIT_read(filename,/*name*/NULL,true,/*divread*/READ_NONE,/*divstring*/NULL, /*add_iit_p*/true,/*labels_read_p*/true)) == NULL) { if (Access_file_exists_p(filename) == false) { fprintf(stderr,"Cannot read file %s\n",filename); } else { fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename); } exit(9); } else if (fieldstring != NULL) { if ((fieldint = IIT_fieldint(*iit,fieldstring)) < 0) { fprintf(stderr,"No field %s defined in iit file.\n",fieldstring); exit(9); } } } *nleftflanks = *nrightflanks = 0; matches = IIT_find(&(*nmatches),*iit,query); } else { if (*iit == NULL) { if ((*iit = IIT_read(filename,/*name*/NULL,true,/*divread*/READ_ONE,*divstring, /*add_iit_p*/true,/*labels_read_p*/false)) == NULL) { if (Access_file_exists_p(filename) == false) { fprintf(stderr,"Cannot read file %s\n",filename); } else { fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename); } exit(9); } else if (fieldstring != NULL) { if ((fieldint = IIT_fieldint(*iit,fieldstring)) < 0) { fprintf(stderr,"No field %s defined in iit file.\n",fieldstring); exit(9); } } } if (typestring == NULL) { /* Treat query as coordinates, without a typestring */ if (exactp == true) { matches = IIT_get_exact_multiple(&(*nmatches),*iit,*divstring,*coordstart,*coordend,/*type*/0); } else { matches = IIT_get(&(*nmatches),*iit,*divstring,*coordstart,*coordend,sortp); } if (nflanking > 0) { IIT_get_flanking(&(*leftflanks),&(*nleftflanks),&(*rightflanks),&(*nrightflanks),*iit,*divstring, *coordstart,*coordend,nflanking,/*sign*/0); } } else if ((typeint = IIT_typeint(*iit,typestring)) < 0) { fprintf(stderr,"No such type as %s.\n",typestring); #if 0 /* Treat query as coordinates, without a typestring */ matches = IIT_get(&(*nmatches),*iit,*divstring,*coordstart,*coordend,sortp); if (nflanking > 0) { IIT_get_flanking(&(*leftflanks),&(*nleftflanks),&(*rightflanks),&(*nrightflanks),*iit,*divstring, *coordstart,*coordend,nflanking,/*sign*/0); } #else matches = (int *) NULL; *nleftflanks = *nrightflanks = 0; nmatches = 0; #endif } else { /* Treat query as coordinates, with a typestring */ if (exactp == true) { matches = IIT_get_exact_multiple(&(*nmatches),*iit,*divstring,*coordstart,*coordend,typeint); } else { matches = IIT_get_typed(&(*nmatches),*iit,*divstring,*coordstart,*coordend,typeint,sortp); } if (nflanking > 0) { debug(printf("Running IIT_get_flanking_typed\n")); IIT_get_flanking_typed(&(*leftflanks),&(*nleftflanks),&(*rightflanks),&(*nrightflanks),*iit,*divstring, *coordstart,*coordend,nflanking,typeint,/*sign*/0); } } } return matches; }
bool Parserange_query (char **divstring, unsigned int *coordstart, unsigned int *coordend, bool *revcomp, char *query, char *filename) { char *coords; unsigned int result, left, length; int div_strlen; IIT_T iit; *divstring = NULL; *revcomp = false; if ((coords = find_div(&div_strlen,query,':')) != NULL) { /* Query may have a div */ *divstring = (char *) CALLOC(div_strlen+1,sizeof(char)); strncpy(*divstring,query,div_strlen); debug(printf("Parsed query %s into divstring %s and coords %s\n", query,*divstring,coords)); if (IIT_read_divint(filename,*divstring,/*add_iit_p*/true) < 0) { fprintf(stderr,"Chromosome %s not found in IIT file\n",*divstring); debug(printf(" but divstring not found, so treat as label\n")); FREE(*divstring); /* free only when returning false */ return false; } else if (coords == NULL || *coords == '\0') { debug(printf(" entire div\n")); if ((iit = IIT_read(filename,/*name*/NULL,/*readonlyp*/true,/*divread*/READ_ONE,*divstring, /*add_iit_p*/true,/*labels_read_p*/false)) == NULL) { if (Access_file_exists_p(filename) == false) { fprintf(stderr,"Cannot read file %s\n",filename); } else { fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename); } exit(9); } else { *coordstart= 0; *coordend = IIT_divlength(iit,*divstring); debug(printf(" divlength is %u\n",*coordend)); IIT_free(&iit); } return true; } else if (isnumberp(&result,coords)) { debug(printf(" and coords %s as a number\n",coords)); *coordstart = result; *coordend = result; return true; } else if (isrange(&left,&length,&(*revcomp),coords)) { debug(printf(" and coords %s as a range starting at %u with length %u and revcomp = %d\n", coords,left,length,*revcomp)); *coordstart = left + 1; /* Because isrange is 0-based */ *coordend = left + length; return true; } else { debug(printf(" but coords %s is neither a number nor a range. Interpret as a label.\n",coords)); FREE(*divstring); /* free only when returning false */ return false; } } else { /* No div. Query must be a number, range, or label */ debug(printf("Parsed query %s without a div ",query)); if (isnumberp(&result,query)) { debug(printf("number\n")); *coordstart = result; *coordend = result; return true; } else if (isrange(&left,&length,&(*revcomp),query)) { debug(printf("range\n")); *coordstart = left + 1; /* Because isrange is 0-based */ *coordend = left + length; return true; } else { debug(printf("label\n")); return false; } } }