private void GCtoCSV_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = Project.folderFullPath; saveFileDialog1.FileName = Project.projectName + "_GC_Content"; saveFileDialog1.Filter = "table (.csv)|*.csv"; if (saveFileDialog1.ShowDialog() == true) { if (GCC.generateCSVGc(saveFileDialog1.FileName) == true) { MainWindow.main.lblStatus.Content = "Table generated to: " + System.IO.Path.GetFileName(saveFileDialog1.FileName); } else { MainWindow.main.lblStatus.Content = "Generating GC table failed (No results?)."; Project.ErrorLog.Add("Generating GC table failed (No results?)."); } } }
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; } }
private void GC() { int success = 0; int errors = 0; if (fastasGC.Count >= 1) { foreach (var fasta in fastasGC) { if (fasta.GC == true) { Status = "Computing GC content " + Path.GetFileNameWithoutExtension(fasta.FullPath); if (GCC.computeGCcontent(fasta.FullPath) == true) { success++; } else { string error = "File" + System.IO.Path.GetFileNameWithoutExtension(fasta.FullPath) + "no longer exists (it has been deleted, moved or renamed) - removing the file from the project."; Project.ErrorLog.Add(error); lblStatusGC.Content = error; Project.fastas.Remove(fasta.FullPath); errors++; } } } } else { string error = "Atleast one valid fasta file must be loaded to compute GC content."; MessageBox.Show(error, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); Status = error; } if (errors != 0 && success > 0) { string inf = "GC content finished but some files were missing or not accessible, these files were removed from the project."; MessageBox.Show(inf, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); Status = inf; MainWindow.main.Status = inf; MainWindow.main.EnableMatrixC(); } else if (errors == 0 && success > 0) { string inf = "Computation finished successfully"; MessageBox.Show(inf, "Sucess", MessageBoxButton.OK, MessageBoxImage.Information); Status = inf; MainWindow.main.Status = inf; MainWindow.main.EnableMatrixC(); } else { string error = "GC conent computation failed for all pairs. Missing files and respective pairs have been removed from the project. For more informations check logs."; MessageBox.Show(error, "Error", MessageBoxButton.OK, MessageBoxImage.Warning); Status = error; MainWindow.main.Status = error; Project.ErrorLog.Add(error); } }