Example #1
0
        //TO THINK: Is it reasonable to transfer Glycan to Modification the first time Glycan is read in? Which could save time.
        //Use glycan index and modification index to reduce space.
        public static Modification NGlycanToModification(Glycan glycan)
        {
            Dictionary <DissociationType, List <double> > neutralLosses = new Dictionary <DissociationType, List <double> >();

            if (glycan.Ions != null)
            {
                List <double> lossMasses = glycan.Ions.Where(p => p.IonMass < 57000000).Select(p => (double)p.LossIonMass / 1E5).OrderBy(p => p).ToList(); //570 is a cutoff for glycan ion size 2N1H, which will generate fragment ions.
                neutralLosses.Add(DissociationType.HCD, lossMasses);
                neutralLosses.Add(DissociationType.CID, lossMasses);
                neutralLosses.Add(DissociationType.EThcD, lossMasses);
            }

            Dictionary <DissociationType, List <double> > diagnosticIons = new Dictionary <DissociationType, List <double> >();

            diagnosticIons.Add(DissociationType.HCD, glycan.DiagnosticIons.Select(p => (double)p / 1E5).ToList());
            diagnosticIons.Add(DissociationType.CID, glycan.DiagnosticIons.Select(p => (double)p / 1E5).ToList());
            diagnosticIons.Add(DissociationType.EThcD, glycan.DiagnosticIons.Select(p => (double)p / 1E5).ToList());
            ModificationMotif.TryGetMotif("N", out ModificationMotif finalMotif); //TO DO: only one motif can be write here.
            var          id           = Glycan.GetKindString(glycan.Kind);
            Modification modification = new Modification(
                _originalId: id,
                _modificationType: "N-Glycosylation",
                _monoisotopicMass: (double)glycan.Mass / 1E5,
                _locationRestriction: "Anywhere.",
                _target: finalMotif,
                _neutralLosses: neutralLosses,
                _diagnosticIons: diagnosticIons
                );

            return(modification);
        }
Example #2
0
        //There are two ways to represent a glycan in string, one only combination, the other structure.
        //The method generate a glycan by read in a glycan structure string from database.
        public static Glycan Struct2Glycan(string theGlycanStruct, int id, bool isOglycan = false)
        {
            Node        node     = Struct2Node(theGlycanStruct);
            List <Node> nodeIons = GetAllChildrenCombination(node);
            int         mass     = Glycan.GetMass(theGlycanStruct);

            byte[]           kind       = Glycan.GetKind(theGlycanStruct);
            List <GlycanIon> glycanIons = new List <GlycanIon>();
            HashSet <double> ionMasses  = new HashSet <double>();

            foreach (var aNodeIon in nodeIons)
            {
                var ionMass = Glycan.GetMass(Node2Struct(aNodeIon));
                if (!ionMasses.Contains(ionMass) && ionMass != mass)
                {
                    ionMasses.Add(ionMass);
                    var       ionKind     = Glycan.GetKind(Node2Struct(aNodeIon));
                    var       lossIonMass = GetIonLossMass(kind, ionKind);
                    GlycanIon glycanIon   = new GlycanIon(null, ionMass, ionKind, lossIonMass);
                    glycanIons.Add(glycanIon);
                }
            }
            if (!isOglycan)
            {
                glycanIons.Add(new GlycanIon(null, 8303819, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, mass - 8303819)); //Cross-ring mass
            }
            glycanIons.Add(new GlycanIon(null, 0, kind, mass));

            Glycan glycan = new Glycan(theGlycanStruct, mass, kind, glycanIons.OrderBy(p => p.IonMass).ToList(), false);

            glycan.GlyId = id;
            return(glycan);
        }
Example #3
0
        //The function here is to build GlycanBoxes used for LocalizationGraph.
        //In LocalizationGraph matrix, for each AdjNode, it represent a ChildOGlycanBox here at certain glycosite.
        public static IEnumerable <GlycanBox> BuildChildOGlycanBoxes(int maxNum, int[] glycanIds, bool targetDecoy = true)
        {
            yield return(new GlycanBox(new int[0], targetDecoy));

            HashSet <string> seen = new HashSet <string>();

            for (int i = 1; i <= maxNum; i++)
            {
                foreach (var idCombine in Glycan.GetKCombs(Enumerable.Range(0, maxNum), i))
                {
                    List <int> ids = new List <int>();
                    foreach (var id in idCombine)
                    {
                        ids.Add(glycanIds[id]);
                    }

                    if (!seen.Contains(string.Join(",", ids.Select(p => p.ToString()))))
                    {
                        seen.Add(string.Join(",", ids.Select(p => p.ToString())));

                        GlycanBox glycanBox = new GlycanBox(ids.ToArray(), targetDecoy);

                        yield return(glycanBox);
                    }
                }
            }
        }
Example #4
0
        //Load KindGlycan. Compatible with Byonic.
        public static IEnumerable <Glycan> LoadKindGlycan(string filePath, bool ToGenerateIons, bool IsOGlycanSearch)
        {
            using (StreamReader lines = new StreamReader(filePath))
            {
                int id = 1;
                while (lines.Peek() != -1)
                {
                    string line = lines.ReadLine().Split('\t').First();

                    if (!(line.Contains("HexNAc") || line.Contains("Hex")))
                    {
                        continue;
                    }

                    var kind = String2Kind(line);

                    var glycan = new Glycan(kind);
                    glycan.GlyId = id++;
                    if (ToGenerateIons)
                    {
                        if (IsOGlycanSearch)
                        {
                            glycan.Ions = OGlycanCompositionCombinationChildIons(kind);
                        }
                        else
                        {
                            glycan.Ions = NGlycanCompositionFragments(kind);
                        }
                    }
                    yield return(glycan);
                }
            }
        }
Example #5
0
        public static Modification OGlycanToModification(Glycan glycan)
        {
            //TO THINK: what the neutralLoss for O-Glyco?
            Dictionary <DissociationType, List <double> > neutralLosses = new Dictionary <DissociationType, List <double> >();

            if (glycan.Ions != null)
            {
                List <double> lossMasses = glycan.Ions.Select(p => (double)p.LossIonMass / 1E5).OrderBy(p => p).ToList();
                neutralLosses.Add(DissociationType.HCD, lossMasses);
                neutralLosses.Add(DissociationType.CID, lossMasses);
                neutralLosses.Add(DissociationType.EThcD, lossMasses);
            }

            Dictionary <DissociationType, List <double> > diagnosticIons = new Dictionary <DissociationType, List <double> >();

            diagnosticIons.Add(DissociationType.HCD, glycan.DiagnosticIons.Select(p => (double)p / 1E5).ToList());
            diagnosticIons.Add(DissociationType.CID, glycan.DiagnosticIons.Select(p => (double)p / 1E5).ToList());
            diagnosticIons.Add(DissociationType.EThcD, glycan.DiagnosticIons.Select(p => (double)p / 1E5).ToList());
            ModificationMotif.TryGetMotif("X", out ModificationMotif finalMotif); //TO DO: only one motif can be write here.

            var          id           = Glycan.GetKindString(glycan.Kind);
            Modification modification = new Modification(
                _originalId: id,
                _modificationType: "O-Glycosylation",
                _monoisotopicMass: (double)glycan.Mass / 1E5,
                _locationRestriction: "Anywhere.",
                _target: finalMotif,
                _neutralLosses: neutralLosses,
                _diagnosticIons: diagnosticIons
                );

            return(modification);
        }
Example #6
0
 private static void _GetCombinations(byte[] kind, List <byte[]> _kinds, HashSet <string> _keys)
 {
     if (kind.Sum(p => p) == 0)
     {
         return;
     }
     else
     {
         for (int i = 0; i < kind.Length; i++)
         {
             if (kind[i] >= 1)
             {
                 byte[] akind = (byte[])kind.Clone();
                 akind[i]--;
                 if (akind.Sum(p => p) != 0)
                 {
                     if (!_keys.Contains(Glycan.GetKindString(akind)))
                     {
                         _keys.Add(Glycan.GetKindString(akind));
                         _kinds.Add((byte[])akind.Clone());
                         _GetCombinations(akind, _kinds, _keys);
                     }
                 }
             }
         }
     }
 }
Example #7
0
 //kind are compositions of glycan. The function here is to generate mass difference of two glycan.
 public static int GetIonLossMass(byte[] Kind, byte[] ionKind)
 {
     byte[] lossKind = new byte[Kind.Length];
     for (int i = 0; i < Kind.Length; i++)
     {
         lossKind[i] = (byte)(Kind[i] - ionKind[i]);
     }
     return(Glycan.GetMass(lossKind));
 }
Example #8
0
        private static GlycanIon GenerateGlycanIon(byte hexose_count, byte hexnac_count, byte fuc_count, byte xyl_count, int glycan_mass)
        {
            byte[] ionKind = new byte[] { hexose_count, hexnac_count, 0, 0, fuc_count, 0, 0, 0, 0, xyl_count };

            int ionMass = Glycan.GetMass(ionKind);

            GlycanIon glycanIon = new GlycanIon(null, ionMass, ionKind, glycan_mass - ionMass);

            return(glycanIon);
        }
Example #9
0
        //After O-glycans are read in from database, we transfer the glycans into 'Modification' class type for MetaMorpheus to manipulate sequences.
        //In the future we may able to combine the two type together.
        public static Modification[] BuildGlobalOGlycanModifications(Glycan[] globalOGlycans)
        {
            Modification[] globalOGlycanModifications = new Modification[globalOGlycans.Length];

            for (int i = 0; i < GlobalOGlycans.Length; i++)
            {
                globalOGlycanModifications[i] = Glycan.OGlycanToModification(globalOGlycans[i]);
            }
            return(globalOGlycanModifications);
        }
Example #10
0
 //Load structured Glycan database.
 public static IEnumerable <Glycan> LoadStructureGlycan(string filePath, bool IsOGlycan)
 {
     using (StreamReader glycans = new StreamReader(filePath))
     {
         int id = 1;
         while (glycans.Peek() != -1)
         {
             string line = glycans.ReadLine();
             yield return(Glycan.Struct2Glycan(line, id++, IsOGlycan));
         }
     }
 }
Example #11
0
        private static GlycanIon ExtendGlycanIon(GlycanIon glycanIon, byte hexose_count, byte hexnac_count, byte fuc_count, byte xyl_count, int glycan_mass)
        {
            byte[] ionKind = glycanIon.IonKind;
            ionKind[0] += hexose_count;
            ionKind[1] += hexnac_count;
            ionKind[4] += fuc_count;
            ionKind[9] += xyl_count;

            int ionMass = Glycan.GetMass(ionKind);

            GlycanIon extend_glycanIon = new GlycanIon(null, ionMass, ionKind, glycan_mass - ionMass);

            return(extend_glycanIon);
        }
Example #12
0
 public static bool Equals(Glycan glycan1, Glycan glycan2)
 {
     if (glycan1.Mass == glycan2.Mass)
     {
         if (glycan1.Ions.Count() == glycan2.Ions.Count())
         {
             for (int i = 0; i < glycan1.Ions.Count(); i++)
             {
                 if (glycan1.Ions[i].IonMass != glycan2.Ions[i].IonMass)
                 {
                     return(false);
                 }
             }
             return(true);
         }
     }
     return(false);
 }
        private static void LoadGlycans()
        {
            OGlycanLocations = new List <string>();
            NGlycanLocations = new List <string>();

            foreach (var glycanFile in Directory.GetFiles(Path.Combine(DataDir, @"Glycan_Mods", @"OGlycan")))
            {
                OGlycanLocations.Add(glycanFile);
            }

            foreach (var glycanFile in Directory.GetFiles(Path.Combine(DataDir, @"Glycan_Mods", @"NGlycan")))
            {
                NGlycanLocations.Add(glycanFile);
            }

            //Add Glycan mod into AllModsKnownDictionary, currently this is for MetaDraw.
            //The reason why not include Glycan into modification database is for users to apply their own database.
            foreach (var path in OGlycanLocations)
            {
                var og = GlycanDatabase.LoadGlycan(path, false, false);
                foreach (var g in og)
                {
                    var ogmod = Glycan.OGlycanToModification(g);
                    if (!AllModsKnownDictionary.ContainsKey(ogmod.IdWithMotif))
                    {
                        AllModsKnownDictionary.Add(ogmod.IdWithMotif, ogmod);
                    }
                }
            }
            foreach (var path in NGlycanLocations)
            {
                var og = GlycanDatabase.LoadGlycan(path, false, false);
                foreach (var g in og)
                {
                    var ogmod = Glycan.OGlycanToModification(g);
                    if (!AllModsKnownDictionary.ContainsKey(ogmod.IdWithMotif))
                    {
                        AllModsKnownDictionary.Add(ogmod.IdWithMotif, ogmod);
                    }
                }
            }
        }
Example #14
0
        //The OGlycanCompositionFragments just generate some core GlycanIons. We need a combination solution.
        public static List <GlycanIon> OGlycanCompositionCombinationChildIons(byte[] kind)
        {
            List <GlycanIon> glycanIons = new List <GlycanIon>();

            int glycan_mass = Glycan.GetMass(kind);

            List <byte[]>    _kinds = new List <byte[]>();
            HashSet <string> _keys  = new HashSet <string>();

            _kinds.Add((byte[])kind.Clone());
            _GetCombinations(kind, _kinds, _keys);

            foreach (var k in _kinds)
            {
                //Rules to build OGlycan child ions.
                //At least one HexNAc
                if (k[1] == 0)
                {
                    continue;
                }

                //#Fucose <= #HexNAc. One Fucose modify one
                if (k[4] != 0 && k[4] > k[1])
                {
                    continue;
                }

                //#NeuAc * 2 >= #Acetylation. One NeuAc can be modified with two Acetylation
                if (k[9] != 0 && k[2] * 2 < k[9])
                {
                    continue;
                }

                var       ionMass   = Glycan.GetMass(k);
                GlycanIon glycanIon = new GlycanIon(null, ionMass, k, glycan_mass - ionMass);
                glycanIons.Add(glycanIon);
            }

            return(glycanIons.OrderBy(p => p.IonMass).ToList());
        }
Example #15
0
        public static IEnumerable <GlycanBox> BuildOGlycanBoxes(int maxNum, bool buildDecoy)
        {
            for (int i = 1; i <= maxNum; i++)
            {
                foreach (var idCombine in Glycan.GetKCombsWithRept(Enumerable.Range(0, GlobalOGlycans.Length), i))
                {
                    GlycanBox glycanBox = new GlycanBox(idCombine.ToArray());
                    glycanBox.TargetDecoy      = true;
                    glycanBox.ChildGlycanBoxes = BuildChildOGlycanBoxes(glycanBox.NumberOfMods, glycanBox.ModIds, glycanBox.TargetDecoy).ToArray();

                    yield return(glycanBox);

                    if (buildDecoy)
                    {
                        GlycanBox glycanBox_decoy = new GlycanBox(idCombine.ToArray());
                        glycanBox_decoy.TargetDecoy      = false;
                        glycanBox_decoy.ChildGlycanBoxes = BuildChildOGlycanBoxes(glycanBox_decoy.NumberOfMods, glycanBox_decoy.ModIds, glycanBox_decoy.TargetDecoy).ToArray();
                        yield return(glycanBox_decoy);
                    }
                }
            }
        }
Example #16
0
        public static Glycan[] BuildTargetDecoyGlycans(IEnumerable <Glycan> glycans)
        {
            List <Glycan> allGlycans = new List <Glycan>();

            Random random = new Random();

            foreach (var aGlycan in glycans)
            {
                allGlycans.Add(aGlycan);
                List <GlycanIon> glycanIons = new List <GlycanIon>();
                foreach (var ion in aGlycan.Ions)
                {
                    var       value     = random.Next(100000, 3000000); //Based on pGlyco [1, 30] and GlycoPAT [-50, 50].
                    GlycanIon glycanIon = new GlycanIon(null, ion.IonMass + value, ion.IonKind, ion.LossIonMass - value);
                    glycanIons.Add(glycanIon);
                }
                var aDecoyGlycan = new Glycan(aGlycan.Struc, aGlycan.Mass, aGlycan.Kind, glycanIons, true);
                aDecoyGlycan.GlyId = aGlycan.GlyId;
                allGlycans.Add(aDecoyGlycan);
            }
            return(allGlycans.OrderBy(p => p.Mass).ToArray());
        }
Example #17
0
        public GlycanBox(int[] ids, bool targetDecoy = true) : base(ids)
        {
            byte[] kind = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            foreach (var id in ModIds)
            {
                for (int i = 0; i < kind.Length; i++)
                {
                    kind[i] += GlobalOGlycans[id].Kind[i];
                }
            }
            Kind = kind;

            if (targetDecoy)
            {
                Mass = (double)Glycan.GetMass(Kind) / 1E5;
            }
            else
            {
                Random random   = new Random();
                int    shiftInd = random.Next(SugarShift.Length);
                Mass = (double)(Glycan.GetMass(Kind) + SugarShift[shiftInd]) / 1E5;
            }
        }
Example #18
0
        //This function build fragments based on the general core of NGlyco fragments.
        //From https://github.com/mobiusklein/glycopeptidepy/structure/fragmentation_strategy/glycan.py#L408
        //The fragment generation is not as good as structure based method. So it is better to use a structure based N-Glycan database.
        public static List <GlycanIon> NGlycanCompositionFragments(byte[] kind)
        {
            int glycan_mass = Glycan.GetMass(kind);

            int  core_count            = 1;
            int  iteration_count       = 0;
            bool extended              = true;
            bool extended_fucosylation = false;

            int fuc_count          = kind[4];
            int xyl_count          = kind[9];
            int hexnac_inaggregate = kind[0];
            int hexose_inaggregate = kind[1];

            List <GlycanIon> glycanIons = new List <GlycanIon>();

            int base_hexnac = Math.Min(hexnac_inaggregate + 1, 3);

            for (int hexnac_count = 0; hexnac_count < base_hexnac; hexnac_count++)
            {
                if (hexnac_count == 0)
                {
                    GlycanIon glycanIon = new GlycanIon(null, 8303819, new byte[] { 0, (byte)hexnac_count, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, glycan_mass - 8303819);
                    glycanIons.Add(glycanIon);
                }
                else if (hexnac_count == 1)
                {
                    GlycanIon glycanIon = GenerateGlycanIon(0, (byte)hexnac_count, 0, 0, glycan_mass);

                    glycanIons.Add(glycanIon);

                    if (iteration_count < fuc_count)
                    {
                        GlycanIon fuc_glycanIon = ExtendGlycanIon(glycanIon, 0, 0, 1, 0, glycan_mass);

                        glycanIons.Add(fuc_glycanIon);
                    }
                }
                else if (hexnac_count == 2)
                {
                    GlycanIon glycanIon = GenerateGlycanIon(0, (byte)hexnac_count, 0, 0, glycan_mass);
                    glycanIons.Add(glycanIon);

                    if (!extended_fucosylation)
                    {
                        if (iteration_count < fuc_count)
                        {
                            GlycanIon fuc_glycanIon = ExtendGlycanIon(glycanIon, 0, 0, 1, 0, glycan_mass);
                            glycanIons.Add(fuc_glycanIon);

                            if (iteration_count < xyl_count)
                            {
                                GlycanIon xyl_fuc_glycanIon = ExtendGlycanIon(fuc_glycanIon, 0, 0, 0, 1, glycan_mass);
                                glycanIons.Add(xyl_fuc_glycanIon);
                            }
                        }
                    }
                    else if (fuc_count > 0)
                    {
                        GlycanIon fuc_glycanIon = ExtendGlycanIon(glycanIon, 0, 0, 1, 0, glycan_mass);
                        glycanIons.Add(fuc_glycanIon);

                        for (int add_fuc_count = 2; add_fuc_count <= fuc_count; add_fuc_count++)
                        {
                            GlycanIon add_fuc_glycanIon = ExtendGlycanIon(glycanIon, 0, 0, (byte)add_fuc_count, 0, glycan_mass);
                            glycanIons.Add(add_fuc_glycanIon);
                        }

                        if (iteration_count < xyl_count)
                        {
                            GlycanIon xyl_fuc_glycanIon = ExtendGlycanIon(fuc_glycanIon, 0, 0, 0, 1, glycan_mass);
                            glycanIons.Add(xyl_fuc_glycanIon);
                        }
                    }

                    if (iteration_count < xyl_count)
                    {
                        GlycanIon xyl_glycanIon = ExtendGlycanIon(glycanIon, 0, 0, 0, 1, glycan_mass);
                        glycanIons.Add(xyl_glycanIon);
                    }


                    int min_hexose_inaggregate = Math.Min(hexose_inaggregate + 1, 4);
                    for (int hexose_count = 1; hexose_count <= min_hexose_inaggregate; hexose_count++)
                    {
                        GlycanIon hexose_glycanIon = GenerateGlycanIon((byte)hexose_count, (byte)hexnac_count, 0, 0, glycan_mass);
                        glycanIons.Add(hexose_glycanIon);

                        if (!extended_fucosylation)
                        {
                            GlycanIon fuc_glycanIon = ExtendGlycanIon(hexose_glycanIon, 0, 0, 1, 0, glycan_mass);
                            glycanIons.Add(fuc_glycanIon);

                            if (iteration_count < xyl_count)
                            {
                                GlycanIon xyl_fuc_glycanIon = ExtendGlycanIon(fuc_glycanIon, 0, 0, 0, 1, glycan_mass);
                                glycanIons.Add(xyl_fuc_glycanIon);
                            }
                        }
                        else if (fuc_count > 0)
                        {
                            GlycanIon fuc_glycanIon = ExtendGlycanIon(hexose_glycanIon, 0, 0, 1, 0, glycan_mass);
                            glycanIons.Add(fuc_glycanIon);

                            for (int add_fuc_count = 2; add_fuc_count <= fuc_count; add_fuc_count++)
                            {
                                GlycanIon add_fuc_glycanIon = ExtendGlycanIon(hexose_glycanIon, 0, 0, (byte)add_fuc_count, 0, glycan_mass);
                                glycanIons.Add(add_fuc_glycanIon);
                            }

                            if (iteration_count < xyl_count)
                            {
                                GlycanIon xyl_fuc_glycanIon = ExtendGlycanIon(fuc_glycanIon, 0, 0, 0, 1, glycan_mass);
                                glycanIons.Add(xyl_fuc_glycanIon);
                            }
                        }

                        if (iteration_count < xyl_count)
                        {
                            GlycanIon xyl_glycanIon = ExtendGlycanIon(hexose_glycanIon, 0, 0, 0, 1, glycan_mass);
                            glycanIons.Add(xyl_glycanIon);
                        }

                        if (hexose_count == 3 && hexnac_count >= 2 * core_count && extended)
                        {
                            for (int extra_hexnac_count = 0; extra_hexnac_count < hexnac_inaggregate - hexnac_count + 1; extra_hexnac_count++)
                            {
                                if (extra_hexnac_count + hexnac_count > hexnac_inaggregate)
                                {
                                    continue;
                                }

                                if (extra_hexnac_count > 0)
                                {
                                    GlycanIon new_glycanIon = GenerateGlycanIon((byte)hexose_count, (byte)(hexnac_count + extra_hexnac_count), 0, 0, glycan_mass);

                                    glycanIons.Add(new_glycanIon);

                                    if (!extended_fucosylation)
                                    {
                                        GlycanIon fuc_glycanIon = ExtendGlycanIon(new_glycanIon, 0, 0, 1, 0, glycan_mass);
                                        glycanIons.Add(fuc_glycanIon);

                                        if (iteration_count < xyl_count)
                                        {
                                            GlycanIon xyl_fuc_glycanIon = ExtendGlycanIon(fuc_glycanIon, 0, 0, 0, 1, glycan_mass);
                                            glycanIons.Add(xyl_fuc_glycanIon);
                                        }
                                    }
                                    else if (fuc_count > 0)
                                    {
                                        GlycanIon fuc_glycanIon = ExtendGlycanIon(new_glycanIon, 0, 0, 1, 0, glycan_mass);
                                        glycanIons.Add(fuc_glycanIon);

                                        for (int add_fuc_count = 2; add_fuc_count <= fuc_count; add_fuc_count++)
                                        {
                                            GlycanIon add_fuc_glycanIon = ExtendGlycanIon(new_glycanIon, 0, 0, (byte)add_fuc_count, 0, glycan_mass);
                                            glycanIons.Add(add_fuc_glycanIon);
                                        }

                                        if (iteration_count < xyl_count)
                                        {
                                            GlycanIon xyl_fuc_glycanIon = ExtendGlycanIon(fuc_glycanIon, 0, 0, 0, 1, glycan_mass);
                                            glycanIons.Add(xyl_fuc_glycanIon);
                                        }
                                    }

                                    if (iteration_count < xyl_count)
                                    {
                                        GlycanIon xyl_glycanIon = ExtendGlycanIon(new_glycanIon, 0, 0, 0, 1, glycan_mass);
                                        glycanIons.Add(xyl_glycanIon);
                                    }
                                }

                                for (int extra_hexose_count = 1; extra_hexose_count < hexose_inaggregate - hexose_count + 1; extra_hexose_count++)
                                {
                                    if (extra_hexose_count + hexose_count > hexose_inaggregate)
                                    {
                                        continue;
                                    }

                                    GlycanIon new_glycanIon = GenerateGlycanIon((byte)(hexose_count + extra_hexose_count), (byte)(hexnac_count + extra_hexnac_count), 0, 0, glycan_mass);

                                    glycanIons.Add(new_glycanIon);

                                    if (!extended_fucosylation)
                                    {
                                        GlycanIon fuc_glycanIon = ExtendGlycanIon(new_glycanIon, 0, 0, 1, 0, glycan_mass);
                                        glycanIons.Add(fuc_glycanIon);

                                        if (iteration_count < xyl_count)
                                        {
                                            GlycanIon xyl_fuc_glycanIon = ExtendGlycanIon(fuc_glycanIon, 0, 0, 0, 1, glycan_mass);
                                            glycanIons.Add(xyl_fuc_glycanIon);
                                        }
                                    }
                                    else if (fuc_count > 0)
                                    {
                                        GlycanIon fuc_glycanIon = ExtendGlycanIon(new_glycanIon, 0, 0, 1, 0, glycan_mass);
                                        glycanIons.Add(fuc_glycanIon);

                                        for (int add_fuc_count = 2; add_fuc_count <= fuc_count; add_fuc_count++)
                                        {
                                            GlycanIon add_fuc_glycanIon = ExtendGlycanIon(new_glycanIon, 0, 0, (byte)add_fuc_count, 0, glycan_mass);
                                            glycanIons.Add(add_fuc_glycanIon);
                                        }

                                        if (iteration_count < xyl_count)
                                        {
                                            GlycanIon xyl_fuc_glycanIon = ExtendGlycanIon(fuc_glycanIon, 0, 0, 0, 1, glycan_mass);
                                            glycanIons.Add(xyl_fuc_glycanIon);
                                        }
                                    }

                                    if (iteration_count < xyl_count)
                                    {
                                        GlycanIon xyl_glycanIon = ExtendGlycanIon(new_glycanIon, 0, 0, 0, 1, glycan_mass);
                                        glycanIons.Add(xyl_glycanIon);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(glycanIons);
        }
Example #19
0
        //This function build fragments based on the general core of OGlyco fragments.
        //From https://github.com/mobiusklein/glycopeptidepy/structure/fragmentation_strategy/glycan.py
        //The fragment generation is not as good as structure based method. So it is better to use a structure based O-Glycan database.
        public static List <GlycanIon> OGlycanCompositionFragments(byte[] kind)
        {
            List <GlycanIon> glycanIons = new List <GlycanIon>();

            int glycan_mass = Glycan.GetMass(kind);

            int  iteration_count = 0;
            bool extended        = true;

            int fuc_count          = kind[4];
            int hexnac_inaggregate = kind[0];
            int hexose_inaggregate = kind[1];

            for (int hexnac_count = 0; hexnac_count < 3; hexnac_count++)
            {
                if (hexnac_inaggregate < hexnac_count)
                {
                    continue;
                }


                if (hexnac_count >= 1)
                {
                    GlycanIon glycanIon = GenerateGlycanIon(0, (byte)hexnac_count, 0, 0, glycan_mass);

                    glycanIons.Add(glycanIon);

                    if (iteration_count < fuc_count)
                    {
                        GlycanIon fuc_glycanIon = ExtendGlycanIon(glycanIon, 0, 0, 1, 0, glycan_mass);

                        glycanIons.Add(fuc_glycanIon);
                    }

                    for (int hexose_count = 0; hexose_count < 2; hexose_count++)
                    {
                        if (hexose_inaggregate < hexose_count)
                        {
                            continue;
                        }

                        if (hexose_count > 0)
                        {
                            GlycanIon hexose_glycanIon = GenerateGlycanIon((byte)hexose_count, (byte)hexnac_count, 0, 0, glycan_mass);
                            glycanIons.Add(hexose_glycanIon);

                            if (iteration_count < fuc_count)
                            {
                                GlycanIon fuc_glycanIon = ExtendGlycanIon(hexose_glycanIon, 0, 0, 1, 0, glycan_mass);

                                glycanIons.Add(fuc_glycanIon);
                            }
                        }

                        // After the core motif has been exhausted, speculatively add on the remaining core monosaccharides sequentially until exhausted.

                        if (extended && hexnac_inaggregate - hexnac_count >= 0)
                        {
                            for (int extra_hexnac_count = 0; extra_hexnac_count < hexnac_inaggregate - hexnac_count + 1; extra_hexnac_count++)
                            {
                                if (extra_hexnac_count > 0)
                                {
                                    GlycanIon new_glycanIon = GenerateGlycanIon((byte)hexose_count, (byte)(hexnac_count + extra_hexnac_count), 0, 0, glycan_mass);

                                    glycanIons.Add(new_glycanIon);


                                    if (iteration_count < fuc_count)
                                    {
                                        GlycanIon fuc_glycanIon = ExtendGlycanIon(new_glycanIon, 0, 0, 1, 0, glycan_mass);

                                        glycanIons.Add(fuc_glycanIon);
                                    }
                                }

                                if (hexose_inaggregate > hexose_count && hexose_count > 0)
                                {
                                    for (int extra_hexose_count = 0; extra_hexose_count < hexose_inaggregate - hexose_count; extra_hexose_count++)
                                    {
                                        if (extra_hexose_count > 0 && extra_hexose_count + hexose_count > 0)
                                        {
                                            GlycanIon new_glycanIon = GenerateGlycanIon((byte)(hexose_count + extra_hexose_count), (byte)(hexnac_count + extra_hexnac_count), 0, 0, glycan_mass);

                                            glycanIons.Add(new_glycanIon);


                                            if (iteration_count < fuc_count)
                                            {
                                                GlycanIon fuc_glycanIon = ExtendGlycanIon(new_glycanIon, 0, 0, 1, 0, glycan_mass);

                                                glycanIons.Add(fuc_glycanIon);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }


            return(glycanIons);
        }
        static GlobalVariables()
        {
            MetaMorpheusVersion = typeof(GlobalVariables).Assembly.GetName().Version.ToString();

            if (MetaMorpheusVersion.Equals("1.0.0.0"))
            {
#if DEBUG
                MetaMorpheusVersion = "Not a release version. DEBUG.";
#else
                MetaMorpheusVersion = "Not a release version.";
#endif
            }
            else
            {
                // as of 0.0.277, AppVeyor appends the build number
                // this is intentional; it's to avoid conflicting AppVeyor build numbers
                // trim the build number off the version number for displaying/checking versions, etc
                var foundIndexes = new List <int>();
                for (int i = 0; i < MetaMorpheusVersion.Length; i++)
                {
                    if (MetaMorpheusVersion[i] == '.')
                    {
                        foundIndexes.Add(i);
                    }
                }
                MetaMorpheusVersion = MetaMorpheusVersion.Substring(0, foundIndexes.Last());
            }

            {
                var pathToProgramFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                if (!String.IsNullOrWhiteSpace(pathToProgramFiles) && AppDomain.CurrentDomain.BaseDirectory.Contains(pathToProgramFiles) && !AppDomain.CurrentDomain.BaseDirectory.Contains("Jenkins"))
                {
                    DataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MetaMorpheus");
                }
                else
                {
                    DataDir = AppDomain.CurrentDomain.BaseDirectory;
                }
            }

            ElementsLocation = Path.Combine(DataDir, @"Data", @"elements.dat");
            UsefulProteomicsDatabases.Loaders.LoadElements();

            AddSeparationTypes(new List <string> {
                { "HPLC" }, { "CZE" }
            });

            // load default crosslinkers
            string crosslinkerLocation = Path.Combine(DataDir, @"Data", @"Crosslinkers.tsv");
            AddCrosslinkers(Crosslinker.LoadCrosslinkers(crosslinkerLocation));

            // load custom crosslinkers
            string customCrosslinkerLocation = Path.Combine(DataDir, @"Data", @"CustomCrosslinkers.tsv");
            if (File.Exists(customCrosslinkerLocation))
            {
                AddCrosslinkers(Crosslinker.LoadCrosslinkers(customCrosslinkerLocation));
            }


            OGlycanLocations = new List <string>();
            foreach (var glycanFile in Directory.GetFiles(Path.Combine(DataDir, @"Glycan_Mods", @"OGlycan")))
            {
                OGlycanLocations.Add(glycanFile);
            }
            NGlycanLocations = new List <string>();
            foreach (var glycanFile in Directory.GetFiles(Path.Combine(DataDir, @"Glycan_Mods", @"NGlycan")))
            {
                NGlycanLocations.Add(glycanFile);
            }

            ExperimentalDesignFileName = "ExperimentalDesign.tsv";

            UnimodDeserialized = UsefulProteomicsDatabases.Loaders.LoadUnimod(Path.Combine(DataDir, @"Data", @"unimod.xml")).ToList();
            PsiModDeserialized = UsefulProteomicsDatabases.Loaders.LoadPsiMod(Path.Combine(DataDir, @"Data", @"PSI-MOD.obo.xml"));
            var formalChargesDictionary = UsefulProteomicsDatabases.Loaders.GetFormalChargesDictionary(PsiModDeserialized);
            UniprotDeseralized = UsefulProteomicsDatabases.Loaders.LoadUniprot(Path.Combine(DataDir, @"Data", @"ptmlist.txt"), formalChargesDictionary).ToList();

            foreach (var modFile in Directory.GetFiles(Path.Combine(DataDir, @"Mods")))
            {
                AddMods(UsefulProteomicsDatabases.PtmListLoader.ReadModsFromFile(modFile, out var errorMods), false);
            }

            AddMods(UniprotDeseralized.OfType <Modification>(), false);
            AddMods(UnimodDeserialized.OfType <Modification>(), false);

            // populate dictionaries of known mods/proteins for deserialization
            AllModsKnownDictionary = new Dictionary <string, Modification>();
            foreach (Modification mod in AllModsKnown)
            {
                if (!AllModsKnownDictionary.ContainsKey(mod.IdWithMotif))
                {
                    AllModsKnownDictionary.Add(mod.IdWithMotif, mod);
                }
                // no error thrown if multiple mods with this ID are present - just pick one
            }

            //Add Glycan mod into AllModsKnownDictionary, currently this is for MetaDraw.
            //The reason why not include Glycan into modification database is for users to apply their own database.
            foreach (var path in OGlycanLocations)
            {
                var og = GlycanDatabase.LoadGlycan(path, false, false);
                foreach (var g in og)
                {
                    var ogmod = Glycan.OGlycanToModification(g);
                    if (!AllModsKnownDictionary.ContainsKey(ogmod.IdWithMotif))
                    {
                        AllModsKnownDictionary.Add(ogmod.IdWithMotif, ogmod);
                    }
                }
            }
            foreach (var path in NGlycanLocations)
            {
                var og = GlycanDatabase.LoadGlycan(path, false, false);
                foreach (var g in og)
                {
                    var ogmod = Glycan.OGlycanToModification(g);
                    if (!AllModsKnownDictionary.ContainsKey(ogmod.IdWithMotif))
                    {
                        AllModsKnownDictionary.Add(ogmod.IdWithMotif, ogmod);
                    }
                }
            }

            RefreshAminoAcidDictionary();

            string settingsPath = Path.Combine(DataDir, @"settings.toml");
            if (!File.Exists(settingsPath))
            {
                Toml.WriteFile <GlobalSettings>(new GlobalSettings(), settingsPath);
            }

            GlobalSettings = Toml.ReadFile <GlobalSettings>(settingsPath);
            AllSupportedDissociationTypes = new Dictionary <string, DissociationType> {
                { DissociationType.CID.ToString(), DissociationType.CID },
                { DissociationType.ECD.ToString(), DissociationType.ECD },
                { DissociationType.ETD.ToString(), DissociationType.ETD },
                { DissociationType.HCD.ToString(), DissociationType.HCD },
                { DissociationType.EThcD.ToString(), DissociationType.EThcD },
                { DissociationType.Custom.ToString(), DissociationType.Custom },
                { DissociationType.LowCID.ToString(), DissociationType.LowCID }

                // TODO: allow reading from scan header (autodetect dissociation type)
            };
        }