public static void WriteDataFile(string fileName, NumericalText nt) { if (((nt.Data != null) && (nt.Data.Count > 0)) || ((nt.Tags != null) && (nt.Tags.Count > 0))) { int useLen = Math.Min(nt.Titles.Count, (nt.Data.Count + nt.Tags.Count)); int dataLen = nt.Data [0].Count; List <int> counts = new List <int> (); List <int> currentIndexes = new List <int> (); List <PrintOutNext> printTypes = new List <PrintOutNext> (); if (nt.Tags != null) { int tagInd = 0; foreach (List <string> sl in nt.Tags) { counts.Add(sl.Count - 1); printTypes.Add(PrintOutNext.Tag); dataLen = Math.Max(dataLen, sl.Count); currentIndexes.Add(tagInd); tagInd++; } } if (nt.Data != null) { int datInd = 0; foreach (List <Double> ld in nt.Data) { counts.Add(ld.Count - 1); printTypes.Add(PrintOutNext.Data); dataLen = Math.Max(dataLen, ld.Count); currentIndexes.Add(datInd); datInd++; } } using (StreamWriter sw = new StreamWriter(fileName)) { for (int i = 0; i < useLen; i++) { if (i > 0) { sw.Write("\t"); } sw.Write(nt.Titles [i]); } sw.Write("\n"); for (int j = 0; j < dataLen; j++) { for (int i = 0; i < useLen; i++) { if (i > 0) { sw.Write("\t"); } if (counts [i] >= j) { if (printTypes [i] == PrintOutNext.Data) { sw.Write(nt.Data [currentIndexes[i]] [j]); } else { sw.Write(nt.Tags [currentIndexes [i]] [j]); } } else { sw.Write("x"); } } sw.Write("\n"); } } MainData.UpdateLog("Saved " + MainData.MainWindow.MaxLenString(fileName, 20), false); } else { MainData.ShowMessageWindow("There isn't any data there to save!", false); } }
public void LoadGFF3(string fileName) { string idTag = AppSettings.Loading.GFF3_ID_TAG.Item; int tagSize = idTag.Length; string line = ""; string parentTag = "arent="; int pTagSize = parentTag.Length; int count = 0; long modulo = MainData.ScanFileForModulo(fileName, 5); long lineCount = modulo * 5; MainData.UpdateLog("Reading... ", true); char[] spChar = { '\t' }; char[] spChar2 = { ';' }; using (StreamReader sr = new StreamReader(fileName)) { while ((line = sr.ReadLine()) != null) { if (line.Length > 10) { string[] spstr = line.Split(spChar, 10); string[] spstr2 = spstr [8].Split(spChar2, 20); string ID = ""; string pID = ""; foreach (string st in spstr2) { if (st.Contains(idTag)) { ID = st; break; } } foreach (string st in spstr2) { if (st.Contains(parentTag)) { pID = st; break; } } ID = ID.Substring(tagSize); GFF3ApplyOptionsToID(ref ID); if (pID != "") { GFF3ApplyOptionsToID(ref pID); } Sense sn = Sense.Sense; if (spstr [6].Equals("-")) { sn = Sense.AntiSense; } else if (spstr [6].Equals(".")) { sn = Sense.None; } string nameOfType = ID + "#" + spstr [2] + "#" + pID;; int sta, end; bool A = int.TryParse(spstr [3], out sta); bool B = int.TryParse(spstr [4], out end); if (A && B) { if (Scaffolds.ContainsKey(spstr [0])) { Scaffolds [spstr [0]].SendComponent(nameOfType, sta, end, sn); } else { throw new Exception("Gff3 references scaffold not found in genome!"); } } } count++; if (count % modulo == 0) { long perc = (long)(((float)count / (float)lineCount) * 100); MainData.UpdateLog("Read " + perc + "% of gff3..", true); } } } if (AppSettings.Genes.GENERATE_ANY_PROMO.Item || AppSettings.Genes.GENERATE_FLANK3.Item) { MainData.UpdateLog("Generating GFF3 additional elements as described in Settings -> Genes", true); foreach (KeyValuePair <string, Scaffold> kvp in Scaffolds) { kvp.Value.RunGenePostLoad(); } } }