示例#1
0
        public static OccurrenceArray[] CreateFromFile(string fileName, DnaBwt bwt)
        {
            using (var file = File.OpenRead(fileName))
            {
                BinaryReader reader = new BinaryReader(file);
                int[][] compressedOccs = new int[4][]
                    {
                        new int[bwt.Length/CompressFactor+1],
                        new int[bwt.Length/CompressFactor+1],
                        new int[bwt.Length/CompressFactor+1],
                        new int[bwt.Length/CompressFactor+1]
                    };

                for (int i = 0; i < compressedOccs[0].Length; i++)
                {
                    for (int dnaBase = 0; dnaBase < 4; dnaBase++)
                    {
                        var value = reader.ReadInt32();
                        compressedOccs[dnaBase][i] = value;
                    }
                }

                OccurrenceArray[] occs = new[]
                    {
                        new OccurrenceArray(bwt, 0, compressedOccs[0]),
                        new OccurrenceArray(bwt, 1, compressedOccs[1]),
                        new OccurrenceArray(bwt, 2, compressedOccs[2]),
                        new OccurrenceArray(bwt, 3, compressedOccs[3])
                    };

                return occs;
            }
        }
示例#2
0
 protected OccurrenceArray(DnaBwt bwt, int dnaBase, int[] compressedOccurrences)
 {
     _compressedOcc = compressedOccurrences;
     _bwt = bwt;
     _length = _bwt.Length;
     _dnaBase = dnaBase;
 }
 public CompressedSuffixArray(uint[] compressedSuffixArray, DnaBwt bwt, OccurrenceArray[] occ, uint[] c)
 {
     _baseArray = compressedSuffixArray;
     _bwt = bwt;
     _occ = occ;
     _c = c;
     Length = bwt.Length;
 }
        public static CompressedSuffixArray CreateFromFile(string fileName, DnaBwt bwt, OccurrenceArray[] occ, uint[] c)
        {
            var buffer = File.ReadAllBytes(fileName);
            uint[] compressedSufArray = new uint[buffer.Length/4];
            for (int i = 0; i < compressedSufArray.Length; i++)
            {
                compressedSufArray[i] = BitConverter.ToUInt32(buffer, i*4);
            }

            CompressedSuffixArray csa = new CompressedSuffixArray(compressedSufArray, bwt, occ, c);
            return csa;
        }
示例#5
0
        public static DnaBwt ReadFromFile(string fileName)
        {
            using (var file = File.OpenRead(fileName))
            {
                var reader = new BinaryReader(file);
                var length = reader.ReadUInt32();
                var sentinelIndex = reader.ReadUInt32();

                byte[] bwt = reader.ReadBytes((int) (length/4 + (length%4 != 0 ? 1 : 0)));

                DnaBwt dnaBwt = new DnaBwt(bwt, length, sentinelIndex);
                return dnaBwt;
            }
        }
示例#6
0
        public static OccurrenceArray[] CreateOccurrenceArrays(DnaBwt bwt)
        {
            OccurrenceArray[] occArrays = new OccurrenceArray[4]
                {
                    new OccurrenceArray(bwt, 0, new int[bwt.Length/CompressFactor+1]),
                    new OccurrenceArray(bwt, 1, new int[bwt.Length/CompressFactor+1]),
                    new OccurrenceArray(bwt, 2, new int[bwt.Length/CompressFactor+1]),
                    new OccurrenceArray(bwt, 3, new int[bwt.Length/CompressFactor+1])
                };
            int[] sums = new int[4];
            for (long i = 0; i < bwt.Length; i++)
            {
                if (bwt[i] >= 0)
                    sums[bwt[i]]++;

                if (i%CompressFactor == 0)
                {
                    occArrays[0][i] = sums[0];
                    occArrays[1][i] = sums[1];
                    occArrays[2][i] = sums[2];
                    occArrays[3][i] = sums[3];
                }
            }

            return occArrays;
        }
示例#7
0
        public static void SavePrecomputedDataToFiles(string baseFileName, DnaSequence referenceGenome)
        {
            Level0String level0String = new Level0String(referenceGenome);
            LongSuffixArray suffixArray = LongSuffixArray.CreateSuffixArray(level0String);
            suffixArray.WriteToFile(baseFileName + ".csa", 32);

            DnaBwt bwt = new DnaBwt(level0String, suffixArray);
            bwt.WriteToFile(baseFileName + ".bwt");
            WriteCToFile(baseFileName + ".c", bwt);

            OccurrenceArray[] occs = OccurrenceArray.CreateOccurrenceArrays(bwt);
            OccurrenceArray.WriteToFile(baseFileName + ".occ", occs);
        }
示例#8
0
        public static void WriteCToFile(string fileName, DnaBwt bwt)
        {
            using (var file = File.Open(fileName, FileMode.Create))
            {
                uint[] c = new uint[4];
                for (long i = 0; i < bwt.Length; i++)
                {
                    if (bwt[i] < 0)
                        continue;

                    c[bwt[i]]++;
                }

                c[3] = c[0] + c[1] + c[2];
                c[2] = c[0] + c[1];
                c[1] = c[0];
                c[0] = 0;

                var writer = new BinaryWriter(file);
                for (int i = 0; i < 4; i++)
                {
                    writer.Write(c[i]);
                }
            }
        }