/// <summary>
 /// Writes a set of sequences to the formatter.
 /// </summary>
 /// <param name="formatter">Formatter</param>
 /// <param name="sequences">Sequences to write.</param>
 /// <param name="fileName">Filename to write to</param>
 public static void Format(this ISequenceAlignmentFormatter formatter, IEnumerable <ISequenceAlignment> sequences, string fileName)
 {
     using (FileStream fs = File.OpenWrite(fileName))
     {
         formatter.Format(fs, sequences);
     }
 }
        /// <summary>
        /// Writes a single sequence to the formatter.
        /// </summary>
        /// <param name="formatter">Formatter</param>
        /// <param name="sequence">Sequence</param>
        public static void Format(this ISequenceAlignmentFormatter formatter, ISequenceAlignment sequence)
        {
            var fs = ParserFormatterExtensions <ISequenceAlignmentFormatter> .GetOpenStream(formatter, true);

            if (fs != null)
            {
                formatter.Format(fs, sequence);
            }
            else
            {
                throw new Exception("You must open a formatter before calling Write.");
            }
        }
示例#3
0
        /// <summary>
        /// Returns sequence alignment formatter which supports the specified file.
        /// </summary>
        /// <param name="fileName">File name for which the formatter is required.</param>
        /// <returns>If found returns the formatter as ISequenceAlignmentFormatter else returns null.</returns>
        public static ISequenceAlignmentFormatter FindFormatterByFile(string fileName)
        {
            ISequenceAlignmentFormatter formatter = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                if (Helper.IsSAM(fileName))
                {
                    formatter = new SAMFormatter();
                }
                else
                {
                    formatter = null;
                }
            }

            return(formatter);
        }
示例#4
0
        /// <summary>
        /// Validates general Sequence Parser.
        /// </summary>
        /// <param name="nodeName">xml node name.</param>
        /// <param name="IsParser">IsParser is true if testcases is validating Parsers,
        /// false if formatter validation</param>
        void ValidateSequenceFileParser(string nodeName, bool IsParser)
        {
            // Gets the expected sequence from the Xml
            string[] filePaths = _utilityObj._xmlUtil.GetTextValues(nodeName,
                                                                    Constants.FilePathsNode);
            string parserDescription = _utilityObj._xmlUtil.GetTextValue(nodeName,
                                                                         Constants.DescriptionNode);
            string parserName = _utilityObj._xmlUtil.GetTextValue(nodeName,
                                                                  Constants.ParserNameNode);
            string fileTypes = _utilityObj._xmlUtil.GetTextValue(nodeName,
                                                                 Constants.FileTypesNode);

            // Get a default parser for the file types.
            for (int i = 0; i < filePaths.Length; i++)
            {
                if (IsParser)
                {
                    ISequenceAlignmentParser parser = SequenceAlignmentParsers.FindParserByFile(filePaths[i]);
                    string description = parser.Description.Replace("\r", "").Replace("\n", "");
                    // Validate parser name, description and the file type supported by parser.
                    Assert.AreEqual(parserName, parser.Name);
                    Assert.AreEqual(parserDescription, description);
                    Assert.AreEqual(fileTypes, parser.FileTypes);
                }
                else
                {
                    ISequenceAlignmentFormatter formatter =
                        SequenceAlignmentFormatters.FindFormatterByFile(filePaths[i]);
                    Console.WriteLine(filePaths[i]);
                    Console.WriteLine(formatter.Description);
                    string description =
                        formatter.Description.Replace("\r", "").Replace("\n", "");
                    // Validate parser name, description and the file type supported by parser.
                    Assert.AreEqual(parserName, formatter.Name);
                    Assert.AreEqual(parserDescription, description);
                    Assert.AreEqual(fileTypes, formatter.FileTypes);
                }
            }

            Console.WriteLine(string.Format((IFormatProvider)null,
                                            "SequenceAlignmentParser : Type of the parser is validated successfully"));
            ApplicationLog.WriteLine("Type of the parser is validated successfully");
        }
 /// <summary>
 /// Writes a sequence to the formatter.
 /// </summary>
 /// <param name="formatter">Formatter</param>
 /// <param name="sequence">Sequence to write.</param>
 /// <param name="fileName">Filename to write to</param>
 public static void Format(this ISequenceAlignmentFormatter formatter, ISequenceAlignment sequence, string fileName)
 {
     // In case this extensions method is in scope, we will forward
     // to the BAMFormatter extension to properly handle the index
     // file.
     if (formatter is BAMFormatter &&
         sequence is SequenceAlignmentMap)
     {
         BAMFormatterExtensions.Format((BAMFormatter)formatter,
                                       (SequenceAlignmentMap)sequence, fileName);
     }
     else
     {
         using (FileStream fs = File.Create(fileName))
         {
             formatter.Format(fs, sequence);
         }
     }
 }
 /// <summary>
 /// Open a file and parse it with the sequence formatter.
 /// </summary>
 /// <param name="formatter">Formatter</param>
 /// <param name="filename">Filename</param>
 /// <returns>IDisposable to close stream.</returns>
 public static IDisposable Open(this ISequenceAlignmentFormatter formatter, string filename)
 {
     return(ParserFormatterExtensions <ISequenceAlignmentFormatter> .Open(formatter, filename));
 }
 /// <summary>
 /// Closes the formatter.
 /// </summary>
 /// <param name="formatter">Formatter.</param>
 public static void Close(this ISequenceAlignmentFormatter formatter)
 {
     ParserFormatterExtensions <ISequenceAlignmentFormatter> .Close(formatter);
 }