public void FastAFormatterValidateWrite1() { var formatter = new FastAFormatter(); using (formatter.Open(Constants.FastaTempFileName)) { // Gets the actual sequence and the alphabet from the Xml string actualSequence = utilityObj.xmlUtil.GetTextValue(Constants.SimpleFastaNodeName, Constants.ExpectedSequenceNode); string alpName = utilityObj.xmlUtil.GetTextValue(Constants.SimpleFastaNodeName, Constants.AlphabetNameNode); // Logs information to the log file ApplicationLog.WriteLine(string.Format("FastA Formatter BVT: Validating with Sequence '{0}' and Alphabet '{1}'.", actualSequence, alpName)); var seqOriginal = new Sequence(Utility.GetAlphabet(alpName), actualSequence) { ID = "" }; Assert.IsNotNull(seqOriginal); // Use the formatter to write the original sequences to a temp file ApplicationLog.WriteLine(string.Format("FastA Formatter BVT: Creating the Temp file '{0}'.", Constants.FastaTempFileName)); var seqList = new List<ISequence> { seqOriginal, seqOriginal, seqOriginal }; formatter.Format(seqList); formatter.Close(); IEnumerable<ISequence> seqsNew = null; // Read the new file, then compare the sequences var parser = new FastAParser(); { parser.Alphabet = Alphabets.Protein; seqsNew = parser.Parse(Constants.FastaTempFileName); char[] seqString = seqsNew.ElementAt(0).Select(a => (char) a).ToArray(); var newSequence = new string(seqString); Assert.IsNotNull(seqsNew); ApplicationLog.WriteLine(string.Format(null, "FastA Formatter BVT: New Sequence is '{0}'.", newSequence)); // Now compare the sequences. int countNew = seqsNew.Count(); Assert.AreEqual(3, countNew); ApplicationLog.WriteLine("The Number of sequences are matching."); Assert.AreEqual(seqOriginal.ID, seqsNew.ElementAt(0).ID); Assert.AreEqual(new string(seqsNew.ElementAt(0).Select(a => (char) a).ToArray()), newSequence); ApplicationLog.WriteLine(string.Format(null, "FastA Formatter BVT: The FASTA sequences '{0}' are matching with Format() method.", newSequence)); // Passed all the tests, delete the tmp file. If we failed an Assert, // the tmp file will still be there in case we need it for debugging. File.Delete(Constants.FastaTempFileName); ApplicationLog.WriteLine("Deleted the temp file created."); } } }
public void FastAFormatterValidateWriteWithStream() { string actualSequence = string.Empty; var formatter = new FastAFormatter(); { using (formatter.Open(Constants.FastaTempFileName)) { // Gets the actual sequence and the alphabet from the Xml actualSequence = utilityObj.xmlUtil.GetTextValue(Constants.SimpleFastaNodeName, Constants.ExpectedSequenceNode); string alpName = utilityObj.xmlUtil.GetTextValue(Constants.SimpleFastaNodeName, Constants.AlphabetNameNode); // Logs information to the log file ApplicationLog.WriteLine(string.Format("FastA Formatter BVT: Validating with Sequence '{0}' and Alphabet '{1}'.", actualSequence, alpName)); var seqOriginal = new Sequence(Utility.GetAlphabet(alpName), actualSequence); seqOriginal.ID = ""; Assert.IsNotNull(seqOriginal); // Use the formatter to write the original sequences to a stream. ApplicationLog.WriteLine(string.Format("FastA Formatter BVT: Creating the Temp file '{0}'.", Constants.FastaTempFileName)); formatter.Format(seqOriginal); formatter.Close(); } IEnumerable<ISequence> seq = null; using (var reader = File.OpenRead(Constants.FastaTempFileName)) { // Read the new file, then compare the sequences var parser = new FastAParser(); { parser.Alphabet = Alphabets.Protein; seq = parser.Parse(reader); //Create a list of sequences. List<ISequence> seqsList = seq.ToList(); Assert.IsNotNull(seqsList); var seqString = new string(seqsList[0].Select(a => (char) a).ToArray()); Assert.AreEqual(actualSequence, seqString); } } // Passed all the tests, delete the tmp file. If we failed an Assert, // the tmp file will still be there in case we need it for debugging. File.Delete(Constants.FastaTempFileName); ApplicationLog.WriteLine("Deleted the temp file created."); } }
public void FastAFormatterInvalidateClose() { FastAFormatter formatter = new FastAFormatter(); formatter.Close(); }