//Creators public static Alphabet AlphabetByOrder(string[] sample, string alpha, int bitLength) { if (sample.Length == 0) throw new Exception(); var a = new List<String>(); int[] ii = new int[bitLength]; while (true) { var s = ""; for (int i = 0; i < bitLength; i++) s += alpha[ii[i]]; a.Add(s); ii[0]++; if (ii[0] < alpha.Length) continue; int index = 0; bool done = false, cont = false; while (ii[index] >= alpha.Length) { ii[index] = 0; if (index + 1 >= ii.Length) { done = true; break; } ii[index + 1]++; if (ii[index + 1] >= alpha.Length) index++; else { cont = true; break; } } if (cont) continue; if (done) break; break; } var r = new Alphabet(); for (int i = 0; i < sample.Length; i++) for (int j = 0; j < sample[i].Length - bitLength; j++) { var s = ""; for (int k = 0; k < bitLength; k++) s += sample[i][j + k]; r.AddMessageSample(s, a); } r.UpdateInfo(); return r; }
private static void TEST(string id, string f) { var testSeqStateLength = 2; var avgWindowLength = 5; //Base Sequences var text = Management.GetTextFromFile(f); List<string> heads, seqs; //var f = Management.GetTextFromFile(@"C:\Users\Ryan\Desktop\VSSD\vs projects\EvoMathProj\resources\data\ORFs.fasta"); //var f = Management.GetTextFromFile(@"C:\Users\Ryan\Desktop\VSSD\vs projects\EvoMathProj\resources\data\dj1.fasta"); CommandLibrary.StateSequence.FastaFileToArrays(text, out heads, out seqs); var baseAlpha = new Alphabet(new int[] { 1, 2, 3 }); baseAlpha.AddMessageSamples(seqs, null); baseAlpha.UpdateInfo(); //Test seq var testSeqIndex = -1; for (int i = 0; i < heads.Count; i++) if (heads[i].Contains(id)) { testSeqIndex = i; break; } if (testSeqIndex == -1) return; var testSeq = seqs[testSeqIndex]; var testSeqFinal = new List<double>(); var outputFileText = new List<string>(); //var testSeqAlpha = new Alphabet(new int[] { 2 }); for (int i = 0; i < testSeq.Length - (testSeqStateLength - 1); i += 1) { var curTestWord = ""; var curTestSeqInd = new List<double>(); var curTestSeqIndCum = 1.0; for (int j = 0; j < testSeqStateLength; j++) { curTestWord += testSeq[j + i]; curTestSeqInd.Add(baseAlpha.GetStateProbability("" + testSeq[j + i])); curTestSeqIndCum *= curTestSeqInd[curTestSeqInd.Count - 1]; } var probOfWord = baseAlpha.GetStateProbability(curTestWord); var y1 = (curTestSeqIndCum - probOfWord); var y2 = Math.Sqrt(y1 * y1); testSeqFinal.Add(y2); var valPI = 0.0; var valER = 0.0; if (testSeqFinal.Count >= avgWindowLength) { valPI = 1.0; var count = 0; for (int j = testSeqFinal.Count - (avgWindowLength); j < testSeqFinal.Count; j++) { valPI *= testSeqFinal[j]; valER += testSeqFinal[j]; count++; } Math.Pow(valPI, 1.0 / count); Math.Sqrt(valER / count); } outputFileText.Add( (i + 1) + "," + testSeq[i] + "," + curTestWord + "," + probOfWord + "," + curTestSeqIndCum + "," + y1 + "," + y2 + "," + valER); //valPI); continue; } if (File.Exists(@"C:\Users\Ryan\Desktop\VSSD\vs projects\EvoMathProj\resources\data\InfoOut.csv")) File.Delete(@"C:\Users\Ryan\Desktop\VSSD\vs projects\EvoMathProj\resources\data\InfoOut.csv"); Management.WriteTextToFile(@"C:\Users\Ryan\Desktop\VSSD\vs projects\EvoMathProj\resources\data\InfoOut.csv", outputFileText.ToArray<string>(), false); return; }