/* * symmetric patMatch that checks if text is shorter than pattern * used for artist checking in addNewTitle */ static int checkSim( const char *text, const char *pat ) { if( strlen( text ) < strlen( pat ) ) { return patMatch( pat, text ); } else { return patMatch( text, pat ); } }
/* * checks if a title entry 'title' matches the search term 'pat' * the test is driven by the first two characters in the * search term. The first character gives the range (taLgd(p)) * the second character notes if the search should be * exact or fuzzy (=*) */ static int matchTitle( mptitle *title, const char* pat ) { int fuzzy=0; char loname[1024]; char *lopat; int res=0; if( ( '=' == pat[1] ) || ( '*' == pat[1] ) ) { if( '*' == pat[1] ) { fuzzy=1; } switch( pat[0] ) { case 't': strltcpy( loname, title->title, 1024 ); break; case 'a': strltcpy( loname, title->artist, 1024 ); break; case 'l': strltcpy( loname, title->album, 1024 ); break; case 'g': strltcpy( loname, title->genre, 1024 ); break; case 'd': strltcpy( loname, title->display, 1024 ); break; case 'p': /* @obsolete! */ strltcpy( loname, title->path, 1024 ); break; default: addMessage( 0, "Unknown range %c in %s!", pat[0], pat ); addMessage( 0, "Using display instead" ); strltcpy( loname, title->display, 1024 ); break; } } else { strltcpy( loname, title->display, 1024 ); } if( fuzzy ) { res=patMatch( loname, pat+2 ); } else { lopat=(char*)falloc( strlen( pat+1 ), 1 ); strltcpy( lopat, pat+2, strlen( pat+1 ) ); res=( strstr( loname, lopat ) != NULL ); free( lopat ); } return res; }
/* * matches term with pattern in search */ static int isMatch( const char *term, const char *pat, const int fuzzy ) { char loterm[MAXPATHLEN]; if( fuzzy ){ return patMatch( term, pat); } else { strltcpy( loterm, term, MAXPATHLEN ); return ( strstr( loterm, pat ) != NULL ); } }
int main() { char text[] = "ABABDABACDABABCABABABABCABAB"; char patt[] = "ABABCABAZ"; int tLen = strlen(text); int pLen = strlen(patt); patMatch(text, patt, tLen, pLen); return 0; }
struct nameOff *scanIntronFile(char *preIntronQ, char *startIntronQ, char *endIntronQ, char *postIntronQ, boolean invert) { char intronFileName[600]; FILE *f; char lineBuf[4*1024]; char *words[4*128]; int wordCount; int lineCount = 0; int preLenQ = strlen(preIntronQ); int startLenQ = strlen(startIntronQ); int endLenQ = strlen(endIntronQ); int postLenQ = strlen(postIntronQ); char *preIntronF, *startIntronF, *endIntronF, *postIntronF; int preLenF, startLenF, endLenF, postLenF; int preIx = 6, startIx = 7, endIx =8, postIx = 9; struct nameOff *list = NULL, *el; boolean addIt; int i; if (preLenQ > 25 || postLenQ > 25 || startLenQ > 40 || endLenQ > 40) { errAbort("Can only handle queries up to 25 bases on either side of the intron " "and 40 bases inside the intron."); } sprintf(intronFileName, "%s%s", wormCdnaDir(), "introns.txt"); f = mustOpen(intronFileName, "r"); while (fgets(lineBuf, sizeof(lineBuf), f) != NULL) { ++lineCount; wordCount = chopByWhite(lineBuf, words, ArraySize(words)); if (wordCount == ArraySize(words)) { warn("May have truncated end of line %d of %s", lineCount, intronFileName); } if (wordCount == 0) continue; if (wordCount < 11) errAbort("Unexpected short line %d of %s", lineCount, intronFileName); preIntronF = words[preIx]; startIntronF = words[startIx]; endIntronF = words[endIx]; postIntronF = words[postIx]; preLenF = strlen(preIntronF); startLenF = strlen(startIntronF); endLenF = strlen(endIntronF); postLenF = strlen(postIntronF); addIt = FALSE; if ( ( preLenQ == 0 || patMatch(preIntronQ, preIntronF+preLenF-preLenQ+countSpecial(preIntronQ), preLenQ)) && (startLenQ == 0 || patMatch(startIntronQ, startIntronF, startLenQ)) && ( endLenQ == 0 || patMatch(endIntronQ, endIntronF+endLenF-endLenQ+countSpecial(endIntronQ), endLenQ)) && ( postLenQ == 0 || patMatch(postIntronQ, postIntronF, postLenQ)) ) { addIt = TRUE; } if (invert) addIt = !addIt; if (addIt) { addIntronToHistogram(preIntronF+preLenF, startIntronF, endIntronF+endLenF, postIntronF); AllocVar(el); el->chrom = cloneString(words[1]); el->name = cloneString(words[5]); el->start = atoi(words[2]); el->end = atoi(words[3]); el->cdnaCount = atoi(words[0]); memcpy(el->startI, startIntronF, 2); memcpy(el->endI, endIntronF + endLenF - 2, 2); assert(wordCount == el->cdnaCount + 10); for (i=10; i<wordCount; ++i) { struct slName *name = newSlName(words[i]); slAddHead(&el->cdnaNames, name); } slReverse(&el->cdnaNames); assert(slCount(el->cdnaNames) == el->cdnaCount); slAddHead(&list, el); } } fclose(f); slSort(&list, cmpCounts); return list; }