public static void RunTheCode(string seq1File, string seq2File, int matchWeight, int misMatchWeight, int indlWeight) { ScoringParameterDto scoringParameter = new ScoringParameterDto(matchWeight, misMatchWeight, indlWeight); var seq1 = LoadProteinDatabase.GetProteins(seq1File); var seq2 = LoadProteinDatabase.GetProteins(seq2File); SequencesDto sequences = new SequencesDto(seq1[0].Seq, seq2[0].Seq); EvaluateDto evaluation = GridEvaluateFunction.Evaluate(scoringParameter, sequences); ResultsDto results = Traceback.Trace(evaluation, sequences); WriteAlignment.Write(results, scoringParameter); }
public static ResultsDto Trace(EvaluateDto eval, SequencesDto seqs) { string seq1 = seqs.Sequence1; string seq2 = seqs.Sequence2; string remstrA = seq1; string remstrB = seq2; int i = seq1.Length; int j = seq2.Length; string A = ""; string B = ""; while (remstrA.Length > 0 && remstrB.Length > 0) { if (eval.directs[i, j][0] == eval.matrix[i, j]) { B = seq2[j - 1].ToString() + B; A = '_'.ToString() + A; j--; } else if (eval.directs[i, j][1] == eval.matrix[i, j]) { A = seq1[i - 1].ToString() + A; B = '_'.ToString() + B; i--; } else if (eval.directs[i, j][2] == eval.matrix[i, j]) { A = seq1[i - 1].ToString() + A; B = seq2[j - 1].ToString() + B; i--; j--; remstrA = remstrA.Substring(0, i); remstrB = remstrB.Substring(0, j); } } int simScore = eval.matrix[seq1.Length, seq2.Length]; Alignment align = new Alignment(A, B); List <Alignment> aligns = new List <Alignment>(); aligns.Add(align); ResultsDto results = new ResultsDto(aligns, simScore); return(results); }
public async Task <ResultsDto> GetUserResultsCountAsync(string login) { if (login == null) { throw new ArgumentNullException(); } var sessions = await _sessionStorage.GetFinishedSessionsAsync(); ResultsDto results = new ResultsDto { WinCount = GetWinsCount(sessions, login), DrawCount = GetDrawCount(sessions, login), LossCount = GetLossCount(sessions, login) }; return(results); }
public static void Write(ResultsDto results, ScoringParameterDto scores) { List <Alignment> alignments = results.alignments; int simScore = results.SimilarityScore; int count = 0; int mismatch = 0; int gap = 0; int match = 0; string sep = ""; Console.WriteLine("Local Alignment Results \n"); string baseAbsoluteUri = Directory.GetCurrentDirectory(); string relativePath = @"\Output\LocalAlignmentResults.txt"; string path = Path.GetFullPath(baseAbsoluteUri + relativePath); if (!File.Exists(path)) { var outFile = File.Create(path); outFile.Close(); TextWriter tw = new StreamWriter(path); tw.WriteLine("Alignment " + ++count); tw.WriteLine("Match: {0}", scores.match); tw.WriteLine("Mismatch: {0}", scores.mismatch); tw.WriteLine("Gap: {0}", scores.gap); tw.WriteLine("Similarity Score: " + simScore + "\n"); foreach (var align in alignments) { int maxlength = Math.Max(align.Sequence1.Length, align.Sequence2.Length); for (int i = 0; i < align.Sequence1.Length; i++) { if (align.Sequence1[i] == align.Sequence2[i]) { if (align.Sequence1[i].Equals('_')) { gap = gap + 2; sep += " "; } else { sep += "|"; match++; } } else if (align.Sequence1[i].Equals('_') || align.Sequence2[i].Equals('_')) { sep += " "; gap++; } else { sep += " "; mismatch++; } } for (int line = 0; line < align.Sequence1.Length; line += 100) { if (line + 100 < align.Sequence1.Length) { tw.WriteLine(align.Sequence1.Substring(line, 100)); tw.WriteLine(sep.Substring(line, 100)); tw.WriteLine(align.Sequence2.Substring(line, 100) + "\n"); } else { tw.WriteLine(align.Sequence1.Substring(line)); tw.WriteLine(sep.Substring(line)); tw.WriteLine(align.Sequence2.Substring(line) + "\n"); } } tw.WriteLine("Identity: {0}/{1} ({2:F1}%)", match, maxlength, (match / (double)maxlength * 100)); tw.WriteLine("Gaps: {0}/{1} ({2:F1}%) \n\n", gap, maxlength, (gap / (double)maxlength * 100)); mismatch = 0; gap = 0; match = 0; tw.Close(); } } else if (File.Exists(path)) { using (var tw = new StreamWriter(path, false)) { tw.WriteLine("Alignment " + ++count); tw.WriteLine("Match: {0}", scores.match); tw.WriteLine("Mismatch: {0}", scores.mismatch); tw.WriteLine("Gap: {0}", scores.gap); tw.WriteLine("Similarity Score: " + simScore + "\n"); foreach (var align in alignments) { int maxlength = Math.Max(align.Sequence1.Length, align.Sequence2.Length); for (int i = 0; i < align.Sequence1.Length; i++) { if (align.Sequence1[i] == align.Sequence2[i]) { if (align.Sequence1[i].Equals('_')) { gap = gap + 2; sep += " "; } else { sep += "|"; match++; } } else if (align.Sequence1[i].Equals('_') || align.Sequence2[i].Equals('_')) { sep += " "; gap++; } else { sep += " "; mismatch++; } } for (int line = 0; line < align.Sequence1.Length; line += 100) { if (line + 100 < align.Sequence1.Length) { tw.WriteLine(align.Sequence1.Substring(line, 100)); tw.WriteLine(sep.Substring(line, 100)); tw.WriteLine(align.Sequence2.Substring(line, 100) + "\n"); } else { tw.WriteLine(align.Sequence1.Substring(line)); tw.WriteLine(sep.Substring(line)); tw.WriteLine(align.Sequence2.Substring(line) + "\n"); } } tw.WriteLine("Identity: {0}/{1} ({2:F1}%)", match, maxlength, (match / (double)maxlength * 100)); tw.WriteLine("Gaps: {0}/{1} ({2:F1}%) \n\n", gap, maxlength, (gap / (double)maxlength * 100)); mismatch = 0; gap = 0; match = 0; } } } sep = ""; foreach (var align in alignments) { int maxlength = Math.Max(align.Sequence1.Length, align.Sequence2.Length); Console.WriteLine("Alignment " + ++count); Console.WriteLine("Match: {0}", scores.match); Console.WriteLine("Mismatch: {0}", scores.mismatch); Console.WriteLine("Gap: {0}", scores.gap); Console.WriteLine("Similarity Score: " + simScore + "\n"); for (int i = 0; i < align.Sequence1.Length; i++) { if (align.Sequence1[i] == align.Sequence2[i]) { if (align.Sequence1[i].Equals('_')) { gap = gap + 2; sep += " "; } else { sep += "|"; match++; } } else if (align.Sequence1[i].Equals('_') || align.Sequence2[i].Equals('_')) { sep += " "; gap++; } else { sep += " "; mismatch++; } } for (int line = 0; line < align.Sequence1.Length; line += 100) { if (line + 100 < align.Sequence1.Length) { Console.WriteLine(align.Sequence1.Substring(line, 100)); Console.WriteLine(sep.Substring(line, 100)); Console.WriteLine(align.Sequence2.Substring(line, 100) + "\n"); } else { Console.WriteLine(align.Sequence1.Substring(line)); Console.WriteLine(sep.Substring(line)); Console.WriteLine(align.Sequence2.Substring(line) + "\n"); } } Console.WriteLine("Identity: {0}/{1} ({2:F1}%)", match, maxlength, (match / (double)maxlength * 100)); Console.WriteLine("Gaps: {0}/{1} ({2:F1}%) \n\n", gap, maxlength, (gap / (double)maxlength * 100)); mismatch = 0; gap = 0; match = 0; } Console.WriteLine("\n*** Press Any Key to Continue!"); Console.ReadKey(); }
public static ResultsDto Trace(EvaluateDto eval, SequencesDto seqs) { string seq1 = seqs.Sequence1; string seq2 = seqs.Sequence2; int largest = eval.matrix.Cast <int>().Max(); List <Alignment> aligns = new List <Alignment>(); int c = 0; List <int> rowmax = new List <int>(); List <int> colmax = new List <int>(); for (int row = 0; row < eval.matrix.GetLength(0); row++) { for (int col = 0; col < eval.matrix.GetLength(1); col++) { if (eval.matrix[row, col] == largest) { rowmax.Add(row); colmax.Add(col); c++; } } } List <string> A = new List <string>(); List <string> B = new List <string>(); for (int count = 0; count < c; count++) { string remstrA = seq1.Substring(0, rowmax[count] - 1); string remstrB = seq2.Substring(0, colmax[count] - 1); int i = rowmax[count]; int j = colmax[count]; A.Add(""); B.Add(""); while (remstrA.Length > 0 && remstrB.Length > 0) { if (eval.directs[i, j][0] == eval.matrix[i, j]) { B[count] = seq2[j - 1].ToString() + B[count]; A[count] = '_'.ToString() + A[count]; j--; } else if (eval.directs[i, j][1] == eval.matrix[i, j]) { A[count] = seq1[i - 1].ToString() + A[count]; B[count] = '_'.ToString() + B[count]; i--; } else if (eval.directs[i, j][2] == eval.matrix[i, j]) { A[count] = seq1[i - 1].ToString() + A[count]; B[count] = seq2[j - 1].ToString() + B[count]; i--; j--; remstrA = remstrA.Substring(0, i); remstrB = remstrB.Substring(0, j); } else { break; } } Alignment align = new Alignment(A[count], B[count]); aligns.Add(align); } int simScore = largest; ResultsDto results = new ResultsDto(aligns, simScore); return(results); }