Ejemplo n.º 1
0
        public XicUnit(XicUnit copy)
        {
            Meta = new XicMeta(copy.Meta);

            if (copy.RetentionTimes != null)
            {
                if (copy.RetentionTimes is string)
                {
                    RetentionTimes = (string)copy.RetentionTimes;
                }
                else
                {
                    ArrayList x = new ArrayList();
                    foreach (double d in (ArrayList)copy.RetentionTimes)
                    {
                        x.Add(d);
                    }

                    RetentionTimes = x;
                }
            }
            else
            {
                RetentionTimes = null;
            }

            if (copy.Intensities != null)
            {
                if (copy.Intensities is string)
                {
                    Intensities = (string)copy.Intensities;
                }
                else
                {
                    ArrayList y = new ArrayList();
                    foreach (double d in (ArrayList)copy.Intensities)
                    {
                        y.Add(d);
                    }

                    Intensities = y;
                }
            }
            else
            {
                Intensities = null;
            }
        }
Ejemplo n.º 2
0
        public static XicData ParseJSON(string jsonString)
        {
            List <JSONInputUnit> jsonIn;
            XicData data = new XicData();

            jsonIn = JsonConvert.DeserializeObject <List <JSONInputUnit> >(jsonString);
            foreach (JSONInputUnit xic in jsonIn)
            {
                XicUnit xicUnit = null;
                if (xic.HasSequence())
                {
                    Peptide p = new Peptide(xic.Sequence);
                    xic.Mz = p.GetMz(xic.Charge);
                }

                if (xic.HasMz())
                {
                    double delta;
                    switch (xic.ToleranceUnit.ToLower())
                    {
                    case "ppm":
                        delta = xic.Mz.Value * xic.Tolerance.Value * 1e-6;
                        break;

                    case "amu":
                        delta = xic.Tolerance.Value;
                        break;

                    case "mmu":
                        delta = xic.Tolerance.Value * 1e-3;
                        break;

                    case "da":
                        delta = xic.Tolerance.Value;
                        break;

                    case "":
                        delta = xic.Mz.Value * xic.Tolerance.Value * 1e-6;
                        break;

                    default:
                        delta = 10;
                        break;
                    }

                    xicUnit = new XicUnit(xic.Mz.Value - delta, xic.Mz.Value + delta, xic.RtStart,
                                          xic.RtEnd, xic.Filter);
                }
                else if (xic.HasMzRange())
                {
                    xicUnit = new XicUnit(xic.MzStart.Value, xic.MzEnd.Value, xic.RtStart, xic.RtEnd, xic.Filter);
                }

                if (xicUnit == null || !xicUnit.HasValidRanges())
                {
                    throw new RawFileParserException(
                              $"Invalid M/Z and/or retention time range:\n{JsonConvert.SerializeObject(xic, Formatting.Indented)}");
                }

                data.Content.Add(xicUnit);
            }

            return(data);
        }