protected static Alignment <string, char> CreateAlignment(params string[] alignment)
        {
            var sequences = new Tuple <string, AlignmentCell <char>, IEnumerable <AlignmentCell <char> >, AlignmentCell <char> > [alignment.GetLength(0)];

            for (int i = 0; i < alignment.Length; i++)
            {
                var      sb     = new StringBuilder();
                string[] split  = alignment[i].Split('|');
                string   prefix = split[0].Trim();
                sb.Append(prefix);

                string[] cellStrs = split[1].Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var      cells    = new AlignmentCell <char> [cellStrs.Length];
                for (int j = 0; j < cellStrs.Length; j++)
                {
                    if (cellStrs[j] == "-")
                    {
                        cells[j] = new AlignmentCell <char>();
                    }
                    else
                    {
                        sb.Append(cellStrs[j]);
                        cells[j] = new AlignmentCell <char>(cellStrs[j]);
                    }
                }

                string suffix = split[2].Trim();
                sb.Append(suffix);

                sequences[i] = Tuple.Create(sb.ToString(), new AlignmentCell <char>(prefix), (IEnumerable <AlignmentCell <char> >)cells, new AlignmentCell <char>(suffix));
            }
            return(new Alignment <string, char>(0, 0, sequences));
        }
Beispiel #2
0
        public Alignment(int rawScore, double normalizedScore, IEnumerable <Tuple <TSeq, AlignmentCell <TItem>, IEnumerable <AlignmentCell <TItem> >, AlignmentCell <TItem> > > sequences)
        {
            if (double.IsNaN(normalizedScore) || normalizedScore < 0 || normalizedScore > 1)
            {
                throw new ArgumentOutOfRangeException("normalizedScore");
            }
            Tuple <TSeq, AlignmentCell <TItem>, IEnumerable <AlignmentCell <TItem> >, AlignmentCell <TItem> >[] sequenceArray = sequences.ToArray();
            if (sequenceArray.Length == 0)
            {
                throw new ArgumentException("No sequences specified.", "sequences");
            }

            _rawScore        = rawScore;
            _normalizedScore = normalizedScore;
            var seqs     = new TSeq[sequenceArray.Length];
            var prefixes = new AlignmentCell <TItem> [sequenceArray.Length];
            var suffixes = new AlignmentCell <TItem> [sequenceArray.Length];

            for (int i = 0; i < sequenceArray.Length; i++)
            {
                seqs[i] = sequenceArray[i].Item1;

                prefixes[i] = sequenceArray[i].Item2;

                AlignmentCell <TItem>[] columnArray = sequenceArray[i].Item3.ToArray();
                if (_matrix == null)
                {
                    _matrix = new AlignmentCell <TItem> [sequenceArray.Length, columnArray.Length];
                }
                else if (columnArray.Length != _matrix.GetLength(1))
                {
                    throw new ArgumentException("All sequences are not the same length.", "sequences");
                }
                for (int j = 0; j < columnArray.Length; j++)
                {
                    _matrix[i, j] = columnArray[j];
                }

                suffixes[i] = sequenceArray[i].Item4;
            }
            _sequences = new ReadOnlyList <TSeq>(seqs);
            _prefixes  = new ReadOnlyList <AlignmentCell <TItem> >(prefixes);
            _suffixes  = new ReadOnlyList <AlignmentCell <TItem> >(suffixes);
        }