Exemplo n.º 1
0
        private Action <JsonObject, List <string[]> > GetJsonStringGenerationAction()
        {
            var actions = new List <Action <JsonObject, string[]> >();

            foreach (string key in Keys)
            {
                if (NonSaKeys.Contains(key))
                {
                    continue;
                }
                var intendedType = GetJsonType(key);

                if (intendedType.Equals(SaJsonValueType.String))
                {
                    actions.Add((jsonObject, value) => CountKeyIfAdded(jsonObject.AddStringValue(key, value[0]), key));
                }

                else if (intendedType.Equals(SaJsonValueType.Bool))
                {
                    actions.Add((jsonObject, value) => CountKeyIfAdded(jsonObject.AddBoolValue(key, CheckAndGetBoolFromString(value[0])), key));
                }

                else if (intendedType.Equals(SaJsonValueType.Number))
                {
                    actions.Add((jsonObject, value) =>
                    {
                        if (value[0] == null)
                        {
                            return;
                        }
                        var doubleValue = CheckAndGetNullableDoubleFromString(value[0]);
                        CustomAnnotationCategories keyCategory = GetCategory(key);
                        CountKeyIfAdded(keyCategory == CustomAnnotationCategories.AlleleFrequency
                            ? jsonObject.AddDoubleValue(key, doubleValue, "0.######")
                            : jsonObject.AddStringValue(key, value[0], false), key);
                    });
                }

                else if (intendedType.Equals(SaJsonValueType.StringArray))
                {
                    actions.Add((jsonObject, value) => CountKeyIfAdded(jsonObject.AddStringValues(key, value), key));
                }

                else
                {
                    throw new Exception($"Unknown data type {intendedType}");
                }
            }

            return((jsonObject, strings) =>
            {
                foreach (var(action, str) in actions.Zip(strings, (a, b) => (a, b)))
                {
                    action(jsonObject, str);
                }

                TotalItems++;
            });
        }
Exemplo n.º 2
0
 public SaJsonKeyProperties(SaJsonValueType valueType, CustomAnnotationCategories category, string description)
 {
     ValueType   = valueType;
     Category    = category;
     Description = description;
 }
Exemplo n.º 3
0
 public static SaJsonKeyAnnotation CreateFromProperties(SaJsonValueType valueType, CustomAnnotationCategories category, string description)
 {
     return(new SaJsonKeyAnnotation {
         Properties = new SaJsonKeyProperties(valueType, category, description)
     });
 }
Exemplo n.º 4
0
        public static CustomAnnotationCategories[] ParseCategories(string line, int numRequiredColumns, int numAnnotationColumns, Action <string, string>[] annotationValidators, string rowNumber)
        {
            CheckPrefix(line, "#categories", rowNumber);
            var splits = line.OptimizedSplit('\t');

            if (splits.Length != numRequiredColumns + numAnnotationColumns)
            {
                throw new UserErrorException("#categories row must have the same number of columns as the header row with column names.");
            }

            var categories = new CustomAnnotationCategories[numAnnotationColumns];

            for (var i = 0; i < numAnnotationColumns; i++)
            {
                switch (splits[i + numRequiredColumns].ToLower())
                {
                case "allelecount":
                    categories[i] = CustomAnnotationCategories.AlleleCount;
                    break;

                case "allelenumber":
                    categories[i] = CustomAnnotationCategories.AlleleNumber;
                    break;

                case "allelefrequency":
                    categories[i] = CustomAnnotationCategories.AlleleFrequency;
                    break;

                case "homozygouscount":
                    categories[i] = CustomAnnotationCategories.HomozygousCount;
                    break;

                case "prediction":
                    categories[i]           = CustomAnnotationCategories.Prediction;
                    annotationValidators[i] = AllowedValues.ValidatePredictionValue;
                    break;

                case "filter":
                    categories[i]           = CustomAnnotationCategories.Filter;
                    annotationValidators[i] = AllowedValues.ValidateFilterValue;
                    break;

                case "identifier":
                    categories[i]           = CustomAnnotationCategories.Identifier;
                    annotationValidators[i] = AllowedValues.ValidateIdentifierValue;
                    break;

                case "description":
                    categories[i]           = CustomAnnotationCategories.Description;
                    annotationValidators[i] = AllowedValues.ValidateDescriptionValue;
                    break;

                case ".":
                case "":
                    categories[i] = CustomAnnotationCategories.Unknown;
                    break;

                default:
                    throw new UserErrorException($"Invalid category value: {splits[i + numRequiredColumns]}");
                }
            }

            return(categories);
        }