public int Extract() { var count = 0; using (_reader) using (_writer) { for (var i = _begin; i <= _end; i++) { var sa = _reader.GetAnnotation(i) as SupplementaryAnnotationPosition; if (sa != null) { count++; _writer.Write(new SupplementaryPositionCreator(sa), i); } } var miniSaInterval = new AnnotationInterval(_begin, _end); // get the supplementary intervals overlapping the mini SA interval var suppIntervals = new List <SupplementaryInterval>(); var readerSuppInterval = _reader.GetSupplementaryIntervals(_renamer); if (readerSuppInterval != null) { foreach (var interval in readerSuppInterval) { if (miniSaInterval.Overlaps(interval.Start, interval.End)) { suppIntervals.Add(interval as SupplementaryInterval); } } } Console.WriteLine("Found {0} supplementary intervals.", suppIntervals.Count); _writer.SetIntervalList(suppIntervals); } return(count); }
public void ReadWriteWithSuppIntervals() { // NIR-1359 var randomPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); // create our expected data source versions var dbSnpVersion = new DataSourceVersion("dbSNP", "142", DateTime.Parse("2015-01-02").Ticks); var expectedDataSourceVersions = new List <DataSourceVersion> { dbSnpVersion }; // This is the case where Nirvana throws an error: Too many bytes in what should have been a 7 bit encoded Int32. var sa = new SupplementaryAnnotationPosition(5073770); var saCreator = new SupplementaryPositionCreator(sa); // adding a supplementary interval var intValues = new Dictionary <string, int>(); var doubleValues = new Dictionary <string, double>(); var freqValues = new Dictionary <string, double>(); var stringValues = new Dictionary <string, string>(); var boolValues = new List <string>(); var suppInterval = new SupplementaryInterval(5073770, 5073970, "chr1", "<DUP>", VariantType.duplication, "ClinVar", _renamer, intValues, doubleValues, freqValues, stringValues, boolValues); suppInterval.AddStringValue("ID", "RandomClin001"); // the above code was unit tested in MergeDbSnpClinVar() using (var writer = new SupplementaryAnnotationWriter(randomPath, "chr9", expectedDataSourceVersions)) { writer.SetIntervalList(new List <SupplementaryInterval> { suppInterval }); writer.Write(saCreator, sa.ReferencePosition); } // read the supplementary annotation file using (var reader = new SupplementaryAnnotationReader(randomPath)) { // read the stored intervals var suppIntervals = reader.GetSupplementaryIntervals(_renamer).ToList(); Assert.Equal(1, suppIntervals.Count); foreach (var interval in suppIntervals) { Assert.Equal(5073770, interval.Start); Assert.Equal(5073970, interval.End); Assert.Equal("<DUP>", interval.AlternateAllele); Assert.Equal("ClinVar", interval.Source); Assert.Equal("duplication", interval.VariantType.ToString()); foreach (var keyValuePair in interval.StringValues) { if (keyValuePair.Key == "ID") { Assert.Equal("RandomClin001", keyValuePair.Value); } if (keyValuePair.Key == "vid") { Assert.Equal("1:5073770:5073970", keyValuePair.Value); } } } } File.Delete(randomPath); File.Delete(randomPath + ".idx"); }
public void ReadAndWrite() { // read the supplementary annotation file using (var reader = new SupplementaryAnnotationReader(_randomPath)) { var observedDataSourceVersions = reader.Header.DataSourceVersions; var refSeq = reader.Header.ReferenceSequenceName; var dataVersion = reader.Header.DataVersion; var creationTime = reader.Header.CreationTimeTicks; var genomeAssembly = reader.Header.GenomeAssembly; // check the data source versions Assert.Equal(observedDataSourceVersions.Count, 1); var observedDataSourceVersion = observedDataSourceVersions[0]; Assert.Equal(_expectedDataSourceVersion.Name, observedDataSourceVersion.Name); Assert.Equal(_expectedDataSourceVersion.Version, observedDataSourceVersion.Version); Assert.Equal(_expectedDataSourceVersion.ReleaseDateTicks, observedDataSourceVersion.ReleaseDateTicks); Assert.NotNull(refSeq); Assert.Equal(SupplementaryAnnotationCommon.DataVersion, dataVersion); Assert.True(DateTime.MinValue.Ticks != creationTime); Assert.True(genomeAssembly == GenomeAssembly.Unknown); var expDbsnp1 = ((DbSnpAnnotation) _expectedAnnotation1.AlleleSpecificAnnotations[AltAllele].Annotations[ DataSourceCommon.GetIndex(DataSourceCommon.DataSource.DbSnp)]).DbSnp; var expDbsnp2 = ((DbSnpAnnotation) _expectedAnnotation2.AlleleSpecificAnnotations[AltAllele].Annotations[ DataSourceCommon.GetIndex(DataSourceCommon.DataSource.DbSnp)]).DbSnp; var expDbsnp3 = ((DbSnpAnnotation) _expectedAnnotation3.AlleleSpecificAnnotations[AltAllele].Annotations[ DataSourceCommon.GetIndex(DataSourceCommon.DataSource.DbSnp)]).DbSnp; // extract the three annotations var observedAnnotation1 = reader.GetAnnotation(100) as SupplementaryAnnotationPosition; var observedAnnotation2 = reader.GetAnnotation(101) as SupplementaryAnnotationPosition; var observedAnnotation3 = reader.GetAnnotation(102) as SupplementaryAnnotationPosition; var obsDbsnp1 = ((DbSnpAnnotation) observedAnnotation1.AlleleSpecificAnnotations[AltAllele].Annotations[ DataSourceCommon.GetIndex(DataSourceCommon.DataSource.DbSnp)]).DbSnp; var obsDbsnp2 = ((DbSnpAnnotation) observedAnnotation2.AlleleSpecificAnnotations[AltAllele].Annotations[ DataSourceCommon.GetIndex(DataSourceCommon.DataSource.DbSnp)]).DbSnp; var obsDbsnp3 = ((DbSnpAnnotation) observedAnnotation3.AlleleSpecificAnnotations[AltAllele].Annotations[ DataSourceCommon.GetIndex(DataSourceCommon.DataSource.DbSnp)]).DbSnp; Assert.Equal(expDbsnp1, obsDbsnp1); Assert.Equal(expDbsnp2, obsDbsnp2); Assert.Equal(expDbsnp3, obsDbsnp3); // jump around the file var observedJumpAnnotation2 = reader.GetAnnotation(_expectedAnnotation2.ReferencePosition) as SupplementaryAnnotationPosition; var observedJumpAnnotation1 = reader.GetAnnotation(_expectedAnnotation1.ReferencePosition) as SupplementaryAnnotationPosition; var observedJumpAnnotation3 = reader.GetAnnotation(_expectedAnnotation3.ReferencePosition) as SupplementaryAnnotationPosition; var obsJumpDbsnp1 = ((DbSnpAnnotation) observedJumpAnnotation1.AlleleSpecificAnnotations[AltAllele].Annotations[ DataSourceCommon.GetIndex(DataSourceCommon.DataSource.DbSnp)]).DbSnp; var obsJumpDbsnp2 = ((DbSnpAnnotation) observedJumpAnnotation2.AlleleSpecificAnnotations[AltAllele].Annotations[ DataSourceCommon.GetIndex(DataSourceCommon.DataSource.DbSnp)]).DbSnp; var obsJumpDbsnp3 = ((DbSnpAnnotation) observedJumpAnnotation3.AlleleSpecificAnnotations[AltAllele].Annotations[ DataSourceCommon.GetIndex(DataSourceCommon.DataSource.DbSnp)]).DbSnp; Assert.Equal(expDbsnp1, obsJumpDbsnp1); Assert.Equal(expDbsnp2, obsJumpDbsnp2); Assert.Equal(expDbsnp3, obsJumpDbsnp3); var observedInterval = reader.GetSupplementaryIntervals(_renamer); Assert.Equal(_expectedInterval, observedInterval.First()); } }