private void CreateDecoy() { Sequence.Reverse(); var sequence = Sequence.Aggregate("", (current, aa) => current + aa.Residue); sequence = SimpleStringProcessing.Mutate(sequence, sequence.Length / 2); Peptide = sequence; Sequence = Sequence.GetSequenceFromMsGfPlusPeptideStr(sequence); }
public void DiaRankScore() { var methodName = MethodBase.GetCurrentMethod().Name; TestUtils.ShowStarting(methodName); const string dataFile = @"\\protoapps\UserData\Wilkins\BottomUp\HCD_QCShew\raw\QC_Shew_13_04_A_17Feb14_Samwise_13-07-28.raw"; const string tsvFile = @"\\protoapps\UserData\Wilkins\BottomUp\HCD_QCShew\tsv\QC_Shew_13_04_A_17Feb14_Samwise_13-07-28.tsv"; if (!File.Exists(dataFile)) { Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, dataFile); } if (!File.Exists(tsvFile)) { Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, tsvFile); } var parser = new TsvFileParser(tsvFile); var sequences = parser.GetData("Peptide"); var charges = parser.GetData("Charge"); var scans = parser.GetData("ScanNum"); var lcms = InMemoryLcMsRun.GetLcMsRun(dataFile, 0, 0); var rankScorer = new DiaRankScore( @"C:\Users\wilk011\Documents\DataFiles\TestFolder\HCD_QExactive_Tryp.txt"); using ( var outFile = new StreamWriter(@"C:\Users\wilk011\Documents\DataFiles\TestFolder\HCD_QCShew_Score_2.txt")) { outFile.WriteLine("Target\tDecoy"); for (int i = 0; i < sequences.Count; i++) { string sequenceStr = sequences[i]; int charge = Convert.ToInt32(charges[i]); int scan = Convert.ToInt32(scans[i]); var sequence = Sequence.GetSequenceFromMsGfPlusPeptideStr(sequenceStr); var decoySeq = Sequence.GetSequenceFromMsGfPlusPeptideStr(sequenceStr); decoySeq.Reverse(); var decoyStr = decoySeq.Aggregate("", (current, aa) => current + aa); decoyStr = SimpleStringProcessing.Mutate(decoyStr, sequence.Count / 2); decoySeq = Sequence.GetSequenceFromMsGfPlusPeptideStr(decoyStr); var sequenceScore = rankScorer.GetScore(sequence, charge, scan, lcms); var decoyScore = rankScorer.GetScore(decoySeq, charge, scan, lcms); outFile.WriteLine("{0}\t{1}", sequenceScore, decoyScore); } } }
/// <summary> /// Create the decoy version of this databse /// </summary> /// <param name="enzyme"></param> /// <param name="shuffle"></param> public void CreateDecoyDatabase(Enzyme enzyme, bool shuffle) { var reader = new FastaFileReader(); if (!reader.OpenFile(_databaseFilePath)) { return; } var decoyDatabaseFileName = GetDecoyDatabasePath(enzyme, shuffle); Console.WriteLine("Creating " + decoyDatabaseFileName); using (var decoyWriter = new StreamWriter(decoyDatabaseFileName)) { while (reader.ReadNextProteinEntry()) { var name = reader.ProteinName; var description = reader.ProteinDescription; var sequence = reader.ProteinSequence; decoyWriter.WriteLine(">{0}_{1} {2}", FastaDatabaseConstants.DecoyProteinPrefix, name, description); if (!shuffle) { // Reversed protein sequence var decoySequence = new StringBuilder(); for (var i = sequence.Length - 1; i >= 0; i--) { var residue = sequence[i]; if (enzyme != null && enzyme.Residues.Length > 0 && enzyme.IsCleavable(residue) && decoySequence.Length > 0) { var residueToBeReplaced = decoySequence[decoySequence.Length - 1]; decoySequence.Remove(decoySequence.Length - 1, 1); decoySequence.Append((char)residue); decoySequence.Append(residueToBeReplaced); } else { decoySequence.Append((char)residue); } } decoyWriter.WriteLine(decoySequence); } else { // Shuffled protein sequences decoyWriter.WriteLine(SimpleStringProcessing.Mutate(SimpleStringProcessing.Shuffle(sequence), NumMutations)); } } reader.CloseFile(); } }
public void TestStringMutation() { var methodName = MethodBase.GetCurrentMethod().Name; Utils.ShowStarting(methodName); const string str = "MSGRGKGGKGLGKGGAKRHRKVLRDNIQGITKPAIRRLARRGGVKRISGLIYEETRGVLKVFLENVIRDAVTYTEHAKRKTVTAMDVVYALKRQGRTLYGFGG"; // Histone H4 const int numMutations = 3; var mutated = SimpleStringProcessing.Mutate(str, numMutations); Console.WriteLine(mutated); Assert.IsTrue(str.Length == mutated.Length); var numDiff = str.Where((t, i) => t != mutated[i]).Count(); Console.WriteLine("Mutations: {0}", numDiff); //var strSorted = String.Concat(str.OrderBy(c => c)); //var shuffledSorted = String.Concat(mutated.OrderBy(c => c)); //Assert.IsTrue(strSorted.Equals(shuffledSorted)); }