Beispiel #1
0
        /// <summary>
        /// Try Parse Sequence File.
        /// </summary>
        /// <param name="fileName">The fileName.</param>
        /// <param name="alphabet">The Alphabet.</param>
        /// <param name="sequences">List of sequences.</param>
        /// <returns>True if Parsed sequence properly.</returns>
        private static bool TryParseSequenceFile(string fileName, IAlphabet alphabet, out IList <ISequence> sequences)
        {
            // Read the first line.
            string firstLine;

            using (var reader = new StreamReader(fileName))
            {
                firstLine = reader.ReadLine();
            }

            // Attempt to discover the format.
            if (ValidateFastaFormat(firstLine))
            {
                var parse = new FastAParser {
                    Alphabet = alphabet
                };
                using (parse.Open(fileName))
                {
                    sequences = parse.Parse().ToList();
                }

                return(true);
            }

            if (ValidatePhylipFormat(firstLine))
            {
                var parse = new PhylipParser {
                    Alphabet = alphabet
                };
                using (parse.Open(fileName))
                {
                    sequences = ConvertAlignedSequenceToSequence(parse.Parse());
                }

                return(true);
            }

            if (ValidateTabFormat(firstLine))
            {
                var parse = new FieldTextFileParser {
                    Alphabet = alphabet
                };
                using (parse.Open(fileName))
                {
                    sequences = parse.Parse().ToList();
                    return(true);
                }
            }

            sequences = null;
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Try Parse Sequence File.
        /// </summary>
        /// <param name="fileName">The fileName.</param>
        /// <param name="alphabet">The Alphabet.</param>
        /// <param name="sequences">List of sequences.</param>
        /// <returns>True if Parsed sequence properly.</returns>
        private static bool TryParseSequenceFile(string fileName, IAlphabet alphabet, out IList <ISequence> sequences)
        {
            using (TextReader reader = new StreamReader(fileName))
            {
                string firstLine = reader.ReadLine();
                if (ValidateFastaFormat(firstLine))
                {
                    using (FastAParser parse = new FastAParser())
                    {
                        parse.Alphabet = alphabet;
                        sequences      = parse.Parse().ToList();
                    }

                    return(true);
                }
                else if (ValidatePhylipFormat(firstLine))
                {
                    PhylipParser parse = new PhylipParser();
                    parse.Alphabet = alphabet;
                    sequences      = ConvertAlignedSequenceToSequence(parse.Parse(fileName));
                    return(true);
                }
                else if (ValidateTabFormat(firstLine))
                {
                    using (FieldTextFileParser parse = new FieldTextFileParser(fileName))
                    {
                        parse.Alphabet = alphabet;
                        sequences      = parse.Parse().ToList();
                        return(true);
                    }
                }
                else
                {
                    sequences = null;
                    return(false);
                }
            }
        }