Exemple #1
0
        internal void Write(ushort chromIndex, NsaReader nsaReader)
        {
            if (nsaReader == null)
            {
                return;
            }

            var dataBlocks  = nsaReader.GetCompressedBlocks(chromIndex);
            var indexBlocks = nsaReader.GetIndexBlocks(chromIndex);

            var i = 0;//index of the index Blocks

            //cannot convert the dataBlocks into a list since that may take up GBs of memory (proportional to the nas file size)
            foreach (var dataBlock in dataBlocks)
            {
                if (i > indexBlocks.Count)
                {
                    throw new IndexOutOfRangeException("Nsa Index have less blocks than the Nsa file. They have to be the same.");
                }

                var oldIndexBlock = indexBlocks[i];
                _index.Add(chromIndex, oldIndexBlock.Start, oldIndexBlock.End, _writer.BaseStream.Position, oldIndexBlock.Length);
                dataBlock.WriteCompressedBytes(_writer);
                i++;
            }
            if (i < indexBlocks.Count)
            {
                throw new IndexOutOfRangeException("Nsa Index have more blocks than the Nsa file. They have to be the same.");
            }
        }
Exemple #2
0
        public void Preload()
        {
            var version = new DataSourceVersion("source1", "v1", DateTime.Now.Ticks, "description");

            using (var saStream = new MemoryStream())
                using (var indexStream = new MemoryStream())
                {
                    using (var extWriter = new ExtendedBinaryWriter(saStream, Encoding.UTF8, true))
                        using (var indexExtWriter = new ExtendedBinaryWriter(indexStream, Encoding.UTF8, true))
                        {
                            var saWriter = new NsaWriter(extWriter, indexExtWriter, version, GetAllASequenceProvider(), "dbsnp", true, true, SaCommon.SchemaVersion, false, true, false, 1024);
                            saWriter.Write(GetDbsnpItems(1000));
                        }

                    saStream.Position    = 0;
                    indexStream.Position = 0;

                    using (var saReader = new NsaReader(saStream, indexStream, 1024))
                    {
                        saReader.PreLoad(_chrom1, GetPositions(50, 1000));

                        Assert.Null(saReader.GetAnnotation(90));     //before any SA existed
                        Assert.NotNull(saReader.GetAnnotation(100)); //first entry of first block
                        Assert.NotNull(saReader.GetAnnotation(480)); //last query of first block
                        Assert.Null(saReader.GetAnnotation(488));    //between first and second block
                        Assert.NotNull(saReader.GetAnnotation(490)); //first entry of second block
                    }
                }
        }
        public void Write_clinvar_basic()
        {
            var version = new DataSourceVersion("source1", "v1", DateTime.Now.Ticks, "description");

            using (var saStream = new MemoryStream())
                using (var indexStream = new MemoryStream())
                {
                    using (var saWriter = new NsaWriter(saStream, indexStream, version, GetSequenceProvider(), "clinvar",
                                                        false, true, SaCommon.SchemaVersion, false, true, false, 1024, GenomeAssembly.GRCh37, true))
                    {
                        saWriter.Write(GetClinvarItems());
                    }

                    saStream.Position    = 0;
                    indexStream.Position = 0;

                    using (var saReader = new NsaReader(saStream, indexStream, 1024))
                    {
                        Assert.Equal(GenomeAssembly.GRCh37, saReader.Assembly);
                        Assert.Equal(version.ToString(), saReader.Version.ToString());
                        saReader.PreLoad(ChromosomeUtilities.Chr1, new List <int> {
                            100, 101, 106
                        });
                        var annotations = saReader.GetAnnotation(100).ToList();

                        Assert.Equal("T", annotations[0].refAllele);
                        Assert.Equal("A", annotations[0].altAllele);
                        Assert.Equal(
                            "\"id\":\"RCV0001\",\"reviewStatus\":\"no assertion provided\",\"alleleOrigins\":[\"origin1\"],\"refAllele\":\"T\",\"altAllele\":\"A\",\"phenotypes\":[\"phenotype1\"],\"medGenIds\":[\"medgen1\"],\"omimIds\":[\"omim1\"],\"orphanetIds\":[\"orpha1\"],\"significance\":[\"significance\"],\"lastUpdatedDate\":\"0001-01-01\",\"pubMedIds\":[\"10024875684920\"]",
                            annotations[0].annotation);

                        annotations = saReader.GetAnnotation(101).ToList();
                        Assert.Equal("A", annotations[0].refAllele);
                        Assert.Equal("", annotations[0].altAllele);
                        Assert.Equal(
                            "\"id\":\"RCV00011\",\"variationId\":101,\"reviewStatus\":\"no assertion provided\",\"alleleOrigins\":[\"origin1\"],\"refAllele\":\"A\",\"altAllele\":\"-\",\"phenotypes\":[\"phenotype1\"],\"medGenIds\":[\"medgen1\"],\"omimIds\":[\"omim1\"],\"orphanetIds\":[\"orpha1\"],\"significance\":[\"significance\"],\"lastUpdatedDate\":\"0001-01-01\",\"pubMedIds\":[\"10024875684920\"]",
                            annotations[0].annotation);

                        saReader.PreLoad(ChromosomeUtilities.Chr2, new List <int> {
                            200, 205
                        });
                        var(refAllele, altAllele, annotation) = saReader.GetAnnotation(200).First();
                        Assert.Equal("G", refAllele);
                        Assert.Equal("A", altAllele);
                        Assert.NotNull(annotation);
                    }
                }
        }