Esempio n. 1
0
        private static ExitCodes ProgramExecution()
        {
            var rootDirectory = new FileInfo(MitoMapFileNames[0]).Directory;

            if (rootDirectory == null)
            {
                return(ExitCodes.PathNotFound);
            }
            var version          = DataSourceVersionReader.GetSourceVersion(Path.Combine(rootDirectory.ToString(), "mitoMapSv"));
            var sequenceProvider = new ReferenceSequenceProvider(FileUtilities.GetReadStream(_compressedReference));
            var chrom            = sequenceProvider.RefNameToChromosome["chrM"];

            sequenceProvider.LoadChromosome(chrom);
            var mitoMapSvReaders      = MitoMapFileNames.Select(mitoMapFileName => new MitoMapSvReader(new FileInfo(mitoMapFileName), sequenceProvider)).ToList();
            var mergedMitoMapVarItems = MitoMapSvReader.MergeAndSort(mitoMapSvReaders);

            string outFileName = $"{version.Name}_{version.Version}";

            using (var nsaStream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outFileName + SaCommon.SiFileSuffix)))
            {
                var nsiWriter = new NsiWriter(new ExtendedBinaryWriter(nsaStream), version, GenomeAssembly.rCRS, SaCommon.MitoMapTag, ReportFor.StructuralVariants, SaCommon.SchemaVersion);
                nsiWriter.Write(mergedMitoMapVarItems);
            }

            return(ExitCodes.Success);
        }
        public void Readback_clingen()
        {
            var version = new DataSourceVersion("source1", "v1", DateTime.Now.Ticks, "description");

            using (var saStream = new MemoryStream())
            {
                using (var siWriter = new NsiWriter(saStream, version, GenomeAssembly.GRCh37, "clingen",
                                                    ReportFor.StructuralVariants, SaCommon.SchemaVersion, true))
                {
                    siWriter.Write(GetClinGenItems());
                }
                saStream.Position = 0;

                var siReader    = NsiReader.Read(saStream);
                var annotations = siReader.GetAnnotation(new Variant(ChromosomeUtilities.Chr1, 100, 14590, "", "<DEL>", VariantType.deletion, "1:100:14590:del", false, false, false, null, null, true)).ToArray();

                string[] expected =
                {
                    "\"chromosome\":\"1\",\"begin\":145,\"end\":2743,\"variantType\":\"copy_number_gain\",\"id\":\"cg1\",\"clinicalInterpretation\":\"likely benign\",\"phenotypes\":[\"phenotype1\",\"phenotype2\"],\"phenotypeIds\":[\"pid1\",\"pid2\"],\"observedGains\":3,\"validated\":true,\"reciprocalOverlap\":0.17935,\"annotationOverlap\":1",
                    "\"chromosome\":\"1\",\"begin\":14585,\"end\":5872743,\"variantType\":\"copy_number_loss\",\"id\":\"cg2\",\"clinicalInterpretation\":\"likely pathogenic\",\"phenotypes\":[\"phenotype3\",\"phenotype5\"],\"phenotypeIds\":[\"pid3\",\"pid5\"],\"observedLosses\":5,\"validated\":true,\"reciprocalOverlap\":0,\"annotationOverlap\":0"
                };

                Assert.Equal(2, annotations.Length);
                Assert.Equal(expected, annotations);
            }
        }
Esempio n. 3
0
        private static ExitCodes ProgramExecution()
        {
            var refProvider = new ReferenceSequenceProvider(FileUtilities.GetReadStream(_referenceSequencePath));
            var version     = DataSourceVersionReader.GetSourceVersion(_inputFile + ".version");
            var outFileName = $"{version.Name}_{version.Version}";

            using (var parser = new LcrRegionParser(GZipUtilities.GetAppropriateStreamReader(_inputFile), refProvider))
                using (var stream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outFileName + SaCommon.LcrFileSuffix)))
                    using (var writer = new NsiWriter(stream, version, refProvider.Assembly, SaCommon.LowComplexityRegionTag, ReportFor.AllVariants, SaCommon.NsiSchemaVersion))
                    {
                        writer.Write(parser.GetItems());
                    }

            return(ExitCodes.Success);
        }
Esempio n. 4
0
        private static ExitCodes ProgramExecution()
        {
            var    dosageMapRegionVersion = DataSourceVersionReader.GetSourceVersion(_dosageMapRegionFile + ".version");
            string outFileName            = $"{dosageMapRegionVersion.Name.Replace(' ', '_')}_{dosageMapRegionVersion.Version}";
            var    referenceProvider      = new ReferenceSequenceProvider(GZipUtilities.GetAppropriateReadStream(_inputReferencePath));

            using (var dosageSensitivityParser = new DosageMapRegionParser(GZipUtilities.GetAppropriateReadStream(_dosageMapRegionFile), referenceProvider.RefNameToChromosome))
                using (var stream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outFileName + SaCommon.SiFileSuffix)))
                    using (var nsiWriter = new NsiWriter(stream, dosageMapRegionVersion, referenceProvider.Assembly, SaCommon.DosageSensitivityTag, ReportFor.StructuralVariants, SaCommon.SchemaVersion))
                    {
                        nsiWriter.Write(dosageSensitivityParser.GetItems());
                    }

            return(ExitCodes.Success);
        }
Esempio n. 5
0
        private static ExitCodes ProgramExecution()
        {
            var    referenceProvider = new ReferenceSequenceProvider(FileUtilities.GetReadStream(_compressedReference));
            var    version           = DataSourceVersionReader.GetSourceVersion(_inputFileName + ".version");
            string outFileName       = $"{version.Name}_{version.Version}";

            using (var clinGenReader = new ClinGenReader(GZipUtilities.GetAppropriateStreamReader(_inputFileName), referenceProvider.RefNameToChromosome))
                using (var nsaStream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outFileName + SaCommon.SiFileSuffix)))
                    using (var nsiWriter = new NsiWriter(new ExtendedBinaryWriter(nsaStream), version, referenceProvider.Assembly, SaCommon.ClinGenTag, ReportFor.StructuralVariants, SaCommon.SchemaVersion))
                    {
                        nsiWriter.Write(clinGenReader.GetItems());
                    }

            return(ExitCodes.Success);
        }
Esempio n. 6
0
        private static ExitCodes ProgramExecution()
        {
            var referenceProvider = new ReferenceSequenceProvider(FileUtilities.GetReadStream(_compressedReference));
            var version           = DataSourceVersionReader.GetSourceVersion(_inputFileName + ".version");

            string outFileName = $"{version.Name}_{version.Version}".Replace(' ', '_');

            using (var reader = GZipUtilities.GetAppropriateStreamReader(_inputFileName))
                using (var oneKGenSvReader = new OneKGenSvReader(reader, referenceProvider.RefNameToChromosome))
                    using (var nsaStream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outFileName + SaCommon.IntervalFileSuffix)))
                        using (var nsiWriter = new NsiWriter(nsaStream, version, referenceProvider.Assembly,
                                                             SaCommon.OnekSvTag, ReportFor.StructuralVariants, SaCommon.SchemaVersion))
                        {
                            nsiWriter.Write(oneKGenSvReader.GetItems());
                        }

            return(ExitCodes.Success);
        }
Esempio n. 7
0
        private Stream GetNsiStream()
        {
            var stream  = new MemoryStream();
            var version = new DataSourceVersion("test", "June_2020", DateTime.Now.Ticks, "dummy");

            using (var writer = new NsiWriter(stream, version, GenomeAssembly.GRCh37, SaCommon.LowComplexityRegionTag,
                                              ReportFor.AllVariants,
                                              SaCommon.NsiSchemaVersion, true))
            {
                writer.Write(new []
                {
                    new LcrInterval(ChromosomeUtilities.Chr1, 100, 150),
                    new LcrInterval(ChromosomeUtilities.Chr1, 300, 450),
                    new LcrInterval(ChromosomeUtilities.Chr1, 600, 650),
                    new LcrInterval(ChromosomeUtilities.Chr2, 100, 150),
                    new LcrInterval(ChromosomeUtilities.Chr2, 300, 450),
                    new LcrInterval(ChromosomeUtilities.Chr2, 600, 650),
                });
            }

            stream.Position = 0;

            return(stream);
        }
Esempio n. 8
0
        private static ExitCodes ProgramExecution()
        {
            var referenceProvider = new ReferenceSequenceProvider(FileUtilities.GetReadStream(_compressedReference));

            List <CustomInterval> intervals;
            SaJsonSchema          intervalJsonSchema;
            string            jsonTag;
            DataSourceVersion version;
            string            outputPrefix = GetOutputPrefix(_inputFile);
            var nsaFileName       = Path.Combine(_outputDirectory, outputPrefix + SaCommon.SaFileSuffix);
            var nsaIndexFileName  = Path.Combine(_outputDirectory, outputPrefix + SaCommon.SaFileSuffix + SaCommon.IndexSufix);
            var nsaSchemaFileName = Path.Combine(_outputDirectory, outputPrefix + SaCommon.SaFileSuffix + SaCommon.JsonSchemaSuffix);
            var nsaItemsCount     = 0;

            using (var customReader = CustomAnnotationsParser.Create(GZipUtilities.GetAppropriateStreamReader(_inputFile), referenceProvider))
                using (var nsaStream = FileUtilities.GetCreateStream(nsaFileName))
                    using (var indexStream = FileUtilities.GetCreateStream(nsaIndexFileName))
                        using (var nsaWriter = new NsaWriter(
                                   new ExtendedBinaryWriter(nsaStream),
                                   new ExtendedBinaryWriter(indexStream),
                                   version = new DataSourceVersion(customReader.JsonTag, GetInputFileName(_inputFile), DateTime.Now.Ticks),
                                   referenceProvider,
                                   customReader.JsonTag,
                                   customReader.MatchByAllele, // match by allele
                                   customReader.IsArray,       // is array
                                   SaCommon.SchemaVersion,
                                   false,                      // is positional
                                   false,                      // skip incorrect ref base
                                   true                        // throw error on conflicting entries
                                   ))
                            using (var saJsonSchemaStream = FileUtilities.GetCreateStream(nsaSchemaFileName))
                                using (var schemaWriter = new StreamWriter(saJsonSchemaStream))
                                {
                                    jsonTag       = customReader.JsonTag;
                                    nsaItemsCount = nsaWriter.Write(customReader.GetItems());
                                    schemaWriter.Write(customReader.JsonSchema);

                                    intervalJsonSchema = customReader.IntervalJsonSchema;
                                    intervals          = customReader.GetCustomIntervals();
                                }

            if (nsaItemsCount == 0)
            {
                if (File.Exists(nsaFileName))
                {
                    File.Delete(nsaFileName);
                }
                if (File.Exists(nsaIndexFileName))
                {
                    File.Delete(nsaIndexFileName);
                }
                if (File.Exists(nsaSchemaFileName))
                {
                    File.Delete(nsaSchemaFileName);
                }
            }

            if (nsaItemsCount == 0 && intervals == null)
            {
                throw new UserErrorException("The provided TSV has no valid custom annotation entries.");
            }

            if (intervals == null)
            {
                return(ExitCodes.Success);
            }

            using (var nsiStream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outputPrefix + SaCommon.SiFileSuffix)))
                using (var nsiWriter = new NsiWriter(new ExtendedBinaryWriter(nsiStream), version, referenceProvider.Assembly, jsonTag, ReportFor.AllVariants, SaCommon.SchemaVersion))
                    using (var siJsonSchemaStream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outputPrefix + SaCommon.SiFileSuffix + SaCommon.JsonSchemaSuffix)))
                        using (var schemaWriter = new StreamWriter(siJsonSchemaStream))
                        {
                            nsiWriter.Write(intervals);
                            schemaWriter.Write(intervalJsonSchema);
                        }

            return(ExitCodes.Success);
        }