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; } } }
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); }
/// <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); }
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)); } }