Beispiel #1
0
        public override string ToString()
        {
            var sb     = new StringBuilder("StructB(");
            int tmp198 = 0;

            if ((Aa != null) && __isset.aa)
            {
                if (0 < tmp198++)
                {
                    sb.Append(", ");
                }
                sb.Append("Aa: ");
                Aa.ToString(sb);
            }
            if ((Ab != null))
            {
                if (0 < tmp198)
                {
                    sb.Append(", ");
                }
                sb.Append("Ab: ");
                Ab.ToString(sb);
            }
            sb.Append(')');
            return(sb.ToString());
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nChain">The peptide that will be constitute the N-terminal region of the resultant spliced peptide</param>
        /// <param name="cChain">The peptide that will be constitute the C-terminal region of the resultant spliced peptide</param>
        /// <param name="nInclude">The included portion of the N-terminal peptide</param>
        /// <param name="cInclude">The included portion of hte C-terminal peptide</param>
        /// <param name="nAlignNullable">The region to align on prior to splicing</param>
        /// <param name="cAlignNullable">The region to align on prior to splicing</param>
        /// <returns></returns>
        public static IChain GetPeptide(IChain nChain, IChain cChain, Range nInclude, Range cInclude, Range?nAlignNullable = null, Range?cAlignNullable = null)
        {
            bool  performAlignment = nAlignNullable != null && cAlignNullable != null;
            Range nAlign           = performAlignment ? new Range((Range)nAlignNullable) : new Range();
            Range cAlign           = performAlignment ? new Range((Range)cAlignNullable) : new Range();

            if (performAlignment && ((Range)nAlignNullable).Length != ((Range)cAlignNullable).Length)
            {
                throw new ArgumentException("Splice ranges must be of equal length");
            }
            if (nInclude.Start < 0 || nChain.Count <= nInclude.End || cInclude.Start < 0 || cChain.Count <= cInclude.End)
            {
                throw new IndexOutOfRangeException("Splice ranges exceed the peptide ranges");
            }

            IChain chain = new Chain();
            //float rmsd = Rmsd.GetRmsd(cTerminus[cAlign.Start, cAlign.End], nTerminus[nAlign.Start, nAlign.End]);
            Matrix cTerminusTransform = performAlignment ? Rmsd.GetRmsdTransform(cChain[cAlign.Start, cAlign.End], nChain[nAlign.Start, nAlign.End]) : Matrix.Identity;

            cTerminusTransform.Rotation.Normalize();
            //Quaternion rotation = cTerminusTransform.Rotation;
            //rotation.Normalize();
            //cTerminusTransform.Rotation = rotation;
            for (int i = nInclude.Start; i <= nInclude.End; i++)
            {
                chain.Add(new Aa(nChain[i]));
            }
            for (int i = cInclude.Start; i <= cInclude.End; i++)
            {
                IAa residue = new Aa(cChain[i]);
                residue.Transform(cTerminusTransform);
                chain.Add(residue);
            }
            return(chain);
        }
Beispiel #3
0
 public void Write(TProtocol oprot)
 {
     oprot.IncrementRecursionDepth();
     try
     {
         TStruct struc = new TStruct("StructB");
         oprot.WriteStructBegin(struc);
         TField field = new TField();
         if (Aa != null && __isset.aa)
         {
             field.Name = "aa";
             field.Type = TType.Struct;
             field.ID   = 1;
             oprot.WriteFieldBegin(field);
             Aa.Write(oprot);
             oprot.WriteFieldEnd();
         }
         field.Name = "ab";
         field.Type = TType.Struct;
         field.ID   = 2;
         oprot.WriteFieldBegin(field);
         Ab.Write(oprot);
         oprot.WriteFieldEnd();
         oprot.WriteFieldStop();
         oprot.WriteStructEnd();
     }
     finally
     {
         oprot.DecrementRecursionDepth();
     }
 }
        public void AA_ShouldPassAddDelayedMessageToLog_WhenBagIsDelayingFlight()
        {
            var timerServiceMock = new Mock <ITimerService>();

            timerServiceMock.Setup(ts => ts.SimulationMultiplier).Returns(1);

            var flightMock = new Mock <IFlight>();

            flightMock.Setup(b => b.FlightState).Returns(FlightState.Departed);

            var bagMock = new Mock <Baggage>();

            bagMock.Object.Destination = typeof(BagCollector).Name;
            bagMock.Object.Flight      = flightMock.Object;

            var bagCollector = new Mock <IChainLink>();

            bagCollector.Setup(bc => bc.Destination).Returns(typeof(BagCollector).Name);

            var aa = new Aa(1, Guid.NewGuid().ToString(), timerServiceMock.Object);

            aa.AddSuccessor(bagCollector.Object);

            aa.PassBaggage(bagMock.Object);

            bagMock.Object.Log.ShouldContain(l => l.Description.Contains(LoggingConstants.BagArrivedLateAtAirportArea));
        }
        public void AA_ShouldPassBaggageToBagCollector_WhenBagIsForBagCollector()
        {
            var timerServiceMock = new Mock <ITimerService>();

            timerServiceMock.Setup(ts => ts.SimulationMultiplier).Returns(1);

            var flightMock = new Mock <IFlight>();

            flightMock.Setup(b => b.FlightState).Returns(FlightState.InPreparation);

            var bagMock = new Mock <IBaggage>();

            bagMock.Setup(b => b.Destination).Returns(typeof(BagCollector).Name);
            bagMock.Setup(b => b.Flight).Returns(flightMock.Object);

            var bagCollector = new Mock <IChainLink>();

            bagCollector.Setup(bc => bc.Destination).Returns(typeof(BagCollector).Name);

            var aa = new Aa(1, Guid.NewGuid().ToString(), timerServiceMock.Object);

            aa.AddSuccessor(bagCollector.Object);

            aa.PassBaggage(bagMock.Object);

            bagMock.Object.Destination.ShouldBe(typeof(BagCollector).Name);
        }
Beispiel #6
0
 private void button2_Click(object sender, EventArgs e)
 {
     Aa.Clear();
     Bb.Clear();
     Hh.Clear();
     rez.Clear();
 }
        static void Main()
        {
            InheritanceToInterface obj = new InheritanceToInterface();
            Aa obj2 = (Aa)obj;
            Bb obj3 = (Bb)obj;

            obj2.Add();
            obj3.Add();
            Console.Read();
        }
Beispiel #8
0
        static void AddDisulfides(Chain peptide)
        {
            for (int i = 0; i < peptide.Count - 1; i++)
            {
                IAa residue1 = peptide[i];
                if (residue1.Name != "CYH")
                {
                    continue;
                }
                for (int j = i + 1; j < peptide.Count; j++)
                {
                    IAa residue2 = peptide[j];
                    if (residue2.Name != "CYH")
                    {
                        continue;
                    }

                    Vector3 SG1 = residue1["SG"].Xyz;
                    Vector3 SG2 = residue2["SG"].Xyz;
                    if (!VectorMath.IsValid(SG1) || !VectorMath.IsValid(SG2))
                    {
                        continue;
                    }

                    if (Vector3.Distance(SG1, SG2) < 2.5)
                    {
                        IAa replace1 = new Aa("CYS", residue1.IsNTerminus, residue1.IsCTerminus);
                        replace1.AlignToNCAC(residue1);
                        foreach (IAtom atom in residue1)
                        {
                            IAtom match = replace1[atom.Name];
                            if (match != null)
                            {
                                match.Xyz = atom.Xyz;
                            }
                        }

                        IAa replace2 = new Aa("CYS", residue2.IsNTerminus, residue2.IsCTerminus);
                        replace2.AlignToNCAC(residue2);
                        foreach (IAtom atom in residue2)
                        {
                            IAtom match = replace2[atom.Name];
                            if (match != null)
                            {
                                match.Xyz = atom.Xyz;
                            }
                        }

                        peptide[i, true] = replace1;
                        peptide[j, true] = replace2;
                        break;
                    }
                }
            }
        }
        public void TestWildCardEventInActor()
        {
            var config = new LogEvent();

            this.Test(r =>
            {
                Aa.RunTest(r, config);
            });

            string actual = config.ToString();

            Assert.True(actual is "E2,UnitEvent,E1");
        }
Beispiel #10
0
        public override int GetHashCode()
        {
            int hashcode = 157;

            unchecked {
                if ((Aa != null) && __isset.aa)
                {
                    hashcode = (hashcode * 397) + Aa.GetHashCode();
                }
                if ((Ab != null))
                {
                    hashcode = (hashcode * 397) + Ab.GetHashCode();
                }
            }
            return(hashcode);
        }
        public void AA_ShouldPassBaggageToMpa_WhenBagIsForMpa()
        {
            var timerServiceMock = new Mock <ITimerService>();
            var bagMock          = new Mock <IBaggage>();

            bagMock.Setup(b => b.Destination).Returns(typeof(Mpa).Name);
            var mpaMock = new Mock <IChainLink>();

            mpaMock.Setup(mpa => mpa.Destination).Returns(typeof(Mpa).Name);

            var aa = new Aa(1, Guid.NewGuid().ToString(), timerServiceMock.Object);

            aa.AddSuccessor(mpaMock.Object);

            aa.PassBaggage(bagMock.Object);

            bagMock.Object.Destination.ShouldBe(typeof(Mpa).Name);
        }
Beispiel #12
0
        public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
            oprot.IncrementRecursionDepth();
            try
            {
                var struc = new TStruct("StructB");
                await oprot.WriteStructBeginAsync(struc, cancellationToken);

                var field = new TField();
                if ((Aa != null) && __isset.aa)
                {
                    field.Name = "aa";
                    field.Type = TType.Struct;
                    field.ID   = 1;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await Aa.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if ((Ab != null))
                {
                    field.Name = "ab";
                    field.Type = TType.Struct;
                    field.ID   = 2;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await Ab.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                await oprot.WriteFieldStopAsync(cancellationToken);

                await oprot.WriteStructEndAsync(cancellationToken);
            }
            finally
            {
                oprot.DecrementRecursionDepth();
            }
        }
Beispiel #13
0
        public static void load_xx(string file_path)
        {
            StreamReader sr = new StreamReader(file_path);

            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();
                if (line.Trim() == "")
                {
                    continue;
                }
                if (line[0] != 'L')
                {
                    continue;
                }
                string[] strs         = line.Split(new char[] { '=', '|' }, StringSplitOptions.RemoveEmptyEntries);
                string   element_name = strs[1];
                string   element_str  = strs[2];
                Config_Help.link_elements_hash[element_name] = Aa.parse_Aa_byString(element_str);
            }
            sr.Close();
        }
Beispiel #14
0
        public override string ToString()
        {
            StringBuilder __sb    = new StringBuilder("StructB(");
            bool          __first = true;

            if (Aa != null && __isset.aa)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("Aa: ");
                __sb.Append(Aa == null ? "<null>" : Aa.ToString());
            }
            if (!__first)
            {
                __sb.Append(", ");
            }
            __sb.Append("Ab: ");
            __sb.Append(Ab == null ? "<null>" : Ab.ToString());
            __sb.Append(")");
            return(__sb.ToString());
        }
Beispiel #15
0
        public static IChain ChainFromRecords(IEnumerable <AtomRecord> records, PdbLoadOptions loadOptions = PdbLoadOptions.Default, char?chainId = null)
        {
            bool wellFormatted   = (loadOptions) == PdbLoadOptions.WellFormatted;
            bool requireNCAC     = (loadOptions & PdbLoadOptions.RequireNCAC) != 0;
            bool requireNonNCAC  = (loadOptions & PdbLoadOptions.RequireNonNCAC) != 0;
            bool missingAtomsNaN = (loadOptions & PdbLoadOptions.MissingAtomsNaN) != 0;

            IEnumerable <AtomSource> allAtoms = records.Where(record => record != null).Select(record => record.ToAtom());
            IEnumerable <IGrouping <char, AtomSource> > chains = allAtoms.GroupBy(atom => atom.ChainIndex);

            foreach (IGrouping <char, AtomSource> chain in chains)
            {
                bool chainFailed   = false;
                char actualChainId = chain.Key;
                if (chainId != null && chainId != actualChainId)
                {
                    continue;
                }

                Chain peptideQuick = new Chain();
                List <IGrouping <int, AtomSource> > pdbResidues = chain.GroupBy(atom => atom.ResidueIndex).OrderBy(group => group.Key).ToList();
                foreach (IGrouping <int, AtomSource> pdbResidue in pdbResidues)
                {
                    bool       nTerminus = pdbResidue == pdbResidues.First();
                    bool       cTerminus = pdbResidue == pdbResidues.Last();
                    AtomSource N         = pdbResidue.FirstOrDefault(atom => atom.Name == "N");
                    AtomSource CA        = pdbResidue.FirstOrDefault(atom => atom.Name == "CA");
                    AtomSource C         = pdbResidue.FirstOrDefault(atom => atom.Name == "C");

                    // Get the name and create the residue
                    string name3 = pdbResidue.First().ResidueName;
                    if (name3 == "HIS") // TODO: Is this the best way of doing this?
                    {
                        if (pdbResidue.FirstOrDefault(atom => atom.Name == "HD1" || atom.Name == "1HD") != null)
                        {
                            name3 = "HID";
                        }
                        else
                        {
                            name3 = "HIE";
                        }
                    }

                    // Default to non-disulfide and then replace with disulfides when CYH are nearby with nearby SG atoms
                    if (name3 == "CYS")
                    {
                        name3 = "CYH";
                    }

                    if (!AaTable.IsResidueNameKnown(name3))
                    {
                        // TODO: Handle ions in some way
                        if ((new string[] { "ZN", "HOH", "H20", "AU", "CA", "MG", "SO4" }.Contains(name3)))
                        {
                            continue;
                        }


                        Console.WriteLine("Failing on unknown residue " + name3);
                        chainFailed = true;
                        break;
                    }
                    IAa residueQuick = new Aa(name3, nTerminus, cTerminus);

                    // Check for existence of atoms
                    if (N == null || CA == null || C == null)
                    {
                        if (requireNCAC)
                        {
                            // TODO: Tracer output
                            chainFailed = true;
                            break;
                        }
                    }
                    else if (float.IsNaN(N.XYZ.Length()) || float.IsNaN(CA.XYZ.Length()) || float.IsNaN(C.XYZ.Length()))
                    {
                        if (requireNCAC)
                        {
                            // TODO: Tracer output
                            chainFailed = true;
                            break;
                        }
                    }
                    else
                    {
                        residueQuick.AlignToNCAC(N.XYZ, CA.XYZ, C.XYZ);
                    }

                    if (missingAtomsNaN)
                    {
                        // Only explicitly PDB-defined atoms have real coordinates
                        for (int i = 0; i < residueQuick.Count; i++)
                        {
                            residueQuick[i].Xyz = new Vector3(float.NaN, float.NaN, float.NaN);
                        }
                    }

                    // Method 1
                    //foreach(AtomQuick atomQuick in residueQuick)
                    //{
                    //    AtomSource atomSource = pdbResidue.FirstOrDefault(atomPdb => atomPdb.Name == atomQuick.Name);

                    //    // Some PDBs are formatted with hydrogens like 2HD1 instead of HD12
                    //    AtomSource alternateAtomSource = null;
                    //    if(atomQuick.Name.StartsWith("H") && Char.IsNumber(atomQuick.Name.Last())) {
                    //       string alternateName = atomQuick.Name.Last() + atomQuick.Name.Substring(0, atomQuick.Name.Length - 1);
                    //       alternateAtomSource = pdbResidue.FirstOrDefault(atomPdb => atomPdb.Name == alternateName);
                    //    }

                    //    if(atomSource != null)
                    //    {
                    //        atomQuick.XYZ = atomSource.XYZ;
                    //    }
                    //    else if (alternateAtomSource != null)
                    //    {
                    //        atomQuick.XYZ = alternateAtomSource.XYZ;
                    //    }
                    //    else if (!allowMissingAtoms)
                    //    {
                    //        // TODO ... return null?
                    //        continue;
                    //    }
                    //}

                    // Method 2 - explicit atom name alternatives
                    // First pass: initialize atom locations based on exact name-matched PDB records
                    List <IAtom>      initializedAtoms   = new List <IAtom>();
                    List <AtomSource> usedSourceAtoms    = new List <AtomSource>();
                    List <IAtom>      uninitializedAtoms = new List <IAtom>(residueQuick);
                    foreach (IAtom atomQuick in residueQuick)
                    {
                        AtomSource atomSource = pdbResidue.FirstOrDefault(atomPdb => atomPdb.Name == atomQuick.Name);

                        if (atomSource != null)
                        {
                            atomQuick.Xyz = atomSource.XYZ;
                            initializedAtoms.Add(atomQuick);
                            uninitializedAtoms.Remove(atomQuick);
                            usedSourceAtoms.Add(atomSource);
                        }
                    }

                    // Second pass: try to initialize any remaining atoms from PDB records corresponding to known alternative atom names. Multiple
                    // passes are made to try to resolve the names, moving from more to less preferred.
                    int alternateAtomNamesMaxCount = alternateAtomNames_.Values.Select(value => value.Count).Max();
                    for (int nameIndex = 0; nameIndex < alternateAtomNamesMaxCount; nameIndex++)
                    {
                        foreach (Atom atomQuick in residueQuick)
                        {
                            if (initializedAtoms.Contains(atomQuick))
                            {
                                continue;
                            }

                            List <string> alternativeAtomNames = null;
                            if (!alternateAtomNames_.TryGetValue(atomQuick.Name, out alternativeAtomNames))
                            {
                                continue;
                            }
                            if (alternativeAtomNames.Count <= nameIndex)
                            {
                                continue;
                            }

                            IEnumerable <AtomSource> atomSources = pdbResidue.Where(atomPdb => alternativeAtomNames[nameIndex] == atomPdb.Name);
                            foreach (AtomSource atomSource in atomSources)
                            {
                                if (usedSourceAtoms.Contains(atomSource))
                                {
                                    continue;
                                }
                                atomQuick.Xyz = atomSource.XYZ;
                                initializedAtoms.Add(atomQuick);
                                uninitializedAtoms.Remove(atomQuick);
                                usedSourceAtoms.Add(atomSource);
                            }
                        }
                    }

                    if (initializedAtoms.Count != residueQuick.Count)
                    {
                        if (!requireNCAC && !requireNonNCAC)
                        {
                            continue;
                        }

                        IEnumerable <IAtom> uninitializedNCAC    = uninitializedAtoms.Where(atom => atom.Name == "N" || atom.Name == "CA" || atom.Name == "C").Where(atom => float.IsNaN(atom.Xyz.Length()));
                        IEnumerable <IAtom> uninitializedNonNCAC = uninitializedAtoms.Where(atom => atom.Name != "N" && atom.Name != "CA" && atom.Name != "C").Where(atom => float.IsNaN(atom.Xyz.Length()));
                        if (requireNCAC && uninitializedNCAC.Count() > 0)
                        {
                            chainFailed = true;
                            break;
                        }

                        if (requireNonNCAC && uninitializedNonNCAC.Count() > 0)
                        {
                            chainFailed = true;
                            break;
                        }

                        //// TODO: Create trace output and move this there
                        //Console.WriteLine("Failed to initialize residue " + residueQuick.Name);
                        //foreach (AtomQuick atom in uninitializedAtoms)
                        //{
                        //    Console.WriteLine(atom.Name);
                        //}

                        //chainFailed = true;
                        //break;
                    }


                    peptideQuick.Add(residueQuick);
                }

                if (!chainFailed && peptideQuick.Count > 0)
                {
                    AddDisulfides(peptideQuick);
                    return(peptideQuick);
                }
            }
            return(null);
        }
 public Bb(Aa a)
 {
 }
Beispiel #17
0
 public AbcClosable(Aa aa)
 {
     _aa = aa;
 }
Beispiel #18
0
        public static IChain GetChain(IChain[] peptides, SequenceAlignment[] alignments, Selection immutableAas)
        {
            IChain fusion = new Chain();

            // Do all pairwise analysis
            for (int i = 0; i < peptides.Length - 1; i++)
            {
                // Determine the ranges outside of the splice
                int start1 = i == 0 ? 0 : alignments[i - 1].Range2.End + 1;
                int end1   = alignments[i].Range1.Start - 1;
                int start2 = alignments[i].Range2.End + 1;
                int end2   = i < alignments.Length - 1 ? alignments[i + 1].Range1.Start - 1 : peptides[i + 1].Count - 1;

                // Add the non-overlapping region of the first peptide
                if (start1 <= end1)
                {
                    foreach (Aa aa in peptides[i][start1, end1])
                    {
                        Aa copy = new Aa(aa, i == 0 && start1 == 0, false);
                        copy.NodeTransform = aa.TotalTransform;
                        fusion.Add(copy);
                    }
                }

                // Add the alignment region, selecting either from the first or second peptide so as to minimize clashes with the sidechains that
                // are for sure being kept on either side
                SequenceAlignment alignment = alignments[i];
                Debug.Assert(alignment.Range1.Length == alignment.Range2.Length);
                for (int alignmentOffset = 0; alignmentOffset < alignment.Range1.Length; alignmentOffset++)
                {
                    int  index1    = alignment.Range1.Start + alignmentOffset;
                    int  index2    = alignment.Range2.Start + alignmentOffset;
                    IAa  option1   = peptides[i][index1];
                    IAa  option2   = peptides[i + 1][index2];
                    bool nTerminus = i == 0 && index1 == 0;
                    bool cTerminus = (i == peptides.Length - 2) && (index2 == peptides[i + 1].Count - 1);

                    if (immutableAas.Aas.Contains(option1))
                    {
                        Aa copy = new Aa(option1, nTerminus, cTerminus);
                        copy.NodeTransform = option1.TotalTransform;
                        fusion.Add(copy);
                    }
                    else if (immutableAas.Aas.Contains(option2))
                    {
                        Aa copy = new Aa(option2, nTerminus, cTerminus);
                        copy.NodeTransform = option2.TotalTransform;
                        fusion.Add(copy);
                    }
                    else
                    {
                        if (option2.Letter == 'P' && index1 >= 4)
                        {
                            SS[] ss1 = SecondaryStructure.GetPhiPsiSS(peptides[i], 5);

                            bool allHelical = (ss1[index1] | ss1[index1 - 1] | ss1[index1 - 2] | ss1[index1 - 3] | ss1[index1 - 4]) == SS.Helix;
                            if (allHelical)
                            {
                                Aa copy = new Aa(option1, nTerminus, cTerminus);
                                copy.NodeTransform = option1.TotalTransform;
                                fusion.Add(copy);
                                continue;
                            }
                        }

                        // Otherwise, select the residue with fewer clashes
                        int clashCount1 = end2 >= start2? peptides[i + 1][start2, end2].Select(other => Clash.AnyContact(other, option1, Clash.ContactType.SidechainSidechainClash) ? 1 : 0).Aggregate(0, (a, b) => a + b) : 0;
                        int clashCount2 = end1 >= start1? peptides[i][start1, end1].Select(other => Clash.AnyContact(other, option2, Clash.ContactType.SidechainSidechainClash) ? 1 : 0).Aggregate(0, (a, b) => a + b) : 0;

                        if (clashCount1 <= clashCount2)
                        {
                            Aa copy = new Aa(option1, nTerminus, cTerminus);
                            copy.NodeTransform = option1.TotalTransform;
                            fusion.Add(copy);
                            continue;
                        }

                        if (clashCount2 < clashCount1)
                        {
                            Aa copy = new Aa(option2, nTerminus, cTerminus);
                            copy.NodeTransform = option2.TotalTransform;
                            fusion.Add(copy);
                            continue;
                        }
                    }
                }

                // Add the non-overlapping region of the last peptide
                if (i == peptides.Length - 2 && start2 <= end2)
                {
                    foreach (Aa aa in peptides[i + 1][start2, end2])
                    {
                        Aa copy = new Aa(aa, false, aa.IsCTerminus);
                        copy.NodeTransform = aa.TotalTransform;
                        fusion.Add(copy);
                    }
                }
            }
            return(fusion);
        }