Ejemplo n.º 1
0
        public bool addModification(Modification modification)
        {
            if (modification == null){
                return false;
            }

            SplitList<Modification> modList = Modifications;
            if (modList == null){
                modList = new SplitList<Modification>(MZTabConstants.COMMA);
                Modifications = modList;
            }

            modList.Add(modification);
            return true;
        }
Ejemplo n.º 2
0
        private static Modification ParseModification(Section section, string target)
        {
            target = ParseString(target);
            // no modification
            if (target.Equals("0")){
                return Modification.CreateNoModification(section);
            }
            target = translateMinusToUnicode(target);
            if (target == null){
                return null;
            }

            target = translateTabToComma(target);
            string[] items = target.Split("\\-".ToCharArray());
            string modLabel;
            string positionLabel;
            if (items.Length > 2){
                // error
                return null;
            }
            if (items.Length == 2){
                positionLabel = items[0];
                modLabel = items[1];
            }
            else{
                positionLabel = null;
                modLabel = items[0];
            }

            Modification modification = null;

            modLabel = translateUnicodeToMinus(modLabel);
            Regex regex = new Regex("(MOD|UNIMOD|CHEMMOD|SUBST):([^\\|]+)(\\|\\[([^,]+)?,([^,]+)?,([^,]+),([^,]*)\\])?");

            if (regex.IsMatch(modLabel)){
                Modification.ModificationType type = Modification.FindType(regex.Match(target).Groups[1].Value);
                string accession = regex.Match(target).Groups[2].Value;
                modification = new Modification(section, type, accession);
                if (positionLabel != null){
                    parsePosition(positionLabel, modification);
                }

                CVParam neutralLoss = string.IsNullOrEmpty(regex.Match(target).Groups[6].Value)
                                          ? null
                                          : new CVParam(regex.Match(target).Groups[4].Value,
                                                        regex.Match(target).Groups[5].Value,
                                                        regex.Match(target).Groups[6].Value,
                                                        regex.Match(target).Groups[7].Value);
                modification.NeutralLoss = neutralLoss;
            }

            return modification;
        }
Ejemplo n.º 3
0
        private static void parsePosition(string target, Modification modification)
        {
            target = translateTabToComma(target);
            SplitList<string> list = ParseStringList(MZTabConstants.BAR, target);

            Regex regex = new Regex("(\\d+)(\\[([^,]+)?,([^,]+)?,([^,]+),([^,]*)\\])?");

            foreach (string item in list){
                if (regex.IsMatch(item.Trim())){
                    int id = int.Parse(regex.Match(item.Trim()).Groups[1].Value);
                    CVParam param = string.IsNullOrEmpty(regex.Match(item.Trim()).Groups[5].Value)
                                        ? null
                                        : new CVParam(regex.Match(item.Trim()).Groups[3].Value,
                                                      regex.Match(item.Trim()).Groups[4].Value,
                                                      regex.Match(item.Trim()).Groups[5].Value,
                                                      regex.Match(item.Trim()).Groups[6].Value);
                    modification.AddPosition(id, param);
                }
            }
        }
Ejemplo n.º 4
0
        public bool AddModification(Modification modification)
        {
            if (modification == null){
                return false;
            }

            if (Modifications == null){
                Modifications = new SplitList<Modification>(MZTabConstants.COMMA);
            }

            if (Modifications.All(x => x.Accession != modification.Accession)){
                Modifications.Add(modification);
            }
            else{
                var m = Modifications.First(x => x.Accession == modification.Accession);
                foreach (int key in modification.PositionMap.Keys){
                    if (m.PositionMap.ContainsKey(key)){
                        continue;
                    }
                    m.AddPosition(key, modification.PositionMap[key]);
                }
            }
            return true;
        }