// -------------------------------------------------------------------------------- // // implementation functions // // -------------------------------------------------------------------------------- //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: private final String getFilterString(final VariantContext vc) private string getFilterString(VariantContext vc) { if (vc.Filtered) { foreach (String filter in vc.Filters) { if (!mHeader.hasFilterLine(filter)) { fieldIsMissingFromHeaderError(vc, filter, "FILTER"); } } return(ParsingUtils.join(";", ParsingUtils.sortList(vc.Filters))); } else if (vc.filtersWereApplied()) { return(VCFConstants.PASSES_FILTERS_v4); } else { return(VCFConstants.UNFILTERED); } }
/// <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); } }