Пример #1
0
        /// <summary>
        /// Create the info string; assumes that no values are null
        /// </summary>
        /// <param name="infoFields"> a map of info fields </param>
        /// <exception cref="IOException"> for writer </exception>
        private string getInfoString(IDictionary <string, string> infoFields)
        {
            if (infoFields.Count == 0)
            {
                return(VCFConstants.EMPTY_INFO_FIELD);
            }
            bool   isFirst  = true;
            string toReturn = "";

            foreach (KeyValuePair <string, string> entry in infoFields)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    toReturn += VCFConstants.INFO_FIELD_SEPARATOR;
                }

                string key = entry.Key;
                toReturn += key;

                if (!entry.Value.Equals(""))
                {
                    VCFInfoHeaderLine metaData = mHeader.getInfoHeaderLine(key);
                    if (metaData == null || metaData.CountType != VCFHeaderLineCount.INTEGER || metaData.Count != 0)
                    {
                        toReturn += "=";
                        toReturn += entry.Value;
                    }
                }
            }
            return(toReturn);
        }
Пример #2
0
        public static VCFCompoundHeaderLine GetMetaDataForField(VCFHeader header, string field)
        {
            VCFCompoundHeaderLine metaData = header.getFormatHeaderLine(field);

            if (metaData == null)
            {
                metaData = header.getInfoHeaderLine(field);
            }
            if (metaData == null)
            {
                throw new VCFParsingError("Fully decoding VariantContext requires header line for all fields, but none was found for " + field);
            }
            return(metaData);
        }
Пример #3
0
        /// <summary>
        /// parse out the info fields into a dictionary of key/values </summary>
        /// <param name="infoField"> the fields </param>
        /// <returns> a mapping of keys to objects </returns>
        private IDictionary <string, object> parseInfo(string infoField)
        {
            IDictionary <string, object> attributes = new Dictionary <string, object> ();

            if (infoField.Length == 0)
            {
                generateException("The VCF specification requires a valid info field");
            }
            if (!infoField.Equals(VCFConstants.EMPTY_INFO_FIELD))
            {
                if (infoField.IndexOf("\t") != -1 || infoField.IndexOf(" ") != -1)
                {
                    generateException("The VCF specification does not allow for whitespace in the INFO field");
                }
                string[] infoFieldArray = infoField.Split(VCFConstants.INFO_FIELD_SEPARATOR_CHAR_AS_ARRAY);
                //int infoFieldSplitSize = ParsingUtils.Split(infoField, infoFieldArray, VCFConstants.INFO_FIELD_SEPARATOR_CHAR, false);
                for (int i = 0; i < infoFieldArray.Length; i++)
                {
                    string key;
                    object value;
                    int    eqI = infoFieldArray [i].IndexOf("=");
                    if (eqI != -1)
                    {
                        key = infoFieldArray [i].Substring(0, eqI);
                        string valueString = infoFieldArray [i].Substring(eqI + 1);

                        // split on the INFO field separator
                        string[] infoValueArray = valueString.Split(VCFConstants.INFO_FIELD_ARRAY_SEPARATOR_CHAR);
                        //int infoValueSplitSize = ParsingUtils.Split(valueString, infoValueArray, VCFConstants.INFO_FIELD_ARRAY_SEPARATOR_CHAR, false);
                        if (infoValueArray.Length == 1)                          // infoValueSplitSize == 1)
                        {
                            value = infoValueArray [0];
                            VCFInfoHeaderLine headerLine = header.getInfoHeaderLine(key);
                            if (headerLine != null && headerLine.Type == VCFHeaderLineType.Flag && value.Equals("0"))
                            {
                                // deal with the case where a flag field has =0, such as DB=0, by skipping the add
                                continue;
                            }
                        }
                        else
                        {
                            //List<string> valueList = new List<string>(infoValueArray);
                            value = infoValueArray;
                        }
                    }
                    else
                    {
                        key = infoFieldArray [i];
                        VCFInfoHeaderLine headerLine = header.getInfoHeaderLine(key);
                        if (headerLine != null && headerLine.Type != VCFHeaderLineType.Flag)
                        {
                            //Note: This was originally a warning that was only thrown once
                            throw new VCFParsingError("Found info key " + key + " without a = value, but the header says the field is of type " + headerLine.Type + " but this construct is only value for FLAG type fields");
                            //Old version just set this value
                            // value = VCFConstants.MISSING_VALUE_v4;
                        }
                        else
                        {
                            value = true;
                        }
                    }
                    // this line ensures that key/value pairs that look like key=; are parsed correctly as MISSING
                    if ("".Equals(value))
                    {
                        value = VCFConstants.MISSING_VALUE_v4;
                    }
                    //TODO: We should have enough information in the header here to
                    attributes [key] = value;
                }
            }

            return(attributes);
        }