using System; using System.IO; public class readsynth { //Extract deprotection readings from 433A Applied Biosciences peptide synthesizer log files //V.V. 03/01/2011. vvostri@gmail.com public static void Main() { string filename; do { int Ncoupl = 1; //Since resin has Fmoc on bool error = false; Console.WriteLine("Enter synthesizer log file name (letter case is not important)"); filename = Console.ReadLine(); if (File.Exists(filename)) { StreamReader streamvariable = File.OpenText(filename); string lineinfile; lineinfile = streamvariable.ReadLine(); while (!lineinfile.Contains("Start")) { lineinfile = streamvariable.ReadLine(); if (lineinfile == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Problem encountered. Append \"Start\" on the first line of the log"); Console.ForegroundColor = ConsoleColor.Gray; error = true; lineinfile = "Start"; } } while (lineinfile != null) { if (lineinfile.Contains("Cartridge")) { if (lineinfile.Contains("Sending")) { } else { Ncoupl++; } } lineinfile = streamvariable.ReadLine(); } streamvariable.Close(); int[,] readings = new int[2, Ncoupl * 10]; string[] sequence = new string[Ncoupl * 10]; string[] seq = new string[Ncoupl]; for (int index = 0; index != Ncoupl * 10; index++) { readings[0, index] = index; } Ncoupl = 0; int counter = 0; streamvariable = File.OpenText(filename); lineinfile = streamvariable.ReadLine(); while (!lineinfile.Contains("Start")) { lineinfile = streamvariable.ReadLine(); if (lineinfile == null) { lineinfile = "Start"; } } while (lineinfile != null) { if (lineinfile.Contains("Cartridge")) { if (lineinfile.Contains("Sending")) { } else { Ncoupl++; string[] split = lineinfile.Split(new string[] { " " }, StringSplitOptions.None); seq[Ncoupl] = split[1]; counter++; while (counter % 10 != 0) { counter++; } split = lineinfile.Split(new string[] { " " }, StringSplitOptions.None); try { sequence[counter] = split[1]; } catch { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Problem encountered. Is number of deprotections 10+ for one of the residues?"); Console.ForegroundColor = ConsoleColor.Gray; error = true; } } } sequence[0] = "resin"; seq[0] = "resin"; if (lineinfile.Contains("Peak")) { string[] split = lineinfile.Split(new string[] { "Peak " }, StringSplitOptions.None); try { readings[1, counter] = Convert.ToInt16(split[1]); } catch { error = true; } counter++; } lineinfile = streamvariable.ReadLine(); } streamvariable.Close(); FileStream file = new FileStream(filename + ".csv", FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(file); { for (counter = 0; counter != (Ncoupl + 1) * 10; counter++) { sw.Write(readings[0, counter]); sw.Write(","); sw.Write(readings[1, counter]); sw.Write(","); sw.Write(sequence[counter]); if (counter < Ncoupl +1) { sw.Write(","); sw.Write(seq[counter]); } sw.Write("\r\n"); } } sw.Close(); file.Close(); if (error == true) { Console.WriteLine("Problems were encountered with file {0}.\n", filename); } else { Console.WriteLine("File {0} has been converted\n", filename); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("File {0} not found\n", filename); Console.ForegroundColor = ConsoleColor.Gray; } } while (filename != "quit"); } }