//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void addGenotype(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void addGenotype(BCF2Encoder encoder, VariantContext vc, Genotype g) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int samplePloidy = g.getPloidy(); int samplePloidy = g.Ploidy; for (int i = 0; i < nValuesPerGenotype; i++) { if (i < samplePloidy) { // we encode the actual allele //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.broadinstitute.variant.variantcontext.Allele a = g.getAllele(i); Allele a = g.getAllele(i); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int offset = getAlleleOffset(a); int offset = getAlleleOffset(a); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int encoded = ((offset+1) << 1) | (g.isPhased() ? 0x01 : 0x00); int encoded = ((offset + 1) << 1) | (g.Phased ? 0x01 : 0x00); encoder.encodeRawBytes(encoded, encodingType); } else { // we need to pad with missing as we have ploidy < max for this sample encoder.encodeRawBytes(encodingType.MissingBytes, encodingType); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void encodeValue(final BCF2Encoder encoder, final Object value, final org.broadinstitute.variant.bcf2.BCF2Type type, final int minValues) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void encodeValue(BCF2Encoder encoder, object value, BCF2Type type, int minValues) { int count = 0; // TODO -- can be restructured to avoid toList operation if (isAtomic) { // fast path for fields with 1 fixed float value if (value != null) { encoder.encodeRawFloat((double?)value); count++; } } else { // handle generic case //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<Double> doubles = toList(Double.class, value); IList <double?> doubles = toList(typeof(double?), value); foreach (Double d in doubles) { if (d != null) // necessary because .,. => [null, null] in VC { encoder.encodeRawFloat(d); count++; } } } for (; count < minValues; count++) { encoder.encodeRawMissingValue(type); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Requires({"encodingType != null", "nValuesPerGenotype >= 0"}) public void addGenotype(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) 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 virtual void addGenotype(BCF2Encoder encoder, VariantContext vc, Genotype g) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Object fieldValue = g.getExtendedAttribute(getField(), null); object fieldValue = g.getExtendedAttribute(Field, null); FieldEncoder.encodeValue(encoder, fieldValue, encodingType, nValuesPerGenotype); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void encodeValue(final BCF2Encoder encoder, final Object value, final org.broadinstitute.variant.bcf2.BCF2Type type, final int minValues) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void encodeValue(BCF2Encoder encoder, object value, BCF2Type type, int minValues) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String s = javaStringToBCF2String(value); string s = javaStringToBCF2String(value); encoder.encodeRawString(s, Math.Max(s.Length, minValues)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void addGenotype(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void addGenotype(BCF2Encoder encoder, VariantContext vc, Genotype g) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String fieldValue = g.getFilters(); string fieldValue = g.Filters; FieldEncoder.encodeValue(encoder, fieldValue, encodingType, nValuesPerGenotype); }
//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) { if (vc.NAlleles > BCF2Utils.MAX_ALLELES_IN_GENOTYPES) { throw new IllegalStateException("Current BCF2 encoder cannot handle sites " + "with > " + BCF2Utils.MAX_ALLELES_IN_GENOTYPES + " alleles, but you have " + vc.NAlleles + " at " + vc.Chr + ":" + vc.Start); } encodingType = BCF2Type.INT8; buildAlleleMap(vc); nValuesPerGenotype = vc.getMaxPloidy(2); base.start(encoder, vc); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void encodeValue(final BCF2Encoder encoder, final Object value, final org.broadinstitute.variant.bcf2.BCF2Type type, final int minValues) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void encodeValue(BCF2Encoder encoder, object value, BCF2Type type, int minValues) { int count = 0; if (value != null) { encoder.encodeRawInt((int?)value, type); count++; } for (; count < minValues; count++) { encoder.encodeRawMissingValue(type); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void encodeValue(final BCF2Encoder encoder, final Object value, final org.broadinstitute.variant.bcf2.BCF2Type type, final int minValues) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void encodeValue(BCF2Encoder encoder, object value, BCF2Type type, int minValues) { int count = 0; foreach (Integer i in toList(typeof(Integer), value)) { if (i != null) // necessary because .,. => [null, null] in VC { encoder.encodeRawInt(i, type); count++; } } for (; count < minValues; count++) { encoder.encodeRawMissingValue(type); } }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: private BCF2FieldEncoder createFieldEncoder(final VCFCompoundHeaderLine line, final BCF2Encoder encoder, final java.util.Map<String, Integer> dict, final boolean createGenotypesEncoders) private BCF2FieldEncoder createFieldEncoder(VCFCompoundHeaderLine line, BCF2Encoder encoder, IDictionary <string, int?> dict, bool createGenotypesEncoders) { if (createGenotypesEncoders && intGenotypeFieldAccessors.getAccessor(line.ID) != null) { if (GeneralUtils.DEBUG_MODE_ENABLED && line.Type != VCFHeaderLineType.Integer) { Console.Error.WriteLine("Warning: field " + line.ID + " expected to encode an integer but saw " + line.Type + " for record " + line); } return(new BCF2FieldEncoder.IntArray(line, dict)); } else if (createGenotypesEncoders && line.ID.Equals(VCFConstants.GENOTYPE_KEY)) { return(new BCF2FieldEncoder.GenericInts(line, dict)); } else { switch (line.Type) { case char?: case string: return(new BCF2FieldEncoder.StringOrCharacter(line, dict)); case Flag: return(new BCF2FieldEncoder.Flag(line, dict)); case float?: return(new BCF2FieldEncoder.Float(line, dict)); case int?: if (line.FixedCount && line.Count == 1) { return(new BCF2FieldEncoder.AtomicInt(line, dict)); } else { return(new BCF2FieldEncoder.GenericInts(line, dict)); } default: throw new System.ArgumentException("Unexpected type for field " + line.ID); } } }
//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: @Override @Requires({"encodingType != null", "nValuesPerGenotype >= 0 || ! getFieldEncoder().hasConstantNumElements()"}) @Ensures("nValuesPerGenotype >= 0") public void start(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc) 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 override void start(BCF2Encoder encoder, VariantContext vc) { // writes the key information base.start(encoder, vc); // only update if we need to if (!FieldEncoder.hasConstantNumElements()) { if (FieldEncoder.hasContextDeterminedNumElements()) // we are cheap -- just depends on genotype of allele counts { nValuesPerGenotype = FieldEncoder.numElements(vc); } else // we have to go fishing through the values themselves (expensive) { nValuesPerGenotype = computeMaxSizeOfGenotypeFieldFromValues(vc); } } encoder.encodeType(nValuesPerGenotype, encodingType); }
//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); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void site(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 site(BCF2Encoder encoder, VariantContext vc) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Object rawValue = vc.getAttribute(getField(), null); object rawValue = vc.getAttribute(Field, null); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.broadinstitute.variant.bcf2.BCF2Type type = getFieldEncoder().getType(rawValue); BCF2Type type = FieldEncoder.getType(rawValue); if (rawValue == null) { // the value is missing, just write in null encoder.encodeType(0, type); } else { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int valueCount = getFieldEncoder().numElements(vc, rawValue); int valueCount = FieldEncoder.numElements(vc, rawValue); encoder.encodeType(valueCount, type); FieldEncoder.encodeValue(encoder, rawValue, type, valueCount); } }
/// <summary> /// Setup the FieldWriters appropriate to each INFO and FORMAT in the VCF header /// /// Must be called before any of the getter methods will work /// </summary> /// <param name="header"> a VCFHeader containing description for every INFO and FORMAT field we'll attempt to write out to BCF </param> /// <param name="encoder"> the encoder we are going to use to write out the BCF2 data </param> /// <param name="stringDictionary"> a map from VCFHeader strings to their offsets for encoding </param> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: public void setup(final VCFHeader header, final BCF2Encoder encoder, final java.util.Map<String, Integer> stringDictionary) public virtual void setup(VCFHeader header, BCF2Encoder encoder, IDictionary <string, int?> stringDictionary) { foreach (VCFInfoHeaderLine line in header.InfoHeaderLines) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String field = line.getID(); string field = line.ID; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final BCF2FieldWriter.SiteWriter writer = createInfoWriter(header, line, encoder, stringDictionary); BCF2FieldWriter.SiteWriter writer = createInfoWriter(header, line, encoder, stringDictionary); add(siteWriters, field, writer); } foreach (VCFFormatHeaderLine line in header.FormatHeaderLines) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String field = line.getID(); string field = line.ID; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final BCF2FieldWriter.GenotypesWriter writer = createGenotypesWriter(header, line, encoder, stringDictionary); BCF2FieldWriter.GenotypesWriter writer = createGenotypesWriter(header, line, encoder, stringDictionary); add(genotypesWriters, field, writer); } }
// ----------------------------------------------------------------- // // Master routine to look at the header, a specific line, and // build an appropriate Genotypes for that header element // // ----------------------------------------------------------------- //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: private BCF2FieldWriter.GenotypesWriter createGenotypesWriter(final VCFHeader header, final VCFFormatHeaderLine line, final BCF2Encoder encoder, final java.util.Map<String, Integer> dict) private BCF2FieldWriter.GenotypesWriter createGenotypesWriter(VCFHeader header, VCFFormatHeaderLine line, BCF2Encoder encoder, IDictionary <string, int?> dict) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String field = line.getID(); string field = line.ID; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final BCF2FieldEncoder fieldEncoder = createFieldEncoder(line, encoder, dict, true); BCF2FieldEncoder fieldEncoder = createFieldEncoder(line, encoder, dict, true); if (field.Equals(VCFConstants.GENOTYPE_KEY)) { return(new BCF2FieldWriter.GTWriter(header, fieldEncoder)); } else if (line.ID.Equals(VCFConstants.GENOTYPE_FILTER_KEY)) { return(new BCF2FieldWriter.FTGenotypesWriter(header, fieldEncoder)); } else if (intGenotypeFieldAccessors.getAccessor(field) != null) { return(new BCF2FieldWriter.IGFGenotypesWriter(header, fieldEncoder, intGenotypeFieldAccessors.getAccessor(field))); } else if (line.Type == VCFHeaderLineType.Integer) { return(new BCF2FieldWriter.IntegerTypeGenotypesWriter(header, fieldEncoder)); } else { return(new BCF2FieldWriter.StaticallyTypeGenotypesWriter(header, fieldEncoder)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Requires("encoder != null") public final void writeFieldKey(final BCF2Encoder encoder) 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 writeFieldKey(BCF2Encoder encoder) { encoder.encodeTypedInt(dictionaryOffset, dictionaryOffsetType); }
// ----------------------------------------------------------------- // // Master routine to look at the header, a specific line, and // build an appropriate SiteWriter for that header element // // ----------------------------------------------------------------- //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: private BCF2FieldWriter.SiteWriter createInfoWriter(final VCFHeader header, final VCFInfoHeaderLine line, final BCF2Encoder encoder, final java.util.Map<String, Integer> dict) private BCF2FieldWriter.SiteWriter createInfoWriter(VCFHeader header, VCFInfoHeaderLine line, BCF2Encoder encoder, IDictionary <string, int?> dict) { return(new BCF2FieldWriter.GenericSiteWriter(header, createFieldEncoder(line, encoder, dict, false))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Override @Requires({"minValues <= 1", "value != null", "value instanceof Boolean", "((Boolean)value) == true"}) public void encodeValue(final BCF2Encoder encoder, final Object value, final org.broadinstitute.variant.bcf2.BCF2Type type, final int minValues) 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 override void encodeValue(BCF2Encoder encoder, object value, BCF2Type type, int minValues) { encoder.encodeRawBytes(1, StaticType); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void done(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 virtual void done(BCF2Encoder encoder, VariantContext vc) // TODO -- overload done so that we null out values and test for correctness { }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Requires("vc != null") public void start(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc) 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 virtual void start(BCF2Encoder encoder, VariantContext vc) { fieldEncoder.writeFieldKey(encoder); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public abstract void site(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 abstract void site(BCF2Encoder encoder, VariantContext vc);
// ---------------------------------------------------------------------- // // methods to encode values, including the key abstract method // // ---------------------------------------------------------------------- /// <summary> /// Key abstract method that should encode a value of the given type into the encoder. /// /// Value will be of a type appropriate to the underlying encoder. If the genotype field is represented as /// an int[], this will be value, and the encoder needs to handle encoding all of the values in the int[]. /// /// The argument should be used, not the getType() method in the superclass as an outer loop might have /// decided a more general type (int16) to use, even through this encoder could have been done with int8. /// /// If minValues > 0, then encodeValue must write in at least minValues items from value. If value is atomic, /// this means that minValues - 1 MISSING values should be added to the encoder. If minValues is a collection /// type (int[]) then minValues - values.length should be added. This argument is intended to handle padding /// of values in genotype fields. /// </summary> /// <param name="encoder"> </param> /// <param name="value"> </param> /// <param name="type"> </param> /// <param name="minValues"> </param> /// <exception cref="IOException"> </exception> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Requires({"encoder != null", "isDynamicallyTyped() || type == getStaticType()", "minValues >= 0"}) public abstract void encodeValue(final BCF2Encoder encoder, final Object value, final org.broadinstitute.variant.bcf2.BCF2Type type, final int minValues) 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 abstract void encodeValue(BCF2Encoder encoder, object value, BCF2Type type, int minValues);
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void addGenotype(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void addGenotype(BCF2Encoder encoder, VariantContext vc, Genotype g) { FieldEncoder.encodeValue(encoder, ige.getValues(g), encodingType, nValuesPerGenotype); }