Beispiel #1
0
        // --------------------------------------------------------------------------------
        //
        // Interface functions
        //
        // --------------------------------------------------------------------------------

        public override void writeHeader(VCFHeader header)
        {
            // make sure the header is sorted correctly
            header = new VCFHeader(header.MetaDataInSortedOrder, header.GenotypeSampleNames);

            // create the config offsets map
            if (header.ContigLines.Count == 0)
            {
                if (ALLOW_MISSING_CONTIG_LINES)
                {
                    if (GeneralUtils.DEBUG_MODE_ENABLED)
                    {
                        Console.Error.WriteLine("No contig dictionary found in header, falling back to reference sequence dictionary");
                    }
                    createContigDictionary(VCFUtils.makeContigHeaderLines(RefDict, null));
                }
                else
                {
                    throw new IllegalStateException("Cannot write BCF2 file with missing contig lines");
                }
            }
            else
            {
                createContigDictionary(header.ContigLines);
            }

            // set up the map from dictionary string values -> offset
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ArrayList<String> dict = org.broadinstitute.variant.bcf2.BCF2Utils.makeDictionary(header);
            List <string> dict = BCF2Utils.makeDictionary(header);

            for (int i = 0; i < dict.Count; i++)
            {
                stringDictionaryMap[dict[i]] = i;
            }

            sampleNames = header.GenotypeSampleNames.ToArray();

            // setup the field encodings
            fieldManager.setup(header, encoder, stringDictionaryMap);

            try
            {
                // write out the header into a byte stream, get it's length, and write everything to the file
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ByteArrayOutputStream capture = new ByteArrayOutputStream();
                ByteArrayOutputStream capture = new ByteArrayOutputStream();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final OutputStreamWriter writer = new OutputStreamWriter(capture);
                OutputStreamWriter writer = new OutputStreamWriter(capture);
                this.header = VCFWriter.writeHeader(header, writer, doNotWriteGenotypes, VCFWriter.VersionLine, "BCF2 stream");
                writer.append('\0');                 // the header is null terminated by a byte
                writer.close();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] headerBytes = capture.toByteArray();
                sbyte[] headerBytes = capture.toByteArray();
                (new BCFVersion(MAJOR_VERSION, MINOR_VERSION)).write(outputStream);
                BCF2Type.INT32.write(headerBytes.Length, outputStream);
                outputStream.write(headerBytes);
            }
            catch (IOException e)
            {
                throw new Exception("BCF2 stream: Got IOException while trying to write BCF2 header", e);
            }
        }