Ejemplo n.º 1
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);
            string            nsaFileName       = Path.Combine(_outputDirectory, outputPrefix + SaCommon.SaFileSuffix);
            string            nsaIndexFileName  = nsaFileName + SaCommon.IndexSufix;
            string            nsaSchemaFileName = nsaFileName + SaCommon.JsonSchemaSuffix;
            ReportFor         reportFor;

            var nsaItemCount = 0;

            using (var parser = VariantAnnotationsParser.Create(GZipUtilities.GetAppropriateStreamReader(_inputFile), referenceProvider))
                using (var nsaStream = FileUtilities.GetCreateStream(nsaFileName))
                    using (var indexStream = FileUtilities.GetCreateStream(nsaIndexFileName))
                        using (var nsaWriter = CaUtilities.GetNsaWriter(nsaStream, indexStream, parser, CaUtilities.GetInputFileName(_inputFile), referenceProvider, out version))
                            using (var saJsonSchemaStream = FileUtilities.GetCreateStream(nsaSchemaFileName))
                                using (var schemaWriter = new StreamWriter(saJsonSchemaStream))
                                {
                                    (jsonTag, nsaItemCount, intervalJsonSchema, intervals) = CaUtilities.WriteSmallVariants(parser, nsaWriter, schemaWriter);
                                    reportFor = parser.ReportFor;
                                    if (intervals == null)
                                    {
                                        return(ExitCodes.Success);
                                    }
                                }

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

            using (var nsiStream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outputPrefix + SaCommon.IntervalFileSuffix)))
                using (var nsiWriter = CaUtilities.GetNsiWriter(nsiStream, version, referenceProvider.Assembly, jsonTag, reportFor))
                    using (var siJsonSchemaStream = FileUtilities.GetCreateStream(Path.Combine(_outputDirectory, outputPrefix + SaCommon.IntervalFileSuffix + SaCommon.JsonSchemaSuffix)))
                        using (var schemaWriter = new StreamWriter(siJsonSchemaStream))
                        {
                            nsiWriter.Write(intervals);
                            schemaWriter.Write(intervalJsonSchema);
                        }

            return(ExitCodes.Success);
        }
Ejemplo n.º 2
0
 public static NsaWriter GetNsaWriter(Stream nsaStream, Stream indexStream, VariantAnnotationsParser parser, string dataVersion, ISequenceProvider referenceProvider, out DataSourceVersion version)
 {
     return(new NsaWriter(
                nsaStream,
                indexStream,
                version = new DataSourceVersion(parser.JsonTag, dataVersion, DateTime.Now.Ticks),
                referenceProvider,
                parser.JsonTag,
                parser.MatchByAllele, // match by allele
                parser.IsArray,       // is array
                SaCommon.SchemaVersion,
                false,                // is positional
                false,                // skip incorrect ref base
                true                  // throw error on conflicting entries
                ));
 }
Ejemplo n.º 3
0
        public static (string JsonTag, int NsaItemsCount, SaJsonSchema IntervalJsonSchema, List <CustomInterval> Intervals) WriteSmallVariants(VariantAnnotationsParser parser, NsaWriter nsaWriter, StreamWriter schemaWriter)
        {
            int nsaItemsCount = nsaWriter.Write(parser.GetItems());

            schemaWriter.Write(parser.JsonSchema);
            var intervals = parser.GetCustomIntervals();

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