コード例 #1
0
//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);
                }
            }
コード例 #2
0
ファイル: BCF2Writer.cs プロジェクト: smith-chem-wisc/Bio.VCF
        // --------------------------------------------------------------------------------
        //
        // implicit block
        //
        // The first four records of BCF are inline untype encoded data of:
        //
        // 4 byte integer chrom offset
        // 4 byte integer start
        // 4 byte integer ref length
        // 4 byte float qual
        //
        // --------------------------------------------------------------------------------
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private byte[] buildSitesData(VariantContext vc) throws IOException
        private sbyte[] buildSitesData(VariantContext vc)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int contigIndex = contigDictionary.get(vc.getChr());
            int contigIndex = contigDictionary[vc.Chr];

            if (contigIndex == -1)
            {
                throw new IllegalStateException(string.Format("Contig {0} not found in sequence dictionary from reference", vc.Chr));
            }

            // note use of encodeRawValue to not insert the typing byte
            encoder.encodeRawValue(contigIndex, BCF2Type.INT32);

            // pos.  GATK is 1 based, BCF2 is 0 based
            encoder.encodeRawValue(vc.Start - 1, BCF2Type.INT32);

            // ref length.  GATK is closed, but BCF2 is open so the ref length is GATK end - GATK start + 1
            // for example, a SNP is in GATK at 1:10-10, which has ref length 10 - 10 + 1 = 1
            encoder.encodeRawValue(vc.End - vc.Start + 1, BCF2Type.INT32);

            // qual
            if (vc.hasLog10PError())
            {
                encoder.encodeRawFloat((float)vc.PhredScaledQual);
            }
            else
            {
                encoder.encodeRawMissingValue(BCF2Type.FLOAT);
            }

            // info fields
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nAlleles = vc.getNAlleles();
            int nAlleles = vc.NAlleles;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nInfo = vc.getAttributes().size();
            int nInfo = vc.Attributes.Count;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nGenotypeFormatFields = getNGenotypeFormatFields(vc);
            int nGenotypeFormatFields = getNGenotypeFormatFields(vc);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nSamples = header.getNGenotypeSamples();
            int nSamples = header.NGenotypeSamples;

            encoder.encodeRawInt((nAlleles << 16) | (nInfo & 0x0000FFFF), BCF2Type.INT32);
            encoder.encodeRawInt((nGenotypeFormatFields << 24) | (nSamples & 0x00FFFFF), BCF2Type.INT32);

            buildID(vc);
            buildAlleles(vc);
            buildFilter(vc);
            buildInfo(vc);

            return(encoder.RecordBytes);
        }