bool GenotypeSet :: AddGenotypesToTables (const RGString& xmlString, const RGString& collectionTag, const RGString& offLadderTag, const RGString& triallelesTag, const RGString& posTriTag) { RGString XMLString (xmlString); RGXMLTagSearch collectionSearch (collectionTag, XMLString); size_t startOffset = 0; size_t endOffset; RGString collectionString; bool returnValue = true; size_t nameStart = 0; size_t nameEnd; RGString name; GenotypesForAMarkerSet* newCollection; GenotypesForAMarkerSet* foundCollection; RGXMLTagSearch nameSearch ("MarkerSetName", collectionString); while (collectionSearch.FindNextTag (startOffset, endOffset, collectionString)) { nameSearch.ResetSearch (); startOffset = endOffset; if (!nameSearch.FindNextTag (nameStart, nameEnd, name)) { returnValue = false; continue; } foundCollection = FindMarkerSetCollection (name); if (foundCollection == NULL) { newCollection = new GenotypesForAMarkerSet (collectionString, offLadderTag, triallelesTag, posTriTag); if (!newCollection->isValid ()) { returnValue = false; delete newCollection; } else mGenotypes.Append (newCollection); } else { if (!foundCollection->AddCollection (collectionString, offLadderTag, triallelesTag, posTriTag)) returnValue = false; } } return returnValue; }
bool GenotypesForAMarkerSet :: AddCollectionToTables (const RGString& xmlString, const RGString& offLadderTag, const RGString& triallelesTag, const RGString& posTriTag) { RGString XMLString (xmlString); RGString positiveControlString; RGString pControlsString; RGString fullPathControlFileName = GenotypesForAMarkerSet::PathToStandardControlFile + "/LadderSpecifications/StandardPositiveControls.xml"; RGFile* allPositiveControls = new RGFile (fullPathControlFileName, "rt"); if (!allPositiveControls->isValid ()) { cout << "Could not find positive controls file: " << (char*)fullPathControlFileName.GetData () << endl; return false; } RGString posXMLString; posXMLString.ReadTextFile (*allPositiveControls); delete allPositiveControls; RGXMLTagSearch nameSearch ("MarkerSetName", XMLString); RGXMLTagSearch positiveControlsSearch ("PositiveControls", posXMLString); RGXMLTagSearch oldPositiveControlsSearch ("PositiveControls", XMLString); RGXMLTagSearch posCtrlSearch ("PositiveControl", pControlsString); RGXMLTagSearch offLadderSearch (offLadderTag, XMLString); RGXMLTagSearch trialleleSearch (triallelesTag, XMLString); RGXMLTagSearch posTriSearch (posTriTag, XMLString); size_t startOffset = 0; size_t endOffset = 0; RGString collectionString; RGString offLadderString; RGString triString; RGString posTriString; size_t startPControls = 0; size_t endPControls = 0; bool returnValue = true; RGString markerSetName; IndividualGenotype* nextGenotype; if (!nameSearch.FindNextTag (startOffset, endOffset, markerSetName)) return false; if (mMarkerSetName.Length () == 0) mMarkerSetName = markerSetName; else if (mMarkerSetName != markerSetName) return false; startOffset = endOffset; size_t startOffsetPos = 0; size_t endOffsetPos = 0; RGString temp; if (oldPositiveControlsSearch.FindNextTag (startOffset, endOffset, temp)) startOffset = endOffset; if (positiveControlsSearch.FindNextTag (startOffsetPos, endOffsetPos, pControlsString)) { posCtrlSearch.ResetSearch (); // cout << "Found positive controls in file" << endl; while (posCtrlSearch.FindNextTag (startPControls, endPControls, positiveControlString)) { // cout << "Found positive control..." << endl; startPControls = endPControls; nextGenotype = new IndividualGenotype (positiveControlString); if (!nextGenotype->isValid ()) { returnValue = false; delete nextGenotype; } else { if (!mGenotypes.Contains (nextGenotype)) { mGenotypes.Insert (nextGenotype); // cout << "Inserted genotype in list..." << endl; } else { returnValue = false; delete nextGenotype; } } } } startOffset = endOffset; if (offLadderSearch.FindNextTag (startOffset, endOffset, offLadderString)) { if (mOffLadderAlleles == NULL) { mOffLadderAlleles = new LocusCollection (offLadderString); if (!mOffLadderAlleles->isValid ()) returnValue = false; } else { if (!mOffLadderAlleles->AddLoci (offLadderString)) returnValue = false; } } startOffset = endOffset; if (trialleleSearch.FindNextTag (startOffset, endOffset, triString)) { if (mSampleTriAlleles == NULL) { mSampleTriAlleles = new LocusCollection (triString); if (!mSampleTriAlleles->isValid ()) returnValue = false; } else { if (!mSampleTriAlleles->AddLoci (triString)) returnValue = false; } } startOffset = endOffset; if (posTriSearch.FindNextTag (startOffset, endOffset, posTriString)) { if (mControlTriAlleles == NULL) { mControlTriAlleles = new LocusCollection (posTriString); if (!mControlTriAlleles->isValid ()) returnValue = false; } else { if (!mControlTriAlleles->AddLoci (posTriString)) returnValue = false; } } return returnValue; }
bool GenotypesForAMarkerSet :: AddCollectionToTablesFromLabSettings (const RGString& xmlString, const RGString& offLadderTag, const RGString& triallelesTag, const RGString& posTriTag) { RGString XMLString (xmlString); RGString positiveControlString; RGString pControlsString; RGXMLTagSearch nameSearch ("MarkerSetName", XMLString); RGXMLTagSearch positiveControlsSearch ("PositiveControls", XMLString); RGXMLTagSearch posCtrlSearch ("PositiveControl", pControlsString); RGXMLTagSearch offLadderSearch (offLadderTag, XMLString); RGXMLTagSearch trialleleSearch (triallelesTag, XMLString); RGXMLTagSearch posTriSearch (posTriTag, XMLString); size_t startOffset = 0; size_t endOffset = 0; RGString collectionString; RGString offLadderString; RGString triString; RGString posTriString; size_t startPControls = 0; size_t endPControls = 0; bool returnValue = true; RGString markerSetName; IndividualGenotype* nextGenotype; if (!nameSearch.FindNextTag (startOffset, endOffset, markerSetName)) return false; if (mMarkerSetName.Length () == 0) mMarkerSetName = markerSetName; else if (mMarkerSetName != markerSetName) return false; startOffset = endOffset; if (positiveControlsSearch.FindNextTag (startOffset, endOffset, pControlsString)) { posCtrlSearch.ResetSearch (); startOffset = endOffset; cout << "Found positive controls in lab settings file" << endl; while (posCtrlSearch.FindNextTag (startPControls, endPControls, positiveControlString)) { cout << "Found positive control..." << endl; startPControls = endPControls; nextGenotype = new IndividualGenotype (positiveControlString); if (!nextGenotype->isValid ()) { returnValue = false; delete nextGenotype; } else { if (!mGenotypes.Contains (nextGenotype)) { mGenotypes.Insert (nextGenotype); cout << "Inserted genotype in list..." << endl; } else { //returnValue = false; cout << "\nWARNING***Found duplicate positive control named " << nextGenotype->GetName ().GetData () << ". Ignoring...\n" << endl; delete nextGenotype; } } } } startOffset = endOffset; if (offLadderSearch.FindNextTag (startOffset, endOffset, offLadderString)) { if (mOffLadderAlleles == NULL) { mOffLadderAlleles = new LocusCollection (offLadderString); if (!mOffLadderAlleles->isValid ()) returnValue = false; } else { if (!mOffLadderAlleles->AddLoci (offLadderString)) returnValue = false; } } startOffset = endOffset; if (trialleleSearch.FindNextTag (startOffset, endOffset, triString)) { if (mSampleTriAlleles == NULL) { mSampleTriAlleles = new LocusCollection (triString); if (!mSampleTriAlleles->isValid ()) returnValue = false; } else { if (!mSampleTriAlleles->AddLoci (triString)) returnValue = false; } } startOffset = endOffset; if (posTriSearch.FindNextTag (startOffset, endOffset, posTriString)) { if (mControlTriAlleles == NULL) { mControlTriAlleles = new LocusCollection (posTriString); if (!mControlTriAlleles->isValid ()) returnValue = false; } else { if (!mControlTriAlleles->AddLoci (posTriString)) returnValue = false; } } return returnValue; }
int Ladder :: AmendLadderData (LadderInputFile* inFile, RGString& oldLadderString) { RGString newLadderString; // Parse oldLadder data into pieces for individual edits RGString locusString; RGString* newLocusString; RGDList locusStrings; size_t startPos = 0; size_t endPos; RGXMLTagSearch locusSearch ("Locus", oldLadderString); RGXMLTagSearch searchRegionsSearch ("SearchRegions", oldLadderString); RGString* ilsName = (RGString*)inFile->GetILSNameList ().First (); endPos = 0; oldLadderString.FindNextSubstring (0, "\t\t\t<Locus>", endPos); RGString insertBase; insertBase << "\t\t\t\t\t<ILSName>" << ilsName->GetData () << "</ILSName>\n"; insertBase << "\t\t\t\t</LSBases>"; RGString leadString = oldLadderString.ExtractSubstring (0, endPos - 1); //cout << "Lead string = \n" << leadString.GetData () << endl; endPos = 0; leadString.FindAndReplaceNextSubstring ("\t\t\t\t</LSBases>", insertBase, endPos); //cout << "Lead string = \n" << leadString.GetData () << endl; newLadderString << leadString; startPos = 0; while (locusSearch.FindNextTag (startPos, endPos, locusString)) { newLocusString = new RGString (locusString); locusStrings.Append (newLocusString); startPos = endPos; } if (mLocusList.size () != locusStrings.Entries ()) { cout << "Number of loci in bins file does not match number of loci in ladder file" << endl; return -152; } Locus* nextLocus; RGString locusInsert; RGString currentLocusString; RGString nameString; RGXMLTagSearch locusNameSearch ("Name", currentLocusString); RGXMLTagSearch coreRepeatSearch ("CoreRepeatNumber", currentLocusString); double minSearch; double maxSearch; RGString repeatString; int repeatNumber; while (locusStrings.Entries () > 0) { newLocusString = (RGString*) locusStrings.GetFirst (); currentLocusString = *newLocusString; locusNameSearch.ResetSearch (); coreRepeatSearch.ResetSearch (); locusNameSearch.FindNextTag (0, endPos, nameString); nextLocus = FindLocusByName (nameString); if (nextLocus == NULL) { cout << "Could not find locus named " << nameString.GetData () << ". Exiting..." << endl; return -155; } if (!coreRepeatSearch.FindNextTag (0, endPos, repeatString)) repeatNumber = 4; else repeatNumber = repeatString.ConvertToInteger (); locusInsert = ""; minSearch = nextLocus->GetMinSearchILSBP () - repeatNumber + 1; maxSearch = nextLocus->GetMaxSearchILSBP () + repeatNumber -1; locusInsert << "\t\t\t\t\t<Region>\n"; locusInsert << "\t\t\t\t\t\t<ILSName>" << ilsName->GetData () << "</ILSName>\n"; locusInsert << "\t\t\t\t\t\t<MinGrid>" << 0.01 * floor (100.0 * minSearch + 0.5) << "</MinGrid>\n"; locusInsert << "\t\t\t\t\t\t<MaxGrid>" << 0.01 * floor (100.0 * maxSearch + 0.5) << "</MaxGrid>\n"; locusInsert << "\t\t\t\t\t</Region>\n"; locusInsert << "\t\t\t\t</SearchRegions>"; endPos = 0; currentLocusString.FindAndReplaceNextSubstring ("\t\t\t\t</SearchRegions>", locusInsert, endPos); newLadderString << "\t\t\t<Locus>" << currentLocusString << "</Locus>\n"; delete newLocusString; } newLadderString << "\t\t</Set>\n"; newLadderString << "\t</Kits>\n"; newLadderString << "</KitData>\n"; RGString ladderPath = inFile->GetOutputConfigDirectoryPath () + "/" + inFile->GetLadderFileName (); RGTextOutput ladderOutput (ladderPath, FALSE); if (!ladderOutput.FileIsValid ()) { cout << "Could not open ladder output file: " << ladderPath.GetData () << endl; return -161; } ladderOutput << newLadderString; cout << "Ladder update completed successfully..." << endl; return 0; }