// parse and combine JuggleMaster and JuggleSaver patterns int ParseAllPatterns(FILE *jm_input, FILE* js_input, struct groups_t *groups, struct styles_t *styles) { int jm = ParsePatterns(jm_input, groups, styles); if (!jm) return 0; #ifdef JUGGLESAVER_SUPPORT if (!js_input) return 1; struct pattern_group_t* last = groups->first; while (last->next != NULL) last = last->next; struct groups_t *js_groups = new groups_t; js_groups->first = NULL; int js = ParseJSPatterns(js_input, js_groups); if (!js) { delete js_groups; return 0; } last->next = js_groups->first; delete js_groups; #endif return 1; }
int main(int argc, char *argv[]) { FILE *f; struct groups_t g; struct styles_t s; struct pattern_group_t *groups; struct style_t *styles; struct pattern_t *patterns; int quiet = 0; int current_arg; s.first = NULL; g.first = NULL; if(argc < 2) { printf("Format: %s [-q[uiet]] <filename1> [filename2 ...]\n", argv[0]); return 1; } if(strncmp(argv[1],"-q",2) == 0) { quiet = 1; current_arg = 2; } else { current_arg = 1; } for(;current_arg<argc;current_arg++) { if((f = fopen(argv[current_arg],"r")) == NULL) { perror("Couldn't open file"); return 1; } ParsePatterns(f,&g,&s); fclose(f); if(!quiet) { printf("File: %s\n", argv[current_arg]); groups = FirstGroup(&g); printf("Group Data\n"); while(groups) { printf(" Group Name: %s\n",Group_GetName(groups)); patterns = Group_GetPatterns(groups); while(patterns) { printf(" Pattern Name: %s\n",Patt_GetName(patterns)); printf(" Style: %s\n",Patt_GetStyle(patterns)); printf(" Data: %s\n",Patt_GetData(patterns)); printf(" Height ratio: %1.2f\n",Patt_GetHR(patterns)); printf(" Dwell Ratio: %1.2f\n",Patt_GetDR(patterns)); printf(" Author: %s\n",Patt_GetAuthor(patterns)); patterns = NextPatt(patterns); } groups = NextGroup(groups); printf("\n"); }; printf("\n\n"); printf("Style Data\n"); styles = FirstStyle(&s); while(styles) { int i; printf(" Style Name: %s\n",Style_GetName(styles)); printf(" Length: %i\n",Style_GetLength(styles)); printf(" Data:\n"); for(i=0;i<(int)Style_GetLength(styles);i++) { if((i%4) == 0) { printf(" {"); } else if ((i%4) == 2) { printf("}{"); } printf(" %i",Style_GetData(styles)[i]); if ((i%4) == 0 || (i%4) == 2) { printf(", "); } else if ((i%4) == 3) { printf("}\n"); } } styles = NextStyle(styles); printf("\n"); } printf("\n\n"); } FreeGroups(&g); FreeStyles(&s); } return 0; }
/* load a description from a file */ PMSDESCRIPTION LoadSiteDescription(const char *Filename) { int error; /* non-zero if error occurred */ int foundPattern; /* non-zero if pattern found */ int foundScoring; /* non-zero if scoring parameters found*/ int foundQuality; /* non-zero if quality filter found */ PMSDESCRIPTION pDescription; /* site description to be loaded */ xmlDocPtr pXMLDocument; /* the XML document in the file */ xmlNode *pNode; /* current node in XML document */ /* parse XML file */ xmlInitParser(); pXMLDocument=xmlParseFile(Filename); if (!pXMLDocument) { fprintf(stderr,"Could not parse site description file!\n"); return(NULL); } /* get memory for site description */ pDescription=(PMSDESCRIPTION)malloc(sizeof(MSDESCRIPTION)); if (!pDescription) { fprintf(stderr,"Could not allocate memory for site description!\n"); xmlFreeDoc(pXMLDocument); xmlCleanupParser(); return(NULL); } pDescription->Length=0; pDescription->Sequence=NULL; pDescription->RepeatBasePosition=-1; pDescription->Minimal5Flank=5; pDescription->Minimal3Flank=5; pDescription->MaximalMismatch=10; pDescription->MaxMismatch5Req=1; pDescription->MaxMismatch3Req=1; pDescription->CutoffForNs=20; pDescription->MaximumNs=30; error=0; do { /* region of controlled exit */ for(pNode=xmlDocGetRootElement(pXMLDocument);pNode;pNode=pNode->next) if (pNode->type==XML_ELEMENT_NODE && !strcmp((const char*)pNode->name,"SiteDescription")) break; if (!pNode) { fprintf(stderr,"Could not find <SiteDescription> in description file!\n"); error=1; break; } foundPattern=0; foundScoring=0; foundQuality=0; for(pNode=pNode->children;pNode;pNode=pNode->next) { if (pNode->type != XML_ELEMENT_NODE) continue; if (!strcmp((const char*)pNode->name,"Pattern")) { if (foundPattern) { fprintf(stderr,"Site description contains two patterns!\n"); error=1; break; } foundPattern=1; error=ParsePatterns(pDescription,pNode); } if (!strcmp((const char*)pNode->name,"ScoringRules")) { if (foundScoring) { fprintf(stderr,"Site description contains two scoring parameter " "sets!\n"); error=1; break; } foundScoring=1; error=ParseScoring(pDescription,pNode); } if (!strcmp((const char*)pNode->name,"QualityFilter")) { if (foundQuality) { fprintf(stderr,"Site description contains two quality filter " "parameter sets!\n"); error=1; break; } foundQuality=1; error=ParseQuality(pDescription,pNode); } if (error) break; } if (!foundPattern) { fprintf(stderr,"Site description does not contain a pattern!\n"); error=1; break; } if (pDescription->RepeatBasePosition<pDescription->Minimal5Flank) { fprintf(stderr,"5' flank is shorter than requested minimal 5' flank " "length!\n"); error=1; break; } if (pDescription->Length-pDescription->RepeatBasePosition-1 <pDescription->Minimal3Flank) { fprintf(stderr,"3' flank is shorter than requested minimal 3' flank " "length!\n"); error=1; break; } } while(0); /* end of region of controlled exit */ xmlFreeDoc(pXMLDocument); xmlCleanupParser(); if (error) DestroySiteDescription(&pDescription); return(pDescription); }