Int2 Main (void) { Int2 argcount; Boolean flagHaveNet; Int4 gi; SeqEntryPtr sep; ComPatPtr cpp, cpph = NULL; SeqAlignPtr sap, sapn; StdSegPtr ssp; SeqLocPtr slp, slpn; Int4 start, stop; FILE *fiop; Char fastafile[256], namesfile[256]; CharPtr title; CharPtr taxon; FloatHi mw; ValNodePtr namelist = NULL; static CharPtr pattern_file = "ncbipros.dat"; static CharPtr protease_file = "ncbiendo.dat"; static CharPtr names_file = "ncbipnam.dat"; static GatherScope gs; GatherScopePtr gsp; static Gather_PBS gpbs; Gather_PBSPtr gpbsp; #ifndef NO_TAX_NET Int4 i; static Char taxdata[8]; static Gather_TaxId gti; Gather_TaxIdPtr gtip; #endif #ifndef NO_TAX_NET Int2 ia=4, ib=5, ic=6, id=7, ie=8, ig=9, ih=10, ii=11; #else Int2 ib=4, ic=5, id=6, ie=7, ig=8, ih=9, ii=10; #endif argcount = sizeof (myargs) / sizeof (Args); if (!GetArgs ("ProSiteSearch", argcount, myargs)) return 1; if (myargs[0].intvalue == 0 && myargs[1].strvalue == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 100, "No gi or FastA file given :: for help : srchaa -"); ErrShow (); exit (1); } gsp = &gs; #ifndef NO_TAX_NET gtip = >i; #endif gpbsp = &gpbs; MemSet ((Pointer) gsp, 0, sizeof (GatherScope)); MemSet ((Pointer) gsp->ignore, (int) (TRUE), (size_t) (OBJ_MAX * sizeof (Boolean))); gsp->ignore[OBJ_SEQDESC] = TRUE; gsp->ignore[OBJ_BIOSEQ] = FALSE; gpbsp->bsp = NULL; gi = myargs[0].intvalue; if (myargs[1].strvalue != NULL) StrCpy (fastafile, myargs[1].strvalue); else fastafile[0] = '\0'; if (gi > 0) { if (!EntrezInit ("srchaa", FALSE, &flagHaveNet)) { ErrPostEx (SEV_ERROR, TOP_ERROR, 102, "Entrez init failed"); ErrShow (); exit (1); } } #ifndef NO_TAX_NET if (myargs[ia].intvalue) { if (!TaxArchInit ()) { ErrPostEx (SEV_ERROR, TOP_ERROR, 103, "Taxonomy init failed"); ErrShow (); exit (1); } } #endif fiop = NULL; if (gi > 0) { sep = EntrezSeqEntryGet (gi, SEQENTRY_READ_BIOSEQ); } else { if ((fiop = FileOpen (fastafile, "r")) == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 103, "Failed to open FastA file: %s", fastafile); ErrShow (); exit (1); } sep = FastaToSeqEntry (fiop, FALSE); } if (sep == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 104, "No seqentry found"); ErrShow (); exit (1); } while (sep != NULL) { gsp->ignore[OBJ_SEQDESC] = TRUE; gsp->ignore[OBJ_BIOSEQ] = FALSE; gpbsp->bsp = NULL; gpbsp->gi = gi; GatherSeqEntry (sep, (Pointer) gpbsp, GetBioseq, (Pointer) gsp); taxon = NULL; #ifndef NO_TAX_NET if (myargs[ia].intvalue) { for (i = 0; i < 8; i++) taxdata[i] = '-'; taxon = taxdata; gsp->ignore[OBJ_SEQDESC] = FALSE; gsp->ignore[OBJ_BIOSEQ] = TRUE; gtip->taxid = 0; GatherSeqEntry (sep, (Pointer) gtip, GetTaxId, (Pointer) gsp); if (gtip->taxid != 0) WhatOrg (gtip->taxid, taxon); else taxon = NULL; } #endif if (gpbsp->bsp != NULL) { if (ISA_aa (gpbsp->bsp->mol)) { if (cpph == NULL) { namesfile[0] = '\0'; if (myargs[id].intvalue) StrCpy (namesfile, names_file); if (myargs[ie].strvalue != NULL) StrCpy (namesfile, myargs[ie].strvalue); if (myargs[ig].strvalue != NULL) { if ((cpph = CompilePattern (myargs[ig].strvalue, 1)) != NULL) StrCpy (cpph->name, "User Pattern"); } else { namelist = ReadPatternNames (namesfile); if (myargs[ib].intvalue) cpph = ReadPrositePattern (protease_file, (Boolean) myargs[2].intvalue, myargs[3].intvalue, taxon, NULL); else cpph = ReadPrositePattern (pattern_file, (Boolean) myargs[2].intvalue, myargs[3].intvalue, taxon, namelist); } } if (!(Boolean) myargs[ih].intvalue) { title = FastaTitle (gpbsp->bsp, ">", NULL); printf ("%s\n", title); MemFree (title); } cpp = cpph; while (cpp != NULL) { sap = PatternMatchBioseq (gpbsp->bsp, cpp, (Int4)myargs[ii].intvalue); if (myargs[ib].intvalue) { printf (">%s\n", cpp->name); if (sap != NULL) printf (" Start Stop M.W.\n"); } if (myargs[ib].intvalue) { EmbedMolecularWeightInfo (sap, gpbsp->bsp); if (myargs[ic].intvalue) URK_SeqAlignSortByMolWt (&sap); while (sap != NULL) { ssp = (StdSegPtr) sap->segs; slp = ssp->loc; start = SeqLocStart (slp); stop = SeqLocStop (slp); mw = ssp->scores->value.realvalue; printf ("%8ld %8ld %9.2f\n", (long) start+1, (long) stop+1, mw); sapn = sap->next; SeqAlignFree (sap); sap = sapn; } } else { slp = MatchSa2Sl (&sap); if (myargs[ih].intvalue && slp != NULL) { title = FastaTitle (gpbsp->bsp, ">", NULL); printf ("%s\n", title); MemFree (title); } while (slp != NULL) { start = SeqLocStart (slp); stop = SeqLocStop (slp); printf ("%8ld %8ld %s\n", (long) start+1, (long) stop+1, cpp->name); slpn = slp->next; SeqLocFree (slp); slp = slpn; } } cpp = cpp->nextpattern; } } else { ErrPostEx (SEV_ERROR, TOP_ERROR, 106, "Not a protein bioseq"); ErrShow (); exit (1); } } else { ErrPostEx (SEV_ERROR, TOP_ERROR, 105, "No bioseq found"); ErrShow (); exit (1); } SeqEntryFree (sep); sep = NULL; if (fiop != NULL) sep = FastaToSeqEntry (fiop, FALSE); } ComPatFree (cpph); ValNodeFreeData (namelist); FileClose (fiop); if (gi > 0) EntrezFini (); #ifndef NO_TAX_NET if (myargs[ia].intvalue) TaxArchFini (); #endif return 0; }
CmdResult Handle (const std::vector<std::string>& parameters, User *user) { if (!parameters.size()) { // no parameters, show the current silence list. silencelist* sl = ext.get(user); // if the user has a silence list associated with their user record, show it if (sl) { for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++) { std::string decomppattern = DecompPattern(c->second); user->WriteNumeric(271, "%s %s %s %s",user->nick.c_str(), user->nick.c_str(),c->first.c_str(), decomppattern.c_str()); } } user->WriteNumeric(272, "%s :End of Silence List",user->nick.c_str()); return CMD_SUCCESS; } else if (parameters.size() > 0) { // one or more parameters, add or delete entry from the list (only the first parameter is used) std::string mask = parameters[0].substr(1); char action = parameters[0][0]; // Default is private and notice so clients do not break int pattern = CompilePattern("pn"); // if pattern supplied, use it if (parameters.size() > 1) { pattern = CompilePattern(parameters[1].c_str()); } if (pattern == 0) { user->WriteServ("NOTICE %s :Bad SILENCE pattern",user->nick.c_str()); return CMD_INVALID; } if (!mask.length()) { // 'SILENCE +' or 'SILENCE -', assume *!*@* mask = "*!*@*"; } ModeParser::CleanMask(mask); if (action == '-') { std::string decomppattern = DecompPattern(pattern); // fetch their silence list silencelist* sl = ext.get(user); // does it contain any entries and does it exist? if (sl) { for (silencelist::iterator i = sl->begin(); i != sl->end(); i++) { // search through for the item irc::string listitem = i->first.c_str(); if (listitem == mask && i->second == pattern) { sl->erase(i); user->WriteNumeric(950, "%s %s :Removed %s %s from silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), decomppattern.c_str()); if (!sl->size()) { ext.unset(user); } return CMD_SUCCESS; } } } user->WriteNumeric(952, "%s %s :%s %s does not exist on your silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), decomppattern.c_str()); } else if (action == '+') { // fetch the user's current silence list silencelist* sl = ext.get(user); if (!sl) { sl = new silencelist; ext.set(user, sl); } if (sl->size() > maxsilence) { user->WriteNumeric(952, "%s %s :Your silence list is full",user->nick.c_str(), user->nick.c_str()); return CMD_FAILURE; } std::string decomppattern = DecompPattern(pattern); for (silencelist::iterator n = sl->begin(); n != sl->end(); n++) { irc::string listitem = n->first.c_str(); if (listitem == mask && n->second == pattern) { user->WriteNumeric(952, "%s %s :%s %s is already on your silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), decomppattern.c_str()); return CMD_FAILURE; } } if (((pattern & SILENCE_EXCLUDE) > 0)) { sl->push_front(silenceset(mask,pattern)); } else { sl->push_back(silenceset(mask,pattern)); } user->WriteNumeric(951, "%s %s :Added %s %s to silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), decomppattern.c_str()); return CMD_SUCCESS; } } return CMD_SUCCESS; }
CmdResult Handle (const std::vector<std::string>& parameters, User *user) { if (!parameters.size()) { // no parameters, show the current silence list. // Use Extensible::GetExt to fetch the silence list silencelist* sl; user->GetExt("silence_list", sl); // if the user has a silence list associated with their user record, show it if (sl) { for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++) { user->WriteNumeric(271, "%s %s %s %s",user->nick.c_str(), user->nick.c_str(),c->first.c_str(), DecompPattern(c->second).c_str()); } } user->WriteNumeric(272, "%s :End of Silence List",user->nick.c_str()); return CMD_LOCALONLY; } else if (parameters.size() > 0) { // one or more parameters, add or delete entry from the list (only the first parameter is used) std::string mask = parameters[0].substr(1); char action = parameters[0][0]; // Default is private and notice so clients do not break int pattern = CompilePattern("pn"); // if pattern supplied, use it if (parameters.size() > 1) { pattern = CompilePattern(parameters[1].c_str()); } if (!mask.length()) { // 'SILENCE +' or 'SILENCE -', assume *!*@* mask = "*!*@*"; } ModeParser::CleanMask(mask); if (action == '-') { // fetch their silence list silencelist* sl; user->GetExt("silence_list", sl); // does it contain any entries and does it exist? if (sl) { for (silencelist::iterator i = sl->begin(); i != sl->end(); i++) { // search through for the item irc::string listitem = i->first.c_str(); if (listitem == mask && i->second == pattern) { sl->erase(i); user->WriteNumeric(950, "%s %s :Removed %s %s from silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), DecompPattern(pattern).c_str()); if (!sl->size()) { delete sl; user->Shrink("silence_list"); } return CMD_SUCCESS; } } } user->WriteNumeric(952, "%s %s :%s %s does not exist on your silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), DecompPattern(pattern).c_str()); } else if (action == '+') { // fetch the user's current silence list silencelist* sl; user->GetExt("silence_list", sl); // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one. if (!sl) { sl = new silencelist; user->Extend("silence_list", sl); } if (sl->size() > maxsilence) { user->WriteNumeric(952, "%s %s :Your silence list is full",user->nick.c_str(), user->nick.c_str()); return CMD_FAILURE; } for (silencelist::iterator n = sl->begin(); n != sl->end(); n++) { irc::string listitem = n->first.c_str(); if (listitem == mask && n->second == pattern) { user->WriteNumeric(952, "%s %s :%s %s is already on your silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), DecompPattern(pattern).c_str()); return CMD_FAILURE; } } if (((pattern & SILENCE_EXCLUDE) > 0)) { sl->push_front(silenceset(mask,pattern)); } else { sl->push_back(silenceset(mask,pattern)); } user->WriteNumeric(951, "%s %s :Added %s %s to silence list",user->nick.c_str(), user->nick.c_str(), mask.c_str(), DecompPattern(pattern).c_str()); return CMD_SUCCESS; } } return CMD_LOCALONLY; }