public static bool GenerateCSVTETRA(string file) { int computed = Directory.GetFiles(Project.folderFullPath + "\\TETRA\\", "*.tet", SearchOption.TopDirectoryOnly).Length; if (computed != 0)//make sure there are some results { StreamWriter writer = new StreamWriter(file); writer.Write("name,"); // cell 1:1 string[] tetraPairs = new string[computed]; tetraPairs = Directory.GetFiles(Project.folderFullPath + "\\TETRA\\", "*.tet", SearchOption.TopDirectoryOnly); //array of full filenames List <string> tetraNames = new List <string>(); foreach (string pair in tetraPairs) { tetraNames.Add(Path.GetFileNameWithoutExtension(pair)); //list of filenames without the extensions } List <string> tetraNamesUnique = new List <string>(); foreach (string pair in tetraNames) { string[] temp = new string[2]; temp = pair.Split(new string[] { "_vs_" }, StringSplitOptions.None); if (!tetraNamesUnique.Contains(temp[0])) { tetraNamesUnique.Add(temp[0]); } if (!tetraNamesUnique.Contains(temp[1])) { tetraNamesUnique.Add(temp[1]); } }//filenames split again to individual fasta names, only unique names matter for the table consturction foreach (string name in tetraNamesUnique) { writer.Write(name + ",");//write first row (fasta names) } bool success = false; foreach (string a in tetraNamesUnique) { writer.Write(Environment.NewLine + a + ",");//new row with another name foreach (string b in tetraNamesUnique) { if (a == b) { writer.Write("X,"); //this value could also be 100 - comparing the sequence with itself (diagonal) } else { if (File.Exists(Project.folderFullPath + "\\TETRA\\" + a + "_vs_" + b + ".tet")) { StreamReader reader = new StreamReader(Project.folderFullPath + "\\TETRA\\" + a + "_vs_" + b + ".tet"); double GCC; if (Double.TryParse(reader.ReadLine(), NumberStyles.Any, CultureInfo.InvariantCulture, out GCC)) { writer.Write(GCC.ToString() + ","); reader.Close(); success = true; } else { writer.Write("err,");//error parsing } } else { writer.Write("nc,");//not computed } } } } writer.Close(); if (success == true) //atleast one valid value in the table { return(true); } else { File.Delete(file); //There is no valid result in the matrix - delete it. return(false); } } else { return(false); } }
public static bool GenerateCSVAniAvg(string file) { int computed = Directory.GetFiles(Project.folderFullPath + "\\ANI\\", "*.ani", SearchOption.TopDirectoryOnly).Length; if (computed != 0)//make sure there are some results { StreamWriter writer = new StreamWriter(file); writer.Write("name,"); // cell 1:1 string[] aniPairs = new string[computed]; aniPairs = Directory.GetFiles(Project.folderFullPath + "\\ANI\\", "*.ani", SearchOption.TopDirectoryOnly); //array of full filenames List<string> aniNames = new List<string>(); foreach (string pair in aniPairs) { aniNames.Add(Path.GetFileNameWithoutExtension(pair)); //list of filenames without the extensions } List<string> aniNamesUnique = new List<string>(); foreach (string pair in aniPairs) { string[] temp = new string[2]; temp = Path.GetFileNameWithoutExtension(pair).Split(new string[] { "_vs_" }, StringSplitOptions.None); if (!aniNamesUnique.Contains(temp[0])) aniNamesUnique.Add(temp[0]); if (!aniNamesUnique.Contains(temp[1])) aniNamesUnique.Add(temp[1]); }//filenames split again to individual fasta names, only unique names matter for the table consturction foreach (string name in aniNamesUnique) { writer.Write(name + ",");//write first row (fasta names) } bool success = false; foreach (string a in aniNamesUnique) { writer.Write(Environment.NewLine + a + ",");//new row with another name foreach (string b in aniNamesUnique) { if (a == b) { writer.Write("X,"); //A versus A = 100% identity and its pointless to compute or display its result, represented by x } else { if (File.Exists(Project.folderFullPath + "\\ANI\\" + a + "_vs_" + b + ".ani") && File.Exists(Project.folderFullPath + "\\ANI\\" + b + "_vs_" + a + ".ani")) { StreamReader reader1 = new StreamReader(Project.folderFullPath + "\\ANI\\" + a + "_vs_" + b + ".ani"); StreamReader reader2 = new StreamReader(Project.folderFullPath + "\\ANI\\" + b + "_vs_" + a + ".ani"); double GCC1; double GCC2; double GCC; if (Double.TryParse(reader1.ReadLine(), NumberStyles.Any, CultureInfo.InvariantCulture, out GCC1) && Double.TryParse(reader2.ReadLine(), NumberStyles.Any, CultureInfo.InvariantCulture, out GCC2))//verifies valid file structure and content { GCC = (GCC1 + GCC2) / 2; writer.Write(GCC.ToString() + ","); reader1.Close(); reader2.Close(); success = true; } else { writer.Write("err,");//error parsing } } else { writer.Write("nc,");//not computed } } } } writer.Close(); if (success == true) //atleast one valid value in the table { return true; } else { File.Delete(file); //There is no valid result in the matrix - delete it. return false; } } else { return false; } }