Пример #1
0
int Ladder :: MergeLocusIntoLadder (const Locus* locus) {
	
	// This combines info and then computes the rest

	Locus* matchingLocus = FindLocusByName (locus->GetName ());

	if (matchingLocus == NULL) {

		cout << "Could not find locus matching name:  " << locus->GetName ().GetData () << endl;
		return -1;
	}

	matchingLocus->SetFirstCoreLocusBP (locus->GetFirstCoreLocusBP ());
	matchingLocus->SetFirstExtendedAllele (locus->GetFirstExtendedAllele ());
	matchingLocus->SetLastExtendedAllele (locus->GetLastExtendedAllele ());
	matchingLocus->ComputeAllBPs ();
	matchingLocus->SetMinMaxSearchILSBP (locus->GetMinSearchILSBP (), locus->GetMaxSearchILSBP ());
	matchingLocus->AdjustSearchRegion ();
	matchingLocus->SetMerged ();

	return 0;
}
Пример #2
0
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;
}