Exemple #1
0
        /*
         * string s의 모든 로테이션을 구하고, 그것들로 matrix를 구성한다음,
         * 그 matrxix의 row들을 lexically하게 정렬한 후, 각 row들의 마지막 문자들을 취한 것이 BWT이다.
         *
         */
        static private BWTransformation BWTransform(string s)
        {
            int l = s.Length;

            char[,] ar = AllRotations(s);
            List <SortBuffer> sl = new List <SortBuffer>();

            string[] sa = new string[l];
            sa = Useful.Char2DArrToStringArr(ar, l, l);
            for (int i = 0; i < l; i++)
            {
                sl.Add(new SortBuffer(sa[i], i));
            }
            char[] r   = new char[l];
            int[]  rps = new int[l];
            //List<string> sl = sa.ToList<string>();
            StringBuilder            f     = new StringBuilder();
            IEnumerable <SortBuffer> query = sl.OrderBy(sb => sb.s);

            sl = new List <SortBuffer>();
            foreach (SortBuffer e in query)
            {
                sl.Add(e);
            }
            //Making BWM is done.
            for (int i = 0; i < l; i++)
            {
                r[i] = sl[i].s[l - 1]; f.Append(sl[i].s[0]); rps[i] = sl[i].rp;
            }
            BWTransformation tr = new BWTransformation();

            tr.L        = Useful.CharToString(r, l);
            tr.F        = f.ToString();
            tr.inputidx = sl[0].rp;
            tr.rps      = Useful.ArrayCopy <int>(rps, l);
            return(tr);
        }
Exemple #2
0
 public BWT(string s)
 {
     this.inputstr = s;
     this.length   = s.Length;
     this.bwt      = BWTransform(s);
 }