示例#1
0
        public void FastaFormatterValidateFormat()
        {
            FastaFormatter formatter = new FastaFormatter();

            // Gets the actual sequence and the alphabet from the Xml
            string actualSequence = Utility._xmlUtil.GetTextValue(Constants.SimpleFastaNodeName,
                                                                  Constants.ExpectedSequenceNode);
            string alpName = Utility._xmlUtil.GetTextValue(Constants.SimpleFastaNodeName,
                                                           Constants.AlphabetNameNode);

            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format(null,
                                                   "FastA Formatter BVT: Validating with Sequence '{0}' and Alphabet '{1}'.",
                                                   actualSequence, alpName));

            Sequence seqOriginal = new Sequence(Utility.GetAlphabet(alpName),
                                                actualSequence);

            Assert.IsNotNull(seqOriginal);

            // Use the formatter to write the original sequences to a temp file
            ApplicationLog.WriteLine(string.Format(null,
                                                   "FastA Formatter BVT: Creating the Temp file '{0}'.", Constants.FastaTempFileName));

            formatter.Format(seqOriginal, Constants.FastaTempFileName);


            // Read the new file, then compare the sequences
            IList <ISequence> seqsNew = null;
            FastaParser       parser  = new FastaParser();

            seqsNew = parser.Parse(Constants.FastaTempFileName);
            Assert.IsNotNull(seqsNew);
            ApplicationLog.WriteLine(string.Format(null,
                                                   "FastA Formatter BVT: New Sequence is '{0}'.",
                                                   seqsNew[0].ToString()));

            // Now compare the sequences.
            int countNew = seqsNew.Count();

            Assert.AreEqual(1, countNew);
            ApplicationLog.WriteLine("The Number of sequences are matching.");

            Assert.AreEqual(seqOriginal.ID, seqsNew[0].ID);
            string orgSeq = seqOriginal.ToString();
            string newSeq = seqsNew[0].ToString();

            Assert.AreEqual(orgSeq, newSeq);
            Console.WriteLine(string.Format(null,
                                            "FastA Formatter BVT: The FASTA sequences '{0}' are matching with Format() method and is as expected.",
                                            seqsNew[0].ToString()));
            ApplicationLog.WriteLine(string.Format(null,
                                                   "FastA Formatter BVT: The FASTA sequences '{0}' are matching with Format() method.",
                                                   seqsNew[0].ToString()));

            // 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.");
        }
示例#2
0
        public void FastaFormatter()
        {
            // Test with FASTA file from Simon

            string filepathOriginal = @"testdata\FASTA\NC_005213.ffn";

            Assert.IsTrue(File.Exists(filepathOriginal));

            FastaParser    parser    = new FastaParser();
            FastaFormatter formatter = new FastaFormatter();

            // Read the original file
            IList <ISequence> seqsOriginal = null;

            parser       = new FastaParser();
            seqsOriginal = parser.Parse(filepathOriginal);
            Assert.IsNotNull(seqsOriginal);

            // Use the formatter to write the original sequences to a temp file
            string filepathTmp = Path.GetTempFileName();

            using (TextWriter writer = new StreamWriter(filepathTmp))
            {
                foreach (Sequence s in seqsOriginal)
                {
                    formatter.Format(s, writer);
                }
            }

            // Read the new file, then compare the sequences
            IList <ISequence> seqsNew = null;

            parser  = new FastaParser();
            seqsNew = parser.Parse(filepathTmp);
            Assert.IsNotNull(seqsOriginal);

            // Now compare the sequences.
            int countOriginal = seqsOriginal.Count();
            int countNew      = seqsNew.Count();

            Assert.AreEqual(countOriginal, countNew);

            int i;

            for (i = 0; i < countOriginal; i++)
            {
                Assert.AreEqual(seqsOriginal[i].ID, seqsNew[i].ID);
                string orgSeq = seqsOriginal[i].ToString();
                string newSeq = seqsNew[i].ToString();
                Assert.AreEqual(orgSeq, newSeq);
            }
            // 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(filepathTmp);
        }
示例#3
0
 protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
 {
     if ((Sequence == null) && (SequenceList != null))
     {
         FastaFormatter formatter = new FastaFormatter();
         formatter.Format(SequenceList, OutputFile);
     }
     else if ((Sequence != null) && (SequenceList == null))
     {
         FastaFormatter formatter = new FastaFormatter();
         formatter.Format(Sequence, OutputFile);
     }
     else if ((Sequence != null) && (SequenceList != null))
     {
         SequenceList.Add(Sequence);
         FastaFormatter formatter = new FastaFormatter();
         formatter.Format(SequenceList, OutputFile);
         SequenceList.Remove(Sequence);
     }
     return(ActivityExecutionStatus.Closed);
 }
示例#4
0
        public void FastaFormatterWithParseValidateFormat()
        {
            // Gets the expected sequence from the Xml
            string filePath = Utility._xmlUtil.GetTextValue(Constants.SimpleFastaNodeName,
                                                            Constants.FilePathNode);

            Assert.IsTrue(File.Exists(filePath));

            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format(null,
                                                   "FastA Formatter BVT: File Exists in the Path '{0}'.", filePath));

            FastaParser    parser    = new FastaParser();
            FastaFormatter formatter = new FastaFormatter();

            // Read the original file
            IList <ISequence> seqsOriginal = null;

            parser       = new FastaParser();
            seqsOriginal = parser.Parse(filePath);
            Assert.IsNotNull(seqsOriginal);

            // Use the formatter to write the original sequences to a temp file
            ApplicationLog.WriteLine(string.Format(null,
                                                   "FastA Formatter BVT: Creating the Temp file '{0}'.",
                                                   Constants.FastaTempFileName));

            using (TextWriter writer = new StreamWriter(Constants.FastaTempFileName))
            {
                foreach (Sequence s in seqsOriginal)
                {
                    formatter.Format(s, writer);
                }
            }

            // Read the new file, then compare the sequences
            IList <ISequence> seqsNew = null;

            parser  = new FastaParser();
            seqsNew = parser.Parse(Constants.FastaTempFileName);
            Assert.IsNotNull(seqsNew);
            ApplicationLog.WriteLine(string.Format(null,
                                                   "FastA Formatter BVT: New Sequence is '{0}'.",
                                                   seqsNew[0].ToString()));

            // Now compare the sequences.
            int countOriginal = seqsOriginal.Count();
            int countNew      = seqsNew.Count();

            Assert.AreEqual(countOriginal, countNew);
            ApplicationLog.WriteLine("The Number of sequences are matching.");

            int i;

            for (i = 0; i < countOriginal; i++)
            {
                Assert.AreEqual(seqsOriginal[i].ID, seqsNew[i].ID);
                string orgSeq = seqsOriginal[i].ToString();
                string newSeq = seqsNew[i].ToString();
                Assert.AreEqual(orgSeq, newSeq);
                Console.WriteLine(string.Format(null,
                                                "FastA Formatter BVT: The FASTA sequences '{0}' are matching with Format() method and is as expected.",
                                                seqsNew[i].ID));
                ApplicationLog.WriteLine(string.Format(null,
                                                       "FastA Formatter BVT: The FASTA sequences '{0}' are matching with Format() method.",
                                                       seqsNew[i].ID));
            }

            // 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.");
        }
示例#5
0
        /// <summary>
        /// Does the logic behind the sequence simulation
        /// </summary>
        internal void DoSimulation(SimulatorWindow window, string outputFileName, SimulatorSettings settings)
        {
            FileInfo file = new FileInfo(outputFileName);

            if (!file.Directory.Exists)
            {
                throw new ArgumentException("Could not write to the output directory for " + outputFileName);
            }

            if (settings.OutputSequenceCount <= 0)
            {
                throw new ArgumentException("'Max Output Sequences Per File' should be greater than zero.");
            }

            if (settings.SequenceLength <= 0)
            {
                throw new ArgumentException("'Mean Output Length' should be greater than zero.");
            }

            string filePrefix;

            if (String.IsNullOrEmpty(file.Extension))
            {
                filePrefix = file.FullName;
            }
            else
            {
                filePrefix = file.FullName.Substring(0, file.FullName.IndexOf(file.Extension));
            }

            string filePostfix = "_{0}.fa";

            int seqCount  = (settings.DepthOfCoverage * Sequence.Count) / settings.SequenceLength;
            int fileCount = seqCount / settings.OutputSequenceCount;

            if (seqCount % settings.OutputSequenceCount != 0)
            {
                fileCount++;
            }

            window.UpdateSimulationStats(seqCount, fileCount);

            if (results == null)
            {
                results = new List <ISequence>();
            }
            else
            {
                results.Clear();
            }

            int            fileIndex = 1;
            FastaFormatter formatter = new FastaFormatter();

            for (int i = 0; i < seqCount; i++)
            {
                results.Add(CreateSubsequence(settings, i));

                if (results.Count >= settings.OutputSequenceCount)
                {
                    FileInfo outFile = new FileInfo(filePrefix + string.Format(filePostfix, fileIndex++));
                    formatter.Format(results, outFile.FullName);
                    results.Clear();
                }
            }

            if (results.Count > 0)
            {
                FileInfo outFile = new FileInfo(filePrefix + string.Format(filePostfix, fileIndex++));
                formatter.Format(results, outFile.FullName);
            }

            window.NotifySimulationComplete(formatter.Name);
        }