//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: private final void buildAlleleMap(final org.broadinstitute.variant.variantcontext.VariantContext vc)
            private void buildAlleleMap(VariantContext vc)
            {
                // these are fast path options to determine the offsets for
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nAlleles = vc.getNAlleles();
                int nAlleles = vc.NAlleles;

                @ref = vc.Reference;
                alt1 = nAlleles > 1 ? vc.getAlternateAllele(0) : null;

                if (nAlleles > 2)
                {
                    // for multi-allelics we need to clear the map, and add additional looks
                    alleleMapForTriPlus.Clear();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.broadinstitute.variant.variantcontext.Allele> alleles = vc.getAlleles();
                    IList <Allele> alleles = vc.Alleles;
                    for (int i = 2; i < alleles.Count; i++)
                    {
                        alleleMapForTriPlus[alleles[i]] = i;
                    }
                }
            }
Example #2
0
        /// <summary>
        /// add a record to the file
        /// </summary>
        /// <param name="vc">      the Variant Context object </param>
        public override void add(VariantContext vc)
        {
            if (mHeader == null)
            {
                throw new IllegalStateException("The VCF Header must be written before records can be added: " + StreamName);
            }

            if (doNotWriteGenotypes)
            {
                vc = (new VariantContextBuilder(vc)).noGenotypes().make();
            }

            try
            {
                base.add(vc);

                IDictionary <Allele, string> alleleMap = buildAlleleMap(vc);

                // CHROM
                write(vc.Chr);
                write(VCFConstants.FIELD_SEPARATOR);

                // POS
                write(Convert.ToString(vc.Start));
                write(VCFConstants.FIELD_SEPARATOR);

                // ID
                string ID = vc.ID;
                write(ID);
                write(VCFConstants.FIELD_SEPARATOR);

                // REF
                string refString = vc.Reference.DisplayString;
                write(refString);
                write(VCFConstants.FIELD_SEPARATOR);

                // ALT
                if (vc.Variant)
                {
                    Allele altAllele = vc.getAlternateAllele(0);
                    string alt       = altAllele.DisplayString;
                    write(alt);

                    for (int i = 1; i < vc.AlternateAlleles.Count; i++)
                    {
                        altAllele = vc.getAlternateAllele(i);
                        alt       = altAllele.DisplayString;
                        write(",");
                        write(alt);
                    }
                }
                else
                {
                    write(VCFConstants.EMPTY_ALTERNATE_ALLELE_FIELD);
                }
                write(VCFConstants.FIELD_SEPARATOR);

                // QUAL
                if (!vc.hasLog10PError())
                {
                    write(VCFConstants.MISSING_VALUE_v4);
                }
                else
                {
                    write(formatQualValue(vc.PhredScaledQual));
                }
                write(VCFConstants.FIELD_SEPARATOR);

                // FILTER
                string filters = getFilterString(vc);
                write(filters);
                write(VCFConstants.FIELD_SEPARATOR);

                // INFO
                IDictionary <string, string> infoFields = new SortedDictionary <string, string>();
                foreach (KeyValuePair <string, object> field in vc.Attributes)
                {
                    string key = field.Key;

                    if (!mHeader.hasInfoLine(key))
                    {
                        fieldIsMissingFromHeaderError(vc, key, "INFO");
                    }

                    string outputValue = formatVCFField(field.Value);
                    if (outputValue != null)
                    {
                        infoFields[key] = outputValue;
                    }
                }
                writeInfoString(infoFields);

                // FORMAT
                GenotypesContext gc = vc.Genotypes;
                if (gc.LazyWithData && ((LazyGenotypesContext)gc).UnparsedGenotypeData is string)
                {
                    write(VCFConstants.FIELD_SEPARATOR);
                    write(((LazyGenotypesContext)gc).UnparsedGenotypeData.ToString());
                }
                else
                {
                    IList <string> genotypeAttributeKeys = calcVCFGenotypeKeys(vc, mHeader);
                    if (genotypeAttributeKeys.Count > 0)
                    {
                        foreach (String format in genotypeAttributeKeys)
                        {
                            if (!mHeader.hasFormatLine(format))
                            {
                                fieldIsMissingFromHeaderError(vc, format, "FORMAT");
                            }
                        }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String genotypeFormatString = org.broad.tribble.util.ParsingUtils.join(VCFConstants.GENOTYPE_FIELD_SEPARATOR, genotypeAttributeKeys);
                        string genotypeFormatString = ParsingUtils.join(VCFConstants.GENOTYPE_FIELD_SEPARATOR, genotypeAttributeKeys);

                        write(VCFConstants.FIELD_SEPARATOR);
                        write(genotypeFormatString);

                        addGenotypeData(vc, alleleMap, genotypeAttributeKeys);
                    }
                }

                write("\n");
                // note that we cannot call flush here if we want block gzipping to work properly
                // calling flush results in all gzipped blocks for each variant
                flushBuffer();
            }
            catch (IOException e)
            {
                throw new Exception("Unable to write the VCF object to " + StreamName, e);
            }
        }
Example #3
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: private final void buildAlleleMap(final org.broadinstitute.variant.variantcontext.VariantContext vc)
			private void buildAlleleMap(VariantContext vc)
			{
				// these are fast path options to determine the offsets for
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int nAlleles = vc.getNAlleles();
				int nAlleles = vc.NAlleles;
				@ref = vc.Reference;
				alt1 = nAlleles > 1 ? vc.getAlternateAllele(0) : null;

				if (nAlleles > 2)
				{
					// for multi-allelics we need to clear the map, and add additional looks
					alleleMapForTriPlus.Clear();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.broadinstitute.variant.variantcontext.Allele> alleles = vc.getAlleles();
					IList<Allele> alleles = vc.Alleles;
					for (int i = 2; i < alleles.Count; i++)
					{
						alleleMapForTriPlus[alleles[i]] = i;
					}
				}
			}