static private void BeforeOrAfterIsLessGeneralThan(AASetSequence flanking1, AASetSequence flanking2, out bool falseForSure, ref bool bAtLeastOneCharOfOtherIsMoreGeneral) { if (flanking1.Count > flanking2.Count) { falseForSure = true; return; } if (flanking2.Count > flanking1.Count) { bAtLeastOneCharOfOtherIsMoreGeneral = true; } for (int i = 0; i < flanking1.Count; ++i) { AASet c1 = flanking1[i]; AASet c2 = flanking2[i]; if (BeforeOrAfterIsMoreGeneralThan(c1, c2)) { falseForSure = true; return; } else if (BeforeOrAfterIsMoreGeneralThan(c2, c1)) { bAtLeastOneCharOfOtherIsMoreGeneral = true; } } falseForSure = false; return; }
private bool AfterAndCoreUnificationAtPosition(Disjunct other, int possiblePos, ref AASetSequence aAASetSequence) { int iHowMuchDoesThisStickIn = Math.Max(other.Core.Count - (possiblePos + Core.Count), 0); for (int iCommon = 0; iCommon < iHowMuchDoesThisStickIn; ++iCommon) { AASet chOther = other.Core[other.Core.Count - iHowMuchDoesThisStickIn + iCommon]; if (iCommon < After.Count) { AASet chThis = After[(int)iCommon]; AASet chUnifyOrEmpty = FlankingAndCoreUnifyOrEmpty(chThis, chOther); if (chUnifyOrEmpty == AASet.Empty) //!!!const { return(false); } aAASetSequence.Append(chUnifyOrEmpty); } else { aAASetSequence.Append(chOther); } } return(true); }
static private AASet FlankingUnifyOrOptionalEmpty(AASet c1, AASet c2) { Debug.Assert(AASetSequence.IsOptional(c1) && AASetSequence.IsOptional(c2)); // real assert AASet result = c1 & c2; return(result); }
private bool AfterUnificationAtPosition(Disjunct other, int possiblePos, ref AASetSequence aAASetSequence) { //This creates the new after string. It will be the unification of other's after string //and any of This's after that sticks out beyond the core of other int iHowMuchDoesThisStickOut = Math.Max(0, possiblePos + Core.Count + After.Count - other.Core.Count); int iHowMuchInCommon = Math.Min(iHowMuchDoesThisStickOut, other.After.Count); for (int iCommon = 0; iCommon < iHowMuchInCommon; ++iCommon) { AASet chThis = After[After.Count - iHowMuchDoesThisStickOut + iCommon]; AASet chOther = other.After[iCommon]; AASet chUnifyOrOptionalEmpty = FlankingUnifyOrOptionalEmpty(chThis, chOther); if (chUnifyOrOptionalEmpty == AASet.OptionalEmpty) //!!!const { return(false); } aAASetSequence.Append(chUnifyOrOptionalEmpty); } int iHowMuchLongerDoesOtherStickOutComparedToThis = Math.Max(0, other.After.Count - iHowMuchDoesThisStickOut); aAASetSequence.AppendSubsequence(other.After, iHowMuchInCommon, iHowMuchLongerDoesOtherStickOutComparedToThis); int iHowMuchLongerDoesThisStickOutComparedToOther = Math.Max(0, iHowMuchDoesThisStickOut - other.After.Count); aAASetSequence.AppendSubsequence(After, After.Count - iHowMuchLongerDoesThisStickOutComparedToOther, iHowMuchLongerDoesThisStickOutComparedToOther); return(true); }
private bool CoreIsMoreGeneralThan(AASet c1, AASet c2) { SpecialFunctions.CheckCondition(IsCore(c1) && IsCore(c2)); //!!!raise error bool b = ((c1 & (~c2)) != AASet.Empty); return(b); }
// public bool IsLessGeneralThan(Disjunct other) // { // SpecialFunctions.CheckCondition(this != other); //!!! raise error // SpecialFunctions.CheckCondition(FullAsString != other.FullAsString); //!!! raise error // // bool b = CoreIsLessGeneralThan(other) && BeforeOrAfterIsLessGeneralThan(Before, other.Before) && BeforeOrAfterIsLessGeneralThan(After, other.After); // return b; // } // private bool CoreIsLessGeneralThan(Disjunct other) // { // SpecialFunctions.CheckCondition(Core.Count == other.Core.Count); //!!! raise error // bool bAtLeastOneCharOfOtherIsMoreGeneral = false; // for(int i = 0; i < Core.Count; ++i) // { // AASet cMe = Core[i]; // AASet cOther = other.Core[i]; // if (CoreIsMoreGeneralThan(cMe, cOther)) // { // return false; // } // else if (CoreIsMoreGeneralThan(cOther, cMe)) // { // bAtLeastOneCharOfOtherIsMoreGeneral = true; // } // } // return bAtLeastOneCharOfOtherIsMoreGeneral; // } // static private bool BeforeOrAfterIsLessGeneralThan(AASetSequence flanking1, AASetSequence flanking2) // { // if (flanking1.Count > flanking2.Count) // { // return false; // } // // bool bAtLeastOneCharOfOtherIsMoreGeneral = (flanking2.Count > flanking1.Count); // for(int i = 0; i < flanking1.Count; ++i) // { // AASet c1 = flanking1[i]; // AASet c2 = flanking2[i]; // if (BeforeOrAfterIsMoreGeneralThan(c1, c2)) // { // return false; // } // else if (BeforeOrAfterIsMoreGeneralThan(c2, c1)) // { // bAtLeastOneCharOfOtherIsMoreGeneral = true; // } // } // return bAtLeastOneCharOfOtherIsMoreGeneral; // } static private bool BeforeOrAfterIsMoreGeneralThan(AASet c1, AASet c2) { SpecialFunctions.CheckCondition(!IsCore(c1) && !IsCore(c2)); //!!!raise error bool b = (c1 == AASet.OptionalAny && c2 != AASet.OptionalAny); return(b); }
private AASet FlankingAndCoreUnifyOrEmpty(AASet flanking, AASet core) { if (flanking == AASet.OptionalAny) { return(core); } Debug.Assert(AASetSequence.IsOptional(flanking)); // real assert AASet chUnifyOrEmpty = AASetSequence.UnifyOrEmpty(AASetSequence.ToRequired(flanking), core); return(chUnifyOrEmpty); }
private bool CoreUnificationAtPosition(Disjunct other, int possiblePos, ref AASetSequence aAASetSequence) { for (int iThisPos = 0; iThisPos < Core.Count; ++iThisPos) { AASet chThis = Core[iThisPos]; int iOtherPos = possiblePos + iThisPos; AASet chOther = other.Core[iOtherPos]; AASet chUnifyOrEmpty = AASetSequence.UnifyOrEmpty(chThis, chOther); if (chUnifyOrEmpty == AASet.Empty) //!!!const { return(false); } aAASetSequence.Append(chUnifyOrEmpty); } return(true); }
private AASetSequence UnifyWithAfterOrNullLongerShorter(AASetSequence longer, AASetSequence shorter) { Debug.Assert(longer.Count >= shorter.Count); // real assert AASetSequence sb = AASetSequence.GetInstance(longer); for (int i = 0; i < shorter.Count; ++i) { AASet chShorter = shorter[i]; AASet chLonger = longer[i]; AASet chUnifyOrEmpty = UnifyOrBoundWithFlanking(chShorter, chLonger); if (chUnifyOrEmpty == AASet.Empty) { return(null); } sb[i] = chUnifyOrEmpty; } return(sb); }
private void Rescore(string msAlignFilePath, string outputFilePath) { var parser = new TsvFileParser(msAlignFilePath); var sequences = parser.GetData("Peptide"); var scanNums = parser.GetData("Scan(s)").Select(s => Convert.ToInt32(s)).ToArray(); var charges = parser.GetData("Charge").Select(c => Convert.ToInt32(c)).ToArray(); var rows = parser.GetRows(); var headers = parser.GetHeaders(); using (var writer = new StreamWriter(outputFilePath)) { writer.WriteLine("{0}\t{1}", string.Join("\t", headers), IcScores.GetScoreNames()); for (var i = 0; i < parser.NumData; i++) { var row = rows[i]; var seqStr = SimpleStringProcessing.GetStringBetweenDots(sequences[i]); if (seqStr == null || seqStr.Contains("(")) { continue; //TODO: currently ignore ids with modifications } var composition = AASet.GetComposition(seqStr); //var sequence = new Sequence(seqStr, AASet); //if (sequence == null) //{ // Console.WriteLine("Ignore illegal sequence: {0}", seqStr); // continue; //} var charge = charges[i]; var scanNum = scanNums[i]; var scores = _topDownScorer.GetScores(AminoAcid.ProteinNTerm, seqStr, AminoAcid.ProteinCTerm, composition, charge, scanNum); if (scores == null) { continue; } writer.WriteLine("{0}\t{1}", row, scores); } } }
private void CoreIsLessGeneralThan(Disjunct other, out bool falseForSure, ref bool bAtLeastOneCharOfOtherIsMoreGeneral) { SpecialFunctions.CheckCondition(Core.Count == other.Core.Count); //!!! raise error for (int i = 0; i < Core.Count; ++i) { AASet cMe = Core[i]; AASet cOther = other.Core[i]; if (CoreIsMoreGeneralThan(cMe, cOther)) { falseForSure = true; return; } else if (CoreIsMoreGeneralThan(cOther, cMe)) { bAtLeastOneCharOfOtherIsMoreGeneral = true; } } falseForSure = false; return; }
private bool BeforeAndCoreUnificationAtPosition(Disjunct other, int possiblePos, ref AASetSequence aAASetSequence) { for (int iCommon = 0; iCommon < possiblePos; ++iCommon) { AASet chOther = other.Core[iCommon]; int iInBefore = Before.Count - possiblePos + iCommon; if (iInBefore >= 0) { AASet chThis = Before[iInBefore]; AASet chUnifyOrEmpty = FlankingAndCoreUnifyOrEmpty(chThis, chOther); if (chUnifyOrEmpty == AASet.Empty) //!!!const { return(false); } aAASetSequence.Append(chUnifyOrEmpty); } else { aAASetSequence.Append(chOther); } } return(true); }
private void SetLeftCoreRightRealizationAbstractionAndRegex() { Before = AASetSequence.GetInstance(); Core = AASetSequence.GetInstance(); After = AASetSequence.GetInstance(); StringBuilder sbCoreRealization = new StringBuilder(); StringBuilder sbFullRealization = new StringBuilder(); StringBuilder sbRegex = new StringBuilder(); CharEnumerator charEnumerator = FullAsString.GetEnumerator(); // Read 1st char bool bOK = charEnumerator.MoveNext(); char ch = char.MinValue; if (bOK) { ch = charEnumerator.Current; } // Read before part while (bOK) { if (!(ch == '.' || (char.IsLetter(ch) && !char.IsUpper(ch)))) { break; } AASet aaSet = Before.AppendGroundOrEdge(ch); sbRegex.Append(AASetSequence.ToRegexString(aaSet)); char fullRealizationChar = AASetSequence.ToFlankingRealizationChar(aaSet); sbFullRealization.Append(fullRealizationChar); bOK = charEnumerator.MoveNext(); if (bOK) { ch = charEnumerator.Current; } } // Read main part while (bOK) { if (ch == '.' || (char.IsLetter(ch) && !char.IsUpper(ch))) { break; } if (char.IsLetter(ch) && char.IsUpper(ch)) { AASet aaSet = Core.AppendGround(ch); char coreRealizationChar = AASetSequence.ToCoreRealizationChar(aaSet); Debug.Assert(ch == coreRealizationChar); //!!!real assert sbCoreRealization.Append(coreRealizationChar); sbFullRealization.Append(coreRealizationChar); sbRegex.Append(AASetSequence.ToRegexString(aaSet)); } else { SpecialFunctions.CheckCondition(ch == '['); //!!!raise error // Read [xyz] StringBuilder sbCharSet = new StringBuilder(); bOK = charEnumerator.MoveNext(); SpecialFunctions.CheckCondition(bOK); //!!!raise error ch = charEnumerator.Current; while (ch != ']') { sbCharSet.Append(ch); bOK = charEnumerator.MoveNext(); SpecialFunctions.CheckCondition(bOK); //!!!raise error ch = charEnumerator.Current; } SpecialFunctions.CheckCondition(sbCharSet.Length > 0); //!!!raies error AASet aaSet = Core.AppendGroundSet(sbCharSet.ToString()); char coreRealizationChar = AASetSequence.ToCoreRealizationChar(aaSet); sbCoreRealization.Append(coreRealizationChar); sbFullRealization.Append(coreRealizationChar); sbRegex.Append(AASetSequence.ToRegexString(aaSet)); } bOK = charEnumerator.MoveNext(); if (bOK) { ch = charEnumerator.Current; } } // Read after part while (bOK) { if (!(ch == '.' || (char.IsLetter(ch) && !char.IsUpper(ch)))) { break; } AASet aaSet = After.AppendGroundOrEdge(ch); sbRegex.Append(AASetSequence.ToRegexString(aaSet)); char fullRealizationChar = AASetSequence.ToFlankingRealizationChar(aaSet); sbFullRealization.Append(fullRealizationChar); bOK = charEnumerator.MoveNext(); if (bOK) { ch = charEnumerator.Current; } } FullAsAASetSequence = AASetSequence.Concatenate(Before, Core, After); CoreRealization = sbCoreRealization.ToString(); FullRealization = sbFullRealization.ToString(); RegexString = sbRegex.ToString(); }
static private bool IsCore(AASet c) { bool b = AASetSequence.IsRequired(c); return(b); }
private AASet UnifyOrBoundWithFlanking(AASet c1, AASet c2) { AASet result = AASetSequence.ToRequired(c1 & c2); return(result); }