Пример #1
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: public static VCFHeader writeHeader(VCFHeader header, final Writer writer, final boolean doNotWriteGenotypes, final String versionLine, final String streamNameForError)
        public static VCFHeader writeHeader(VCFHeader header, Writer writer, bool doNotWriteGenotypes, string versionLine, string streamNameForError)
        {
            header = doNotWriteGenotypes ? new VCFHeader(header.MetaDataInSortedOrder) : header;

            try
            {
                // the file format field needs to be written first
                writer.write(versionLine + "\n");

                foreach (VCFHeaderLine line in header.MetaDataInSortedOrder)
                {
                    if (VCFHeaderVersion.isFormatString(line.Key))
                    {
                        continue;
                    }

                    writer.write(VCFHeader.METADATA_INDICATOR);
                    writer.write(line.ToString());
                    writer.write("\n");
                }

                // write out the column line
                writer.write(VCFHeader.HEADER_INDICATOR);
                bool isFirst = true;
                foreach (string field in VCFHeader.HEADER_FIELDS)
                {
                    if (isFirst)
                    {
                        isFirst = false;                         // don't write out a field separator
                    }
                    else
                    {
                        writer.write(VCFConstants.FIELD_SEPARATOR);
                    }
                    writer.write(field.ToString());
                }

                if (header.hasGenotypingData())
                {
                    writer.write(VCFConstants.FIELD_SEPARATOR);
                    writer.write("FORMAT");
                    foreach (string sample in header.GenotypeSampleNames)
                    {
                        writer.write(VCFConstants.FIELD_SEPARATOR);
                        writer.write(sample);
                    }
                }

                writer.write("\n");
                writer.flush();                 // necessary so that writing to an output stream will work
            }
            catch (IOException e)
            {
                throw new Exception("IOException writing the VCF header to " + streamNameForError, e);
            }

            return(header);
        }
Пример #2
0
		/// <summary>
		/// Determine which genotype fields are in use in the genotypes in VC </summary>
		/// <param name="vc"> </param>
		/// <returns> an ordered list of genotype fields in use in VC.  If vc has genotypes this will always include GT first </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: public static List<String> calcVCFGenotypeKeys(final VariantContext vc, final VCFHeader header)
		public static IList<string> calcVCFGenotypeKeys(VariantContext vc, VCFHeader header)
		{
			Set<string> keys = new HashSet<string>();

			bool sawGoodGT = false;
			bool sawGoodQual = false;
			bool sawGenotypeFilter = false;
			bool sawDP = false;
			bool sawAD = false;
			bool sawPL = false;
			foreach (Genotype g in vc.Genotypes)
			{
				keys.addAll(g.ExtendedAttributes.Keys);
				if (g.Available)
				{
					sawGoodGT = true;
				}
				if (g.hasGQ())
				{
					sawGoodQual = true;
				}
				if (g.hasDP())
				{
					sawDP = true;
				}
				if (g.hasAD())
				{
					sawAD = true;
				}
				if (g.hasPL())
				{
					sawPL = true;
				}
				if (g.Filtered)
				{
					sawGenotypeFilter = true;
				}
			}

			if (sawGoodQual)
			{
				keys.add(VCFConstants.GENOTYPE_QUALITY_KEY);
			}
			if (sawDP)
			{
				keys.add(VCFConstants.DEPTH_KEY);
			}
			if (sawAD)
			{
				keys.add(VCFConstants.GENOTYPE_ALLELE_DEPTHS);
			}
			if (sawPL)
			{
				keys.add(VCFConstants.GENOTYPE_PL_KEY);
			}
			if (sawGenotypeFilter)
			{
				keys.add(VCFConstants.GENOTYPE_FILTER_KEY);
			}

			IList<string> sortedList = ParsingUtils.sortList(new List<string>(keys));

			// make sure the GT is first
			if (sawGoodGT)
			{
				IList<string> newList = new List<string>(sortedList.Count + 1);
				newList.Add(VCFConstants.GENOTYPE_KEY);
				newList.AddRange(sortedList);
				sortedList = newList;
			}

			if (sortedList.Count == 0 && header.hasGenotypingData())
			{
				// this needs to be done in case all samples are no-calls
				return Collections.singletonList(VCFConstants.GENOTYPE_KEY);
			}
			else
			{
				return sortedList;
			}
		}
Пример #3
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: public static VCFHeader writeHeader(VCFHeader header, final Writer writer, final boolean doNotWriteGenotypes, final String versionLine, final String streamNameForError)
		public static VCFHeader writeHeader(VCFHeader header, Writer writer, bool doNotWriteGenotypes, string versionLine, string streamNameForError)
		{
			header = doNotWriteGenotypes ? new VCFHeader(header.MetaDataInSortedOrder) : header;

			try
			{
				// the file format field needs to be written first
				writer.write(versionLine + "\n");

				foreach (VCFHeaderLine line in header.MetaDataInSortedOrder)
				{
					if (VCFHeaderVersion.isFormatString(line.Key))
					{
						continue;
					}

					writer.write(VCFHeader.METADATA_INDICATOR);
					writer.write(line.ToString());
					writer.write("\n");
				}

				// write out the column line
				writer.write(VCFHeader.HEADER_INDICATOR);
				bool isFirst = true;
				foreach (string field in VCFHeader.HEADER_FIELDS)
				{
					if (isFirst)
					{
						isFirst = false; // don't write out a field separator
					}
					else
					{
						writer.write(VCFConstants.FIELD_SEPARATOR);
					}
					writer.write(field.ToString());
				}

				if (header.hasGenotypingData())
				{
					writer.write(VCFConstants.FIELD_SEPARATOR);
					writer.write("FORMAT");
					foreach (string sample in header.GenotypeSampleNames)
					{
						writer.write(VCFConstants.FIELD_SEPARATOR);
						writer.write(sample);
					}
				}

				writer.write("\n");
				writer.flush(); // necessary so that writing to an output stream will work
			}
			catch (IOException e)
			{
				throw new Exception("IOException writing the VCF header to " + streamNameForError, e);
			}

			return header;
		}
Пример #4
0
        /// <summary>
        /// Determine which genotype fields are in use in the genotypes in VC </summary>
        /// <param name="vc"> </param>
        /// <returns> an ordered list of genotype fields in use in VC.  If vc has genotypes this will always include GT first </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: public static List<String> calcVCFGenotypeKeys(final VariantContext vc, final VCFHeader header)
        public static IList <string> calcVCFGenotypeKeys(VariantContext vc, VCFHeader header)
        {
            Set <string> keys = new HashSet <string>();

            bool sawGoodGT         = false;
            bool sawGoodQual       = false;
            bool sawGenotypeFilter = false;
            bool sawDP             = false;
            bool sawAD             = false;
            bool sawPL             = false;

            foreach (Genotype g in vc.Genotypes)
            {
                keys.addAll(g.ExtendedAttributes.Keys);
                if (g.Available)
                {
                    sawGoodGT = true;
                }
                if (g.hasGQ())
                {
                    sawGoodQual = true;
                }
                if (g.hasDP())
                {
                    sawDP = true;
                }
                if (g.hasAD())
                {
                    sawAD = true;
                }
                if (g.hasPL())
                {
                    sawPL = true;
                }
                if (g.Filtered)
                {
                    sawGenotypeFilter = true;
                }
            }

            if (sawGoodQual)
            {
                keys.add(VCFConstants.GENOTYPE_QUALITY_KEY);
            }
            if (sawDP)
            {
                keys.add(VCFConstants.DEPTH_KEY);
            }
            if (sawAD)
            {
                keys.add(VCFConstants.GENOTYPE_ALLELE_DEPTHS);
            }
            if (sawPL)
            {
                keys.add(VCFConstants.GENOTYPE_PL_KEY);
            }
            if (sawGenotypeFilter)
            {
                keys.add(VCFConstants.GENOTYPE_FILTER_KEY);
            }

            IList <string> sortedList = ParsingUtils.sortList(new List <string>(keys));

            // make sure the GT is first
            if (sawGoodGT)
            {
                IList <string> newList = new List <string>(sortedList.Count + 1);
                newList.Add(VCFConstants.GENOTYPE_KEY);
                newList.AddRange(sortedList);
                sortedList = newList;
            }

            if (sortedList.Count == 0 && header.hasGenotypingData())
            {
                // this needs to be done in case all samples are no-calls
                return(Collections.singletonList(VCFConstants.GENOTYPE_KEY));
            }
            else
            {
                return(sortedList);
            }
        }
Пример #5
0
        void writeHeader(VCFHeader header)
		{
          
			header = doNotWriteGenotypes ? new VCFHeader(header.MetaDataInSortedOrder) : header;
			try
			{
				// the file format field needs to be written first
				writer.Write(VERSION_LINE + "\n");

				foreach (VCFHeaderLine line in header.MetaDataInSortedOrder)
				{
					if (VCFHeaderVersion.IsFormatString(line.Key))
					{
						continue;
					}

					writer.Write(VCFHeader.METADATA_INDICATOR);
					writer.Write(line.ToString());
					writer.Write("\n");
				}

				// write out the column line
				writer.Write(VCFHeader.HEADER_INDICATOR);
				bool isFirst = true;
				foreach (string field in VCFHeader.HEADER_FIELDS)
				{
					if (isFirst)
					{
						isFirst = false; // don't write out a field separator
					}
					else
					{
						writer.Write(VCFConstants.FIELD_SEPARATOR);
					}
					writer.Write(field.ToString());
				}
				if (header.hasGenotypingData())
				{
					writer.Write(VCFConstants.FIELD_SEPARATOR);
					writer.Write("FORMAT");
					foreach (string sample in header.GenotypeSampleNames)
					{
						writer.Write(VCFConstants.FIELD_SEPARATOR);
						writer.Write(sample);
					}
				}
				writer.Write("\n");
	        }
			catch (IOException e)
			{
				throw new Exception("IOException writing the VCF header." , e);
			}

			
		}