void NodeSig(phylo P, sample S, int outmethod, int abundWeighted) { // Currently need to use taxon name of interior as a marker, // because Mesquite will not show all labels, but if it will soon, // best to use notes, and not muck around with taxon name //TODO modifying to use abundances, need longs instead of ints for counters int plot, node, taxon, i, ordHI, ordLO, run; int tipsReal_n[P.nnodes]; float test_r[RUNS]; char mark[2]; char tmp[15]; int **tips_rn; // was: int tips_rn[RUNS][MaxNode+1]; phylo Out[S.nsamples]; int *attach; attach = ivector(0, S.ntaxa-1); tips_rn = imatrix(0, RUNS-1, 0, P.nnodes-1); for (i = 0; i < S.nsamples; i++) { Out[i] = P; // all the pointers in Out are the same as those in Intree // careful not to change any preexisting arrays in Out, or they will // also be changed in Intree! if (TreeView == 0) Out[i].arenotes = 1; if (TreeView == 1) Out[i].arenotes = 0; // dimension a new array for Out names: if (TreeView == 0) Out[i].notes = cmatrix(0, P.nnodes-1, 0, MAXNOTELENGTH+10); if (TreeView == 1) Out[i].taxon = cmatrix(0, P.nnodes-1, 0, MAXTAXONLENGTH+10); } // for each plot if (outmethod == 1) printf("plot\tnode\tnode_name \tntaxa\tmedian\trank\tsig\n"); for (plot = 0; plot < S.nsamples; plot++) { if (S.srec[plot] > 2) { for (node = 0; node < P.nnodes; node++) { tipsReal_n[node] = 0; for (run = 0; run < RUNS; run++) tips_rn[run][node] = 0; } // need to reset it AttachSampleToPhylo(S, P, attach); // follow up from tips, adding 1 to each node passed through for (taxon = 0; taxon < S.srec[plot]; taxon++) { i = P.t2n[ attach[ S.id[plot][taxon] ] ]; while (i != -1) { if (abundWeighted) tipsReal_n[i] += S.abund[plot][taxon]; else tipsReal_n[i]++; i = P.up[i]; } } // ooo this is slow, putting rnd inside the plot loop! for (run = 0; run < RUNS; run++) { // now randomize the plot // RandomizeB(plot); PhylogenyAttachShuffle(P, S, attach); for (taxon = 0; taxon < S.srec[plot]; taxon++) { i = P.t2n[ attach[ S.id[plot][taxon] ] ]; while (i != -1) { if (abundWeighted) tips_rn[run][i] += S.abund[plot][taxon]; else tips_rn[run][i]++; i = P.up[i]; } } } // now unpeel the nodes for (node = 0; node < P.nnodes; node++) { if (TreeView == 0) strcpy(Out[plot].notes[node], ""); if (TreeView == 1) strcpy(Out[plot].taxon[node], ""); // interior nodes only if (P.noat[node] != 0) { ordHI = 0; ordLO = 0; for (run = 0; run < RUNS; run++) { if (tips_rn[run][node] < tipsReal_n[node]) ordHI++; if (tips_rn[run][node] > tipsReal_n[node]) ordLO++; } strcpy(mark, " "); if (ordLO >= (int) ((float) RUNS * 0.975)) { strcpy(mark, "-"); if (TreeView == 0) strcat(Out[plot].notes[node], "SIGLESS"); if (TreeView == 1) { sprintf(tmp, "LESS_%d_", node); strcpy(Out[plot].taxon[node], tmp); } if (outmethod == 1) printf("%d\t%d\t%-10s\t%d\t%d\t%d\t%d\t%s\n", plot +1, node, P.taxon[node], tipsReal_n[node], (int) test_r[(int) ((float) RUNS * 0.5)], ordHI, ordLO, mark); } else if (ordHI >= (int) ((float) RUNS * 0.975)) { strcpy(mark, "+"); if (TreeView == 0) strcat(Out[plot].notes[node], "SIGMORE"); if (TreeView == 1) { sprintf(tmp, "MORE_%d_", node); strcpy(Out[plot].taxon[node], tmp); } if (outmethod == 1) printf("%d\t%d\t%-20s\t%d\t%d\t%d\t%d\t%s\n", plot +1, node, P.taxon[node], tipsReal_n[node], (int) test_r[(int) ((float) RUNS * 0.5)], ordHI, ordLO, mark); } // printf("%s\t%s\n", Out.taxon[node], Intree.taxon[node]); else if (outmethod == 1) printf("%d\t%d\t%-20s\t%d\t%d\t%d\t%d\t%s\n", plot+1, node, P.taxon[node], tipsReal_n[node], (int) test_r[(int) ((float) RUNS * 0.5)], ordHI, ordLO, mark); } if ((TreeView == 1) && (strcmp(P.taxon[node], ".") != 0)) { strcat(Out[plot].taxon[node], P.taxon[node]); } } } // Name tree strcpy(Out[plot].phyname, "NodeSig_"); strcat(Out[plot].phyname, S.pname[plot]); } if (outmethod ==0) WriteNexus(Out, S.nsamples, ReadSample(SampleFile), 1, ReadTraits(TraitFile), 1); }
//----------------------------------------------------------------------------- bool psNPCLoader::LoadFromFile(csString &filename) { area.Clear(); CPrintf(CON_DEBUG, "Importing NPC from file: %s\n",filename.GetData()); // try to read data from the file csRef<iVFS> vfs = csQueryRegistry<iVFS> (psserver->GetObjectReg()); csRef<iDataBuffer> data(vfs->ReadFile(filename.GetData())); if(!data || !data->GetSize()) { CPrintf(CON_ERROR, "Error: Couldn't load file '%s'.\n", filename.GetData()); return false; } csRef<iDocumentSystem> xml; xml.AttachNew(new csTinyDocumentSystem); csRef<iDocument> doc = xml->CreateDocument(); const char* error = doc->Parse(data); if(error) { Error2("Error in XML: %s", error); return false; } npcRoot = doc->GetRoot()->GetNode("npc"); if(!npcRoot) { CPrintf(CON_ERROR, "Error: no <npc> tag found\n"); return false; } dialogManager = new psDialogManager; npc = new psCharacter; npc->SetCharType(PSCHARACTER_TYPE_NPC); // process xml data if(!ReadBasicInfo() || !ReadLocation()) { CPrintf(CON_ERROR, "Error: Failed to load NPC data\n"); return false; } ReadDescription(); ReadTraits(); ReadStats(); ReadMoney(); ReadSkills(); ReadTrainerInfo(); ReadMerchantInfo(); ReadFactions(); ReadKnowledgeAreas(); ReadSpecificKnowledge(); ReadSpecialResponses(); // insert processed data into the database if(!WriteToDatabase()) { CPrintf(CON_ERROR, "Error: Failed to insert data into the database\n"); return false; } return true; }