示例#1
0
        public static bool TryGetLikelyFormatterForFile(string filename, out SequenceFormatter formatter)
        {
            string firstLine = Bio.Util.FileUtils.ReadLine(filename);

            Helper.CheckCondition(!string.IsNullOrEmpty(firstLine), "First line of file cannot be empty.");
            return(TryGetLikelyFormatterForFirstLineOfFile(firstLine, out formatter));
        }
示例#2
0
        public static bool TryGetMatrixFromSequenceFileAndPossiblyConvertDna2Aa <TRow, TCol, TVal>(string filename, TVal missing, bool keepOneValueVariables, ParallelOptions parallelOptions, out Matrix <TRow, TCol, TVal> matrix)
        {
            SequenceFormatter formatter;

            matrix = null;
            if (SequenceFormatter.TryGetLikelyFormatterForFile(filename, out formatter))
            {
                // only support true sequence formats.
                if (formatter is SequenceMatrix)
                {
                    return(false);
                }

                var seqs = formatter.Parse(filename);
                if (seqs.Count == 0)
                {
                    return(false);
                }

                if (seqs[0].IsDna())
                {
                    seqs = Translate(seqs, true);
                }

                matrix = NamedSequencesToMatrix <TRow, TCol, TVal>(seqs, missing, keepOneValueVariables, parallelOptions);
                return(true);
            }
            return(false);
        }
示例#3
0
        public static bool TryGetMatrixFromSequenceFile <TRow, TCol, TVal>(string filename, TVal missing, bool keepOneValueVariables, ParallelOptions parallelOptions, out Matrix <TRow, TCol, TVal> matrix)
        {
            SequenceFormatter formatter;

            matrix = null;
            if (SequenceFormatter.TryGetLikelyFormatterForFile(filename, out formatter))
            {
                // only support true sequence formats.
                if (formatter is SequenceMatrix)// || formatter is SequenceFormatterSparse)
                {
                    return(false);
                }

                var seqs = formatter.Parse(filename);
                if (seqs.Count == 0)
                {
                    Console.Error.WriteLine("No sequences in sequence file of format {0}", formatter.FileFormat);
                    return(false);
                }
                matrix = NamedSequencesToMatrix <TRow, TCol, TVal>(seqs, missing, keepOneValueVariables, parallelOptions);
                return(true);
                //if (IsDna(seqs[0].Sequence))
                //{
                //    seqs = NucSeqToAaSeq(seqs, true);
                //}
            }
            Console.Error.WriteLine("No SequenceFormatter matches this file type.");
            return(false);
        }
示例#4
0
        public static SequenceFormatter GetInstance(SequenceFileFormat format)
        {
            SequenceFormatter formatter = null;

            switch (format)
            {
            case SequenceFileFormat.Phylip:
                formatter = new Phylip();
                break;

            case SequenceFileFormat.Fasta:
                formatter = new Fasta();
                break;

            case SequenceFileFormat.Tab:
                formatter = new Tab();
                break;

            //case SequenceFileFormat.Sparse:
            //    formatter = new SequenceFormatterSparse();
            //    break;
            case SequenceFileFormat.Matrix:
                formatter = new SequenceMatrix();
                break;

            default:
                throw new Exception("Should never get here.");
            }
            formatter._formatType = format;

            return(formatter);
        }
示例#5
0
        public static List <NamedSequence> ParseWithMostLikelyFormatter(TextReader reader)
        {
            string            firstLine       = reader.ReadLine();
            string            allButFirstLine = reader.ReadToEnd();
            SequenceFormatter formatter       = null;

            TryGetLikelyFormatterForFirstLineOfFile(firstLine, out formatter).Enforce("Could not find a suitable sequence formatter for first line " + firstLine);

            TextReader           newReader = new StringReader(firstLine + "\n" + allButFirstLine);
            List <NamedSequence> result    = formatter.Parse(newReader);

            return(result);
        }
示例#6
0
        public static bool TryGetLikelyFormatterForFirstLineOfFile(string firstLine, out SequenceFormatter formatter)
        {
            foreach (string format in Enum.GetNames(typeof(SequenceFileFormat)))
            {
                formatter = GetInstance(format);
                if (formatter.ConformsToFileFormat(firstLine))
                {
                    return(true);
                }
            }

            formatter = null;
            return(false);
        }
示例#7
0
 public void FinalizeParse()
 {
     this.AddRange(SequenceFormatter.ParseWithMostLikelyFormatter(File));
 }
示例#8
0
        public override bool Equals(object obj)
        {
            SequenceFormatter other = obj as SequenceFormatter;

            return(other != null && _formatType == other._formatType);
        }