Boolean RGDirectory :: MoveDirectory (const RGString& oldName, const RGString& suffix, int MaxLevels) { int i = 0; RGString newName = oldName + suffix; while (i < MaxLevels) { if (!FileOrDirectoryExists (newName)) { // FinalName = newName; cout << "Attempting to move " << oldName.GetData () << " to " << newName.GetData () << endl; return MoveFile (oldName.GetData (), newName.GetData ()); } i++; newName += suffix; } return FALSE; }
int CopyVolumeFile (const RGString& inputFileName, const RGString& outputFileName) { RGFile inputFile (inputFileName, "rt"); if (!inputFile.isValid ()) { cout << "Could not read " << inputFileName.GetData () << " for default volume...exiting" << endl; return -1; } RGString inputFileString; inputFileString.ReadTextFile (inputFile); RGTextOutput outputFile (outputFileName, FALSE); if (!outputFile.FileIsValid ()) { cout << "Could not create " << outputFileName.GetData () << "...exiting" << endl; return -1; } outputFile << inputFileString; return 0; }
void Ladder :: OutputTo (RGTextOutput& xmlFile, LadderInputFile& inputFile) { RGString link ("http://www.w3.org/2001/XMLSchema-instance"); xmlFile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; xmlFile << "<KitData xmlns:xsi=\"" << link.GetData () << "\" xsi:noNamespaceSchemaLocation=\"MarkerSet.xsd\">\n"; xmlFile << "\t<Version>" << inputFile.GetVersion () << "</Version>\n"; xmlFile << "\t<Kits>\n"; xmlFile << "\t\t<Set>\n"; xmlFile << "\t\t\t<Name>" << mMarkerSetName.GetData () << "</Name>\n"; xmlFile << "\t\t\t<NChannels>" << mNumberOfChannels << "</NChannels>\n"; xmlFile << "\t\t\t<ILS>\n"; if (inputFile.GenerateILSFamilies ()) { xmlFile << "\t\t\t\t<LSBases>\n"; OutputILSFamilyListTo (xmlFile); xmlFile << "\t\t\t\t</LSBases>\n"; } else { xmlFile << "\t\t\t<LS>\n"; OutputILSListTo (xmlFile); xmlFile << "\t\t\t</LS>\n"; } xmlFile << "\t\t\t\t<ChannelNo>" << mChannelForILS << "</ChannelNo>\n"; xmlFile << "\t\t\t</ILS>\n"; xmlFile << "\t\t\t<FileNameSuffix>" << mSuffix << "</FileNameSuffix>\n"; xmlFile << "\t\t\t<GenotypeSuffix>" << mSuffix << "</GenotypeSuffix>\n"; xmlFile << "\t\t\t<DirectorySearchString>" << mSuffix << "</DirectorySearchString>\n"; OutputChannelMapTo (xmlFile, inputFile); list <Locus*>::const_iterator locusIterator; Locus* nextLocus; for (locusIterator = mLocusList.begin(); locusIterator != mLocusList.end(); locusIterator++) { nextLocus = *locusIterator; nextLocus->OutputTo (xmlFile); } xmlFile << "\t\t</Set>\n"; xmlFile << "\t</Kits>\n"; xmlFile << "</KitData>"; }
RGString LocusData :: FormXMLString () { RGString Result; if (AlleleStringIsEmpty ()) return Result; RGTPtrDList<RGString> temp; RGString sixTabs = "\t\t\t\t\t\t"; RGString sevenTabs = "\t\t\t\t\t\t\t"; RGString eightTabs = "\t\t\t\t\t\t\t\t"; Result << sixTabs << "<Locus>\n"; Result << sevenTabs << "<Name>" << (char*)mLocusName.GetData () << "</Name>\n"; RGString* nextAllele; while (mAlleleList.entries () > 0) { nextAllele = mAlleleList.RemoveFirst (); nextAllele->FindAndReplaceAllSubstrings ("\"", ""); temp.append (nextAllele); Result << sevenTabs << "<Allele>\n"; Result << eightTabs << "<Name>" << (char*)nextAllele->GetData () << "</Name>\n"; Result << eightTabs << "<BioID>0</BioID>\n"; Result << sevenTabs << "</Allele>\n"; } Result << sixTabs << "</Locus>\n"; //cout << (char*) Result.GetData (); while (temp.entries () > 0) { nextAllele = temp.RemoveFirst (); mAlleleList.append (nextAllele); } return Result; }
int SmartNoticeWarehouse :: AddType (SmartNotice* NewType) { RGPersistent* test = ClassTypes->Append (NewType); int val; if (SmartNoticeWarehouse::DebugFlag) { RGString name (NewType->GetName ()); cout << "Adding class to notice list, Name = " << name.GetData () << endl; } if (test != NULL) { val = ClassTypes->Entries (); } else { val = 0; } return val; }
int CoreBioComponent :: InitializeSM (SampleData& fileData, PopulationCollection* collection, const RGString& markerSetName, Boolean isGrid) { // // This is ladder and sample stage 1 // mTime = fileData.GetCollectionStartTime (); mDate = fileData.GetCollectionStartDate (); mName = fileData.GetName (); mRunStart = mDate.GetOARString () + mTime.GetOARString (); mMarkerSet = collection->GetNamedPopulationMarkerSet (markerSetName); Progress = 0; smMarkerSetNameUnknown noNamedMarkerSet; smNamedILSUnknown noNamedILS; smChannelIsILS channelIsILS; if (mMarkerSet == NULL) { ErrorString = "*******COULD NOT FIND MARKER SET NAMED "; ErrorString << markerSetName << " IN POPULATION COLLECTION********\n"; SetMessageValue (noNamedMarkerSet, true); AppendDataForSmartMessage (noNamedMarkerSet, markerSetName); return -1; } mLaneStandard = mMarkerSet->GetLaneStandard (); mNumberOfChannels = mMarkerSet->GetNumberOfChannels (); if ((mLaneStandard == NULL) || !mLaneStandard->IsValid ()) { ErrorString = "Could not find named internal lane standard associated with marker set named "; ErrorString << markerSetName << "\n"; cout << "Could not find named internal lane standard associated with marker set named " << (char*)markerSetName.GetData () << endl; SetMessageValue (noNamedILS, true); AppendDataForSmartMessage (noNamedILS, markerSetName); return -1; } mDataChannels = new ChannelData* [mNumberOfChannels + 1]; int i; const int* fsaChannelMap = mMarkerSet->GetChannelMap (); for (i=0; i<=mNumberOfChannels; i++) mDataChannels [i] = NULL; mLaneStandardChannel = mMarkerSet->GetLaneStandardChannel (); for (i=1; i<=mNumberOfChannels; i++) { if (i == mLaneStandardChannel) mDataChannels [i] = GetNewLaneStandardChannel (i, mLaneStandard); else { if (isGrid) mDataChannels [i] = GetNewGridDataChannel (i, mLaneStandard); else mDataChannels [i] = GetNewDataChannel (i, mLaneStandard); } mDataChannels [i]->SetFsaChannel (fsaChannelMap [i]); } mLSData = mDataChannels [mLaneStandardChannel]; mLSData->SetMessageValue (channelIsILS, true); mMarkerSet->ResetLocusList (); Locus* nextLocus; while (nextLocus = mMarkerSet->GetNextLocus ()) mDataChannels [nextLocus->GetLocusChannel ()]->AddLocus (nextLocus); Progress = 1; return 0; }
void CoreBioComponent :: ReportXMLSmartSampleTableRowWithLinks (RGTextOutput& text, RGTextOutput& tempText) { RGString type; if (mIsNegativeControl) type = "-Control"; else if (mIsPositiveControl) type = "+Control"; else type = "Sample"; RGString pResult; RGString SimpleFileName (mName); size_t startPos = 0; size_t endPos; size_t length = SimpleFileName.Length (); if (SimpleFileName.FindLastSubstringCaseIndependent (DirectoryManager::GetDataFileType (), startPos, endPos)) { if (endPos == length - 1) SimpleFileName.ExtractAndRemoveLastCharacters (4); } SimpleFileName.FindAndReplaceAllSubstrings ("\\", "/"); startPos = endPos = 0; if (SimpleFileName.FindLastSubstring ("/", startPos, endPos)) { SimpleFileName.ExtractAndRemoveSubstring (0, startPos); } text << CLevel (1) << "\t\t<Sample>\n"; text << "\t\t\t<Name>" << xmlwriter::EscAscii (SimpleFileName, &pResult) << "</Name>\n"; text << "\t\t\t<SampleName>" << xmlwriter::EscAscii (mSampleName, &pResult) << "</SampleName>\n"; text << "\t\t\t<RunStart>" << mRunStart.GetData () << "</RunStart>\n"; text << "\t\t\t<Type>" << type.GetData () << "</Type>\n" << PLevel (); int trigger = Notice::GetMessageTrigger (); // int channelHighestLevel; // bool channelAlerts = false; int cbcHighestMsgLevel = GetHighestMessageLevelWithRestrictionSM (); RGDListIterator it (*mSmartMessageReporters); SmartMessageReporter* nextNotice; bool includesExportInfo = false; while (nextNotice = (SmartMessageReporter*) it ()) { if (nextNotice->HasViableExportInfo ()) { includesExportInfo = true; break; } } if (((cbcHighestMsgLevel > 0) && (cbcHighestMsgLevel <= trigger)) || includesExportInfo) { // text << CLevel (1) << "\t\t\t<SampleAlerts>\n" << PLevel (); // get message numbers and report ReportXMLSmartNoticeObjects (text, tempText, " "); // text << CLevel (1) << "\t\t\t</SampleAlerts>\n" << PLevel (); } mDataChannels [mLaneStandardChannel]->ReportXMLILSSmartNoticeObjects (text, tempText, " "); int i; //for (i=1; i<=mNumberOfChannels; i++) { // //if (i == mLaneStandardChannel) // // continue; // channelHighestLevel = mDataChannels [i]->GetHighestMessageLevelWithRestrictionSM (); // if ((channelHighestLevel > 0) && (channelHighestLevel <= trigger)) { // channelAlerts = true; // break; // } //} // if (channelAlerts) { text << CLevel (1) << "\t\t\t<ChannelAlerts>\n" << PLevel (); for (i=1; i<=mNumberOfChannels; i++) { if (i == mLaneStandardChannel) continue; mDataChannels [i]->ReportXMLSmartNoticeObjects (text, tempText, " "); } text << CLevel (1) << "\t\t\t</ChannelAlerts>\n" << PLevel (); // } mMarkerSet->ResetLocusList (); Locus* nextLocus; while (nextLocus = mMarkerSet->GetNextLocus ()) { nextLocus->ReportXMLSmartSampleTableRowWithLinks (text, tempText, " "); } if (mIsPositiveControl) text << CLevel (1) << "\t\t\t<PositiveControl>" << mPositiveControlName << "</PositiveControl>\n"; text << CLevel (1) << "\t\t</Sample>\n" << PLevel (); }
Locus* Bins :: AssembleLocusFromLineStrings () { // uses current values in mLocusLineStrings Locus* newLocus = new Locus (); int nLines = mLocusLineStrings.Length (); SplitLocusLine (mLocusLineStrings [0]); // This should give us the name field RGString name = mLocusLineFieldString [1]; cout << "Locus name = " << name.GetData () << endl; //cout << "Bins locus line 1: "; int i; int len = mLocusLineFieldString.Length (); //for (i=0; i<len; i++) { // cout << mLocusLineFieldString [i].GetData (); // if (i < len - 1) // cout << ", "; //} //cout << endl; RGString firstAlleleName; int firstLocusBP; double firstILSBP; double lastILSBP; RGString firstExtendedAlleleName; RGString lastExtendedAlleleName; int lineForFirstAllele = 0; for (i=1; i<nLines; i++) { SplitLocusLine (mLocusLineStrings [i]); if (mLocusLineFieldString.Length () < 4) { cout << "Could not find first allele for locus " << name.GetData () << endl; delete newLocus; return NULL; } if (mLocusLineFieldString.Length () >= 5) { if (mLocusLineFieldString [4] == "virtual") { if (i == 1) { firstExtendedAlleleName = mLocusLineFieldString [0]; } continue; } } firstAlleleName = mLocusLineFieldString [0]; firstILSBP = mLocusLineFieldString [1].ConvertToDouble (); firstLocusBP = (int) floor (firstILSBP + 0.5); lineForFirstAllele = i; break; } if (firstExtendedAlleleName.Length () == 0) firstExtendedAlleleName = firstAlleleName; bool foundLastExtendedAllele = false; for (i=nLines-1; i>lineForFirstAllele; i--) { SplitLocusLine (mLocusLineStrings [i]); if (mLocusLineFieldString.Length () < 4) continue; if (!foundLastExtendedAllele) { lastExtendedAlleleName = mLocusLineFieldString [0]; foundLastExtendedAllele = true; } if ((mLocusLineFieldString.Length () >= 5) && (mLocusLineFieldString [4] == "virtual")) continue; lastILSBP = mLocusLineFieldString [1].ConvertToDouble (); break; } if (lastExtendedAlleleName.Length () == 0) { cout << "Could not locate last extended allele name for locus: " << name.GetData () << endl; delete newLocus; return NULL; } newLocus->SetFirstCoreAllele (firstAlleleName); newLocus->SetFirstExtendedAllele (firstExtendedAlleleName); newLocus->SetLastExtendedAllele (lastExtendedAlleleName); newLocus->SetMinMaxSearchILSBP (firstILSBP, lastILSBP); // These will have to be adjusted later when core repeat number is known newLocus->SetFirstCoreLocusBP (firstLocusBP); newLocus->SetName (name); // Need to add to Locus ability to compute first and last extended bp return newLocus; }
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; }
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; }
Boolean RGDirectory :: MakeDirectory (const RGString& fullName) { return MakeDirectory(fullName.GetData()); }
RGDirectory :: RGDirectory (const RGString& fullName) { direct = opendir (fullName.GetData ()); }