Exemple #1
0
        Main(string[] args)
        {
            int i;

            for (i = 0; i < args.Length; ++i)
            {
                using (System.IO.FileStream fs = new System.IO.FileStream(
                           args[i],
                           System.IO.FileMode.Open,
                           System.IO.FileAccess.Read))
                {
                    System.Console.Write(args[i] + @": {0:d} bytes ... ", fs.Length);
                    byte[] T  = new byte[fs.Length];
                    int[]  SA = new int[fs.Length];
                    fs.Read(T, 0, T.Length);

                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                    sw.Start();
                    SAIS.sufsort(T, SA, T.Length);
                    sw.Stop();

                    double sec = (double)sw.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency;
                    System.Console.WriteLine(@"{0:f4} sec", sec);

                    check(T, SA, T.Length, true);
                    T  = null;
                    SA = null;
                }
            }
        }
Exemple #2
0
        private static IBigArray <ulong> buildSuffixArray(string str)
        {
            //Initialise the array that will hold the suffix array
            MemoryEfficientBigULongArray suffixArray = new MemoryEfficientBigULongArray(str.Length);

            //Calculate the suffix array
            long status = SAIS.sufsort(str, suffixArray, str.Length);

            if (status != 0)
            {
                string error = String.Format("Error occurred whilst generating the suffix array: {0}", status);
                Console.WriteLine(error);
                throw new Exception(error);
            }

            return(suffixArray);
        }
Exemple #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="fastaDatabase"></param>
        public SearchableDatabase(FastaDatabase fastaDatabase)
        {
            FastaDatabase = fastaDatabase;
            _sequence     = fastaDatabase.GetSequence();
            _suffixArray  = new int[_sequence.Length];
            SAIS.sufsort(_sequence, _suffixArray, _sequence.Length);

            var neighboringLcps = new byte[_suffixArray.Length];

            neighboringLcps[0] = 0;

            for (var i = 1; i < _suffixArray.Length; i++)
            {
                var lcp = IndexedDatabase.GetLcp(_sequence, _suffixArray[i - 1], _suffixArray[i]);
                neighboringLcps[i] = lcp;
            }

            _leftLcps  = new byte[_suffixArray.Length];
            _rightLcps = new byte[_suffixArray.Length];

            InitializeLcps(neighboringLcps, _leftLcps, _rightLcps, 0, _suffixArray.Length - 1);
        }
        Main(string[] args)
        {
            if (args.Length != 2)
            {
                System.Console.WriteLine(@"usage: bwt INFILE OUTFILE"); return;
            }

            System.Console.Write(args[0] + @" ... ");

            byte[] T = System.IO.File.ReadAllBytes(args[0]);
            int[]  A = new int[T.Length];

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            int pidx = SAIS.bwt(T, T, A, T.Length);

            sw.Stop();

            double sec = (double)sw.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency;

            System.Console.WriteLine(@"{0:f4} sec", sec);

            using (System.IO.FileStream outfs = new System.IO.FileStream(
                       args[1],
                       System.IO.FileMode.Create,
                       System.IO.FileAccess.Write))
            {
                byte[] U = new byte[4];
                U[0] = (byte)(pidx & 0xff); U[1] = (byte)((pidx >> 8) & 0xff);
                U[2] = (byte)((pidx >> 16) & 0xff); U[3] = (byte)((pidx >> 24) & 0xff);
                outfs.Write(U, 0, U.Length);
                outfs.Write(T, 0, T.Length);
                U = null;
            }

            T = null;
            A = null;
        }
Exemple #5
0
        private void CreatePermutedLongestCommonPrefixFile()
        {
            if (File.Exists(_pLcpFilePath))
            {
                File.Delete(_pLcpFilePath);
            }

            var sequence = FastaDatabase.GetSequence();
            //Console.WriteLine("Annotation: {0}", System.Text.Encoding.ASCII.GetString(sequence));
            var suffixArray = new int[sequence.Length - 1];

            SAIS.sufsort(sequence, suffixArray, sequence.Length - 1);

            var prevIndex = sequence.Length - 1;

            var pLcp = new byte[suffixArray.Length];

            // Data dependency: cannot run in parallel
            foreach (var index in suffixArray)
            {
                var lcp = GetLcp(sequence, prevIndex, index);
                pLcp[index] = lcp;
                //Console.WriteLine("{0}\t{1}", System.Text.Encoding.ASCII.GetString(sequence, offset, sequence.Length - offset - 1), lcp);
                prevIndex = index;
            }

            using (var fs = new FileStream(_pLcpFilePath, FileMode.OpenOrCreate, FileAccess.Write))
            {
                foreach (var lcp in pLcp)
                {
                    //Console.WriteLine("LCP: {0}", lcp);
                    fs.WriteByte(lcp);
                }
                fs.Write(BitConverter.GetBytes(FastaDatabase.FileFormatId), 0, sizeof(int));
                fs.Write(BitConverter.GetBytes(FastaDatabase.GetLastWriteTimeHash()), 0, sizeof(int));
            }
        }