public IndexedDatabase(FastaDatabase fastaDatabase) { FastaDatabase = fastaDatabase; var databaseFilePath = FastaDatabase.GetFastaFilePath(); //var databaseFilePathNoExt = Path.Combine(Path.GetDirectoryName(databaseFilePath), Path.GetFileNameWithoutExtension(databaseFilePath)); //_pLcpFilePath = databaseFilePathNoExt + PermutedLongestCommonPrefixFileExtension; _pLcpFilePath = Path.ChangeExtension(databaseFilePath, PermutedLongestCommonPrefixFileExtension); var lastWriteTimeHash = FastaDatabase.GetLastWriteTimeHash(); if (!File.Exists(_pLcpFilePath) || !FastaDatabase.CheckHashCodeBinaryFile(_pLcpFilePath, lastWriteTimeHash)) { Console.Write("Generating " + _pLcpFilePath + " ... "); CreatePermutedLongestCommonPrefixFile(); Console.WriteLine("Done"); } }
/// <summary> /// Constructor - build the index /// </summary> /// <param name="fastaDatabase"></param> public IndexedDatabase(FastaDatabase fastaDatabase) { FastaDatabase = fastaDatabase; var databaseFilePath = FastaDatabase.GetFastaFilePath(); //var databaseFilePathNoExt = Path.Combine(Path.GetDirectoryName(databaseFilePath), Path.GetFileNameWithoutExtension(databaseFilePath)); //_pLcpFilePath = databaseFilePathNoExt + PermutedLongestCommonPrefixFileExtension; _pLcpFilePath = Path.ChangeExtension(databaseFilePath, PermutedLongestCommonPrefixFileExtension); var lastWriteTimeHash = FastaDatabase.GetLastWriteTimeHash(); if (!File.Exists(_pLcpFilePath) || !FastaDatabase.CheckHashCodeBinaryFile(_pLcpFilePath, lastWriteTimeHash)) { Console.Write("Generating " + _pLcpFilePath + " ... "); CreatePermutedLongestCommonPrefixFile(); Console.WriteLine("Done"); } }
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)); } }