/// <summary> /// Recode the incoming object to a String, compacting it into a /// BCF2 string if the value is a list. /// </summary> /// <param name="value"> a String or List<String> to encode, or null </param> /// <returns> a non-null string to encode </returns> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Ensures("result != null") private String javaStringToBCF2String(final Object value) //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: private string javaStringToBCF2String(object value) { if (value == null) { return(""); } else if (value is IList) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<String> l = (java.util.List<String>)value; IList <string> l = (IList <string>)value; if (l.Count == 0) { return(""); } else { return(BCF2Utils.collapseStringList(l)); } } else { return((string)value); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Requires("! strings.isEmpty()") @Ensures("result.isIntegerType()") private final org.broadinstitute.variant.bcf2.BCF2Type encodeStringsByRef(final Collection<String> strings) throws IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: private BCF2Type encodeStringsByRef(ICollection <string> strings) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final List<Integer> offsets = new ArrayList<Integer>(strings.size()); IList <int?> offsets = new List <int?>(strings.Count); // iterate over strings until we find one that needs 16 bits, and break foreach (String string in strings) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Integer got = stringDictionaryMap.get(string); int?got = stringDictionaryMap[string]; if (got == null) { throw new IllegalStateException("Format error: could not find string " + string + " in header as required by BCF"); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int offset = got; int offset = got; offsets.Add(offset); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.broadinstitute.variant.bcf2.BCF2Type type = org.broadinstitute.variant.bcf2.BCF2Utils.determineIntegerType(offsets); BCF2Type type = BCF2Utils.determineIntegerType(offsets); encoder.encodeTyped(offsets, type); return(type); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Ensures("encodeStream.size() > old(encodeStream.size())") public final void encodeTypedInt(final int v) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public void encodeTypedInt(int v) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.broadinstitute.variant.bcf2.BCF2Type type = org.broadinstitute.variant.bcf2.BCF2Utils.determineIntegerType(v); BCF2Type type = BCF2Utils.determineIntegerType(v); encodeTypedInt(v, type); }
/// <summary> /// Can we safely write on the raw (undecoded) genotypes of an input VC? /// /// The cache depends on the undecoded lazy data header == lastVCFHeaderOfUnparsedGenotypes, in /// which case we return the previous result. If it's not cached, we use the BCF2Util to /// compare the VC header with our header (expensive) and cache it. /// </summary> /// <param name="lazyData"> /// @return </param> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: private boolean canSafelyWriteRawGenotypesBytes(final org.broadinstitute.variant.bcf2.BCF2Codec.LazyData lazyData) private bool canSafelyWriteRawGenotypesBytes(BCF2Codec.LazyData lazyData) { if (lazyData.header != lastVCFHeaderOfUnparsedGenotypes) { // result is already cached canPassOnUnparsedGenotypeDataForLastVCFHeader = BCF2Utils.headerLinesAreOrderedConsistently(this.header, lazyData.header); lastVCFHeaderOfUnparsedGenotypes = lazyData.header; } return(canPassOnUnparsedGenotypeDataForLastVCFHeader); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Ensures("encodeStream.size() > old(encodeStream.size())") public final void encodeTyped(List<? extends Object> v, final org.broadinstitute.variant.bcf2.BCF2Type type) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public void encodeTyped <T1>(IList <T1> v, BCF2Type type) where T1 : Object { if (type == BCF2Type.CHAR && v.Count != 0) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String s = org.broadinstitute.variant.bcf2.BCF2Utils.collapseStringList((List<String>) v); string s = BCF2Utils.collapseStringList((IList <string>)v); v = stringToBytes(s); } encodeType(v.Count, type); encodeRawValues(v, type); }
// ---------------------------------------------------------------------- // // Constructor // // ---------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Requires({"headerLine != null", "dict != null"}) private BCF2FieldEncoder(final Bio.VCF.VCFCompoundHeaderLine headerLine, final java.util.Map<String, Integer> dict, final org.broadinstitute.variant.bcf2.BCF2Type staticType) //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: private BCF2FieldEncoder(VCFCompoundHeaderLine headerLine, IDictionary <string, int?> dict, BCF2Type staticType) { this.headerLine = headerLine; this.staticType = staticType; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Integer offset = dict.get(getField()); int?offset = dict[Field]; if (offset == null) { throw new IllegalStateException("Format error: could not find string " + Field + " in header as required by BCF"); } this.dictionaryOffset = offset; dictionaryOffsetType = BCF2Utils.determineIntegerType(offset); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Requires("size >= 0") @Ensures("encodeStream.size() > old(encodeStream.size())") public final void encodeType(final int size, final org.broadinstitute.variant.bcf2.BCF2Type type) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public void encodeType(int size, BCF2Type type) { if (size <= BCF2Utils.MAX_INLINE_ELEMENTS) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int typeByte = org.broadinstitute.variant.bcf2.BCF2Utils.encodeTypeDescriptor(size, type); int typeByte = BCF2Utils.encodeTypeDescriptor(size, type); encodeStream.write(typeByte); } else { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int typeByte = org.broadinstitute.variant.bcf2.BCF2Utils.encodeTypeDescriptor(org.broadinstitute.variant.bcf2.BCF2Utils.OVERFLOW_ELEMENT_MARKER, type); int typeByte = BCF2Utils.encodeTypeDescriptor(BCF2Utils.OVERFLOW_ELEMENT_MARKER, type); encodeStream.write(typeByte); // write in the overflow size encodeTypedInt(size); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void start(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void start(BCF2Encoder encoder, VariantContext vc) { // the only value that is dynamic are integers //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<Integer> values = new java.util.ArrayList<Integer>(vc.getNSamples()); IList <int?> values = new List <int?>(vc.NSamples); foreach (Genotype g in vc.Genotypes) { foreach (Object i in BCF2Utils.toList(g.getExtendedAttribute(Field, null))) { if (i != null) // we know they are all integers { values.Add((int?)i); } } } encodingType = BCF2Utils.determineIntegerType(values); base.start(encoder, vc); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Requires("arg != null") private final org.broadinstitute.variant.bcf2.BCF2Type determineBCFType(final Object arg) //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: private BCF2Type determineBCFType(object arg) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Object toType = arg instanceof List ? ((List)arg).get(0) : arg; object toType = arg is IList ? ((IList)arg)[0] : arg; if (toType is int?) { return(BCF2Utils.determineIntegerType((int?)toType)); } else if (toType is string) { return(BCF2Type.CHAR); } else if (toType is double?) { return(BCF2Type.FLOAT); } else { throw new System.ArgumentException("No native encoding for Object of type " + arg.GetType().Name); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void start(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void start(BCF2Encoder encoder, VariantContext vc) { // TODO // TODO this piece of code consumes like 10% of the runtime alone because fo the vc.getGenotypes() iteration // TODO encodingType = BCF2Type.INT8; foreach (Genotype g in vc.Genotypes) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] pls = ige.getValues(g); int[] pls = ige.getValues(g); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.broadinstitute.variant.bcf2.BCF2Type plsType = getFieldEncoder().getType(pls); BCF2Type plsType = FieldEncoder.getType(pls); encodingType = BCF2Utils.maxIntegerType(encodingType, plsType); if (encodingType == BCF2Type.INT32) { break; // stop early } } base.start(encoder, vc); }
// -------------------------------------------------------------------------------- // // 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); } }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: public org.broadinstitute.variant.bcf2.BCF2Type getDynamicType(final Object value) public override BCF2Type getDynamicType(object value) { return(value == null ? BCF2Type.INT8 : BCF2Utils.determineIntegerType(toList(typeof(int?), value))); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: public org.broadinstitute.variant.bcf2.BCF2Type getDynamicType(final Object value) public override BCF2Type getDynamicType(object value) { return(value == null ? BCF2Type.INT8 : BCF2Utils.determineIntegerType((int[])value)); }