Ejemplo n.º 1
0
int Ladder :: MergeThisLadderInto (Ladder* ladder) {

	list <Locus*>::const_iterator locusIterator;
	Locus* nextLocus;
	Locus* prevLocus = NULL;
	double prevMax;
	double nextMin;
	double nextOriginal;
	double prevOriginal;

	for (locusIterator = mLocusList.begin(); locusIterator != mLocusList.end(); locusIterator++) {

		nextLocus = *locusIterator;
		ladder->MergeLocusIntoLadder (nextLocus);
	}

	// To do:  test that search regions do not overlap neighboring loci

	for (locusIterator = mLocusList.begin(); locusIterator != mLocusList.end(); locusIterator++) {

		nextLocus = *locusIterator;
		
		if (prevLocus == NULL) {

			prevLocus = nextLocus;
			continue;
		}

		if (nextLocus->GetChannel () != prevLocus->GetChannel ()) {

			prevLocus = nextLocus;
			continue;
		}

		prevMax = prevLocus->GetMaxSearchILSBP ();
		nextMin = nextLocus->GetMinSearchILSBP ();

		if (prevMax <= nextMin) {

			prevLocus = nextLocus;
			continue;
		}

		nextOriginal = nextLocus->GetOriginalMinSearchILSBP () - 0.55;
		prevOriginal = prevLocus->GetOriginalMaxSearchILSBP () + 0.55;

		if (prevOriginal > nextOriginal)
			prevOriginal = nextOriginal = 0.5 * (prevOriginal + nextOriginal);

		if (prevMax >= nextOriginal)
			prevLocus->SetMaxSearhILSBP (nextOriginal);

		if (nextMin <= prevOriginal)
			nextLocus->SetMinSearhILSBP (prevOriginal);

		prevLocus = nextLocus;
	}

	return 0;
}
Ejemplo n.º 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;
}