示例#1
0
 public DonatedSubstitutionInfo(string description, string folder, string @interface, string interfacePadded, InterfaceInterfaceData interfaceInterfaceSequenceIdentityClusteringItem)
 {
     Description     = description;
     Folder          = folder;
     Interface       = @interface;
     InterfacePadded = interfacePadded;
     InterfaceInterfaceSequenceIdentityClusteringItem = interfaceInterfaceSequenceIdentityClusteringItem;
 }
示例#2
0
        public static void Main(string[] args)
        {
            var resultsFolder = @"C:\r\";

            Directory.CreateDirectory(resultsFolder);

            var atomsFullFolder = @"C:\dbmk\atoms_all\";

            const int atom_chain     = 21;
            const int atom_chain_len = 1;

            const int atom_icode     = 26;
            const int atom_icode_len = 1;

            const int atom_type     = 14;
            const int atom_type_len = 3;

            const int atom_resseq     = 22;
            const int atom_resseq_len = 4;

            var dbmkList = File.ReadAllLines(@"c:\dbmk\dbmk-1to1-list.txt").ToList();

            dbmkList = dbmkList.Where(a => !string.IsNullOrWhiteSpace(a)).ToList();

            var structureOutputTypes = new List <string>()
            {
                "all"
            };
            var sequenceOutputTypes = new List <string> {
                "pir"
            };

            var list = new List <string>();

            foreach (var dbmkProtein in dbmkList)
            {
                var pdbId     = dbmkProtein.Substring(0, 4);
                var pdbChains = dbmkProtein.Substring(4);

                var pdbInterfaceInterfaceData = InterfaceInterfaceData.Load(@"c:\dbmk\interfaces\interface-interface_" + pdbId + ".pdb.csv");

                pdbInterfaceInterfaceData = pdbInterfaceInterfaceData.Where(a => !string.IsNullOrWhiteSpace(a.ReceptorPdbId) && !string.IsNullOrWhiteSpace(a.LigandPdbId)).ToList();
                pdbInterfaceInterfaceData = pdbInterfaceInterfaceData.Where(a => pdbChains.Contains(a.ReceptorChainId) && pdbChains.Contains(a.LigandChainId)).ToList();
                pdbInterfaceInterfaceData = pdbInterfaceInterfaceData.Where(a => ((double)a.LigandInterfaceAllAminoAcidsSuper.Length / (double)a.LigandSequenceSuper.Length) < 0.5).ToList();


                for (int index = 0; index < pdbInterfaceInterfaceData.Count; index++)
                {
                    var receptorLigandDimerA = pdbInterfaceInterfaceData[index];
                    var outputFolder         = @"c:\r\" + receptorLigandDimerA.LigandPdbId + "_" + receptorLigandDimerA.LigandChainId + "_" + (index + 1) + "_" + receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper.Length + "_" + receptorLigandDimerA.LigandSequenceSuper.Length + "_" + receptorLigandDimerA.LigandInterfaceSuperStart + "_" + receptorLigandDimerA.LigandInterfaceSuperEnd + @"\";

                    var substitutionList = new List <DonatedSubstitutionInfo>();

                    var receptorLigandDimerChainOrderA = new List <char> {
                        receptorLigandDimerA.ReceptorChainId, receptorLigandDimerA.LigandChainId
                    };


                    for (var interfacePositionIndex = 0; interfacePositionIndex <= receptorLigandDimerA.LigandSequenceSuper.Length - receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper.Length; interfacePositionIndex++)
                    {
                        var subInterface = receptorLigandDimerA.LigandSequenceSuper.Substring(interfacePositionIndex, receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper.Length);
                        var description  = "Interface Sliding Window " + interfacePositionIndex + " " + (interfacePositionIndex + subInterface.Length);
                        substitutionList.Add(new DonatedSubstitutionInfo(description, description.Replace(" ", "_"), subInterface, subInterface, receptorLigandDimerA));
                    }

                    var receptorLigandFilename = @"" + receptorLigandDimerA.LigandPdbId + ".pdb";

                    var acceptorTemplateAllAtomPdbFileData = !structureOutputTypes.Contains("all") ? null : File.ReadAllLines(atomsFullFolder + receptorLigandFilename).Where(a => a[atom_icode] == ' ' && ((a[atom_chain] == receptorLigandDimerA.ReceptorChainId) || (a[atom_chain] == receptorLigandDimerA.LigandChainId))).OrderBy(a => receptorLigandDimerChainOrderA.IndexOf(a[atom_chain])).ThenBy(a => int.Parse(a.Substring(atom_resseq, atom_resseq_len))).ToArray();

                    var monomerAcceptorTemplateLigandAllAtomPdbFile = !structureOutputTypes.Contains("all") ? null : acceptorTemplateAllAtomPdbFileData.Where(a => a[atom_icode] == ' ' && a[atom_chain] == receptorLigandDimerA.LigandChainId).OrderBy(a => receptorLigandDimerChainOrderA.IndexOf(a[atom_chain])).ThenBy(a => int.Parse(a.Substring(atom_resseq, atom_resseq_len))).ToList();

                    var receptorHeader = ">" + receptorLigandDimerA.ReceptorPdbId + ":" + receptorLigandDimerA.ReceptorChainId;
                    var ligandHeader   = ">" + receptorLigandDimerA.LigandPdbId + ":" + receptorLigandDimerA.LigandChainId;

                    var dimerAcceptorTemplateDimerSequenceSuper = new List <Sequence> {
                        new Sequence(receptorHeader, receptorLigandDimerA.ReceptorSequenceSuper), new Sequence(ligandHeader, receptorLigandDimerA.LigandSequenceSuper)
                    };

                    foreach (var sub in substitutionList)
                    {
                        // align ligand interface sequence and substitution sequence
                        var offset = AlignInside(receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper, sub.InterfacePadded);

                        if (receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper.Length < sub.InterfacePadded.Length)
                        {
                            offset = -offset;
                        }

                        var acceptorTemplateSubstitutionStart = receptorLigandDimerA.LigandInterfaceSuperStart + offset;

                        //var info = string.Join(Environment.NewLine, new string[] { "" + receptorLigandDimerA.ReceptorSequenceClusterIndex, "" + receptorLigandDimerA.ReceptorInterfaceSequenceClusterIndex, "" + receptorLigandDimerA.LigandSequenceClusterIndex, "" + receptorLigandDimerA.LigandInterfaceSequenceClusterIndex, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.ReceptorSequenceClusterIndex, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.ReceptorInterfaceSequenceClusterIndex, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.LigandSequenceClusterIndex, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.LigandInterfaceSequenceClusterIndex, receptorLigandDimerA.ReceptorPdbId, "" + receptorLigandDimerA.ReceptorChainId, receptorLigandDimerA.LigandPdbId, "" + receptorLigandDimerA.LigandChainId, sub.InterfaceInterfaceSequenceIdentityClusteringItem.ReceptorPdbId, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.ReceptorChainId, sub.InterfaceInterfaceSequenceIdentityClusteringItem.LigandPdbId, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.LigandChainId, sub.Description, receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper, sub.Interface, sub.InterfacePadded });

                        var modelOutputFolder = outputFolder + sub.Folder + @"\";
                        Directory.CreateDirectory(modelOutputFolder);

                        //File.WriteAllText(modelOutputFolder + "substitution.log", info);

                        if (structureOutputTypes.Contains("all"))
                        {
                            File.WriteAllLines(modelOutputFolder + "template_ligand_all.pdb", monomerAcceptorTemplateLigandAllAtomPdbFile);
                        }

                        var mutatedLigandSequenceSubLigand = new Sequence(ligandHeader, receptorLigandDimerA.LigandSequenceSuper.Remove(acceptorTemplateSubstitutionStart, sub.InterfacePadded.Length).Insert(acceptorTemplateSubstitutionStart, sub.InterfacePadded));


                        var dimerSequenceAfterSubstitution = dimerAcceptorTemplateDimerSequenceSuper.Select(a => a.Id == ligandHeader ? mutatedLigandSequenceSubLigand : a).ToList();

                        if (sequenceOutputTypes.Contains("pir"))
                        {
                            File.WriteAllText(modelOutputFolder + "template_ligand_after_substitution.ali", Sequence.GetFormattedSequence(mutatedLigandSequenceSubLigand, Sequence.SequenceFormat.Pir));
                        }
                    }
                }
            }
        }
        public static void Main(string[] args)
        {
            var resultsFolder = @"C:\r\";

            Directory.CreateDirectory(resultsFolder);

            //var clustersCsvFile = @"C:\CategoryM\catm_combined_data.csv";

            //var atomsCaTraceFolder = @"C:\dbmk\atoms_ca\";
            //var atomsBackBoneFolder = @"C:\dbmk\atoms_mc\";
            //var atomsSideChainFolder = @"C:\dbmk\atoms_sc\";
            var atomsFullFolder = @"C:\dbmk\atoms_all\";

            const int atom_chain     = 21;
            const int atom_chain_len = 1;

            const int atom_icode     = 26;
            const int atom_icode_len = 1;

            const int atom_type     = 14;
            const int atom_type_len = 3;

            const int atom_resseq     = 22;
            const int atom_resseq_len = 4;

            /*
             * var data = InterfaceInterfaceData.Load(clustersCsvFile);
             *
             * // interfaces with length at least five
             * data = data.Where(a => a.ReceptorInterfaceResSeqLength >= 5 && a.LigandInterfaceResSeqLength >= 5).ToList();
             *
             * data = data.Where(a => char.IsLetterOrDigit(a.ReceptorChainId) && char.IsLetterOrDigit(a.LigandChainId)).ToList();
             *
             * // ensure pdbids are uppercase
             * foreach (var d in data)
             * {
             *  d.ReceptorPdbId = d.ReceptorPdbId.ToUpperInvariant();
             *  d.LigandPdbId = d.LigandPdbId.ToUpperInvariant();
             * }
             */
            var scripts = new List <string>();
            //scripts.AddRange(Directory.GetFiles(@"c:\modeller_scripts\", "*.py*", SearchOption.AllDirectories));
            //scripts.AddRange(Directory.GetFiles(@"c:\modeller_scripts\", "*.bat", SearchOption.AllDirectories));
            //scripts.AddRange(Directory.GetFiles(@"c:\modeller_scripts\", "*.html*", SearchOption.AllDirectories));



            var dbmkList = File.ReadAllLines(@"c:\dbmk\dbmk-1to1-list.txt").ToList();

            dbmkList = dbmkList.Where(a => !string.IsNullOrWhiteSpace(a)).ToList();


            var scriptsText = scripts.Select(a => new Tuple <string, string>(a, File.ReadAllText(a))).ToList();

            /*
             * var dataGroupedByReceptorClusterIndex = data.GroupBy(a => a.ReceptorConsensusClusterIndex).Select(a => a.ToList()).ToList();
             * var dataGroupedByReceptorClusterIndexAndInterfaceOverlap = new List<List<InterfaceInterfaceData>>();
             *
             * foreach (var l in dataGroupedByReceptorClusterIndex)
             * {
             *  var overlapClusters = l.Select(a => new List<InterfaceInterfaceData> { a }).ToList();
             *
             *  foreach (var a in l)
             *  {
             *      foreach (var b in l)
             *      {
             *          if (a == b) continue;
             *
             *          var seqLenDiff = Math.Abs(Sequence.TrimSequence(a.ReceptorSequenceFromSequenceFile).Length - Sequence.TrimSequence(b.ReceptorSequenceFromSequenceFile).Length);
             *
             *
             *          var maxMultiBindDist = -seqLenDiff;
             *          maxMultiBindDist--;
             *
             *          var o = ProteinBioClass.InterfaceOverlap(a.ReceptorInterfaceResSeqStart, a.ReceptorInterfaceResSeqEnd, b.ReceptorInterfaceResSeqStart, b.ReceptorInterfaceResSeqEnd);
             *
             *          if (o >= maxMultiBindDist || a.ReceptorInterfaceSequenceClusterIndex == b.ReceptorInterfaceSequenceClusterIndex)
             *          {
             *              var aCluster = overlapClusters.First(c => c.Contains(a));
             *              var bCluster = overlapClusters.First(c => c.Contains(b));
             *              if (aCluster == bCluster) continue;
             *              aCluster.AddRange(bCluster);
             *              overlapClusters.Remove(bCluster);
             *          }
             *      }
             *  }
             *
             *  dataGroupedByReceptorClusterIndexAndInterfaceOverlap.AddRange(overlapClusters);
             * }
             *
             * // make sure cluster has more than 1 pdb id
             * dataGroupedByReceptorClusterIndexAndInterfaceOverlap = dataGroupedByReceptorClusterIndexAndInterfaceOverlap.Where(a => a.Select(b => b.ReceptorPdbId).Distinct().Count() > 1).ToList();
             */

            var structureOutputTypes = new List <string>()
            {
                "all"
            };
            var sequenceOutputTypes = new List <string> {
                "pir"
            };
            //var calculateReversed = true;

            var list = new List <string>();

            foreach (var dbmkProtein in dbmkList)
            {
                var pdbId     = dbmkProtein.Substring(0, 4);
                var pdbChains = dbmkProtein.Substring(4);

                var pdbInterfaceInterfaceData = InterfaceInterfaceData.Load(@"c:\dbmk\interfaces\interface-interface_" + pdbId + ".pdb.csv");

                pdbInterfaceInterfaceData = pdbInterfaceInterfaceData.Where(a => !string.IsNullOrWhiteSpace(a.ReceptorPdbId) && !string.IsNullOrWhiteSpace(a.LigandPdbId)).ToList();
                pdbInterfaceInterfaceData = pdbInterfaceInterfaceData.Where(a => pdbChains.Contains(a.ReceptorChainId) && pdbChains.Contains(a.LigandChainId)).ToList();
                pdbInterfaceInterfaceData = pdbInterfaceInterfaceData.Where(a => ((double)a.LigandInterfaceAllAminoAcidsSuper.Length / (double)a.LigandSequenceSuper.Length) < 0.5).ToList();


                for (int index = 0; index < pdbInterfaceInterfaceData.Count; index++)
                {
                    var receptorLigandDimerA = pdbInterfaceInterfaceData[index];
                    var outputFolder         = @"c:\r\" + receptorLigandDimerA.LigandPdbId + "_" + receptorLigandDimerA.LigandChainId + "_" + (index + 1) + "_" + receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper.Length + "_" + receptorLigandDimerA.LigandSequenceSuper.Length + "_" + receptorLigandDimerA.LigandInterfaceSuperStart + "_" + receptorLigandDimerA.LigandInterfaceSuperEnd + @"\";

                    //list.Add(outputFolder);
                    //continue;

                    var substitutionList = new List <DonatedSubstitutionInfo>();

                    var receptorLigandDimerChainOrderA = new List <char> {
                        receptorLigandDimerA.ReceptorChainId, receptorLigandDimerA.LigandChainId
                    };


                    for (var interfacePositionIndex = 0; interfacePositionIndex <= receptorLigandDimerA.LigandSequenceSuper.Length - receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper.Length; interfacePositionIndex++)
                    {
                        var subInterface = receptorLigandDimerA.LigandSequenceSuper.Substring(interfacePositionIndex, receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper.Length);
                        var description  = "Interface Sliding Window " + interfacePositionIndex + " " + (interfacePositionIndex + subInterface.Length);
                        substitutionList.Add(new DonatedSubstitutionInfo(description, description.Replace(" ", "_"), subInterface, subInterface, receptorLigandDimerA));
                    }


                    var receptorLigandFilename = @"" + receptorLigandDimerA.LigandPdbId + ".pdb";

                    var acceptorTemplateAllAtomPdbFileData = !structureOutputTypes.Contains("all") ? null : File.ReadAllLines(atomsFullFolder + receptorLigandFilename).Where(a => a[atom_icode] == ' ' && ((a[atom_chain] == receptorLigandDimerA.ReceptorChainId) || (a[atom_chain] == receptorLigandDimerA.LigandChainId))).OrderBy(a => receptorLigandDimerChainOrderA.IndexOf(a[atom_chain])).ThenBy(a => int.Parse(a.Substring(atom_resseq, atom_resseq_len))).ToArray();

                    // monomer
                    //var monomerAcceptorTemplateReceptorAllAtomPdbFile = !structureOutputTypes.Contains("all") ? null : acceptorTemplateAllAtomPdbFileData.Where(a => a[atom_icode] == ' ' && a[atom_chain] == receptorLigandDimerA.ReceptorChainId).OrderBy(a => receptorLigandDimerChainOrderA.IndexOf(a[atom_chain])).ThenBy(a => int.Parse(a.Substring(atom_resseq, atom_resseq_len))).ToList();

                    var monomerAcceptorTemplateLigandAllAtomPdbFile = !structureOutputTypes.Contains("all") ? null : acceptorTemplateAllAtomPdbFileData.Where(a => a[atom_icode] == ' ' && a[atom_chain] == receptorLigandDimerA.LigandChainId).OrderBy(a => receptorLigandDimerChainOrderA.IndexOf(a[atom_chain])).ThenBy(a => int.Parse(a.Substring(atom_resseq, atom_resseq_len))).ToList();


                    // dimer
                    //var dimerAcceptorTemplateDimerAllAtomPdbFile = !structureOutputTypes.Contains("all") ? null : acceptorTemplateAllAtomPdbFileData.Where(a => a[atom_icode] == ' ' && (a[atom_chain] == receptorLigandDimerA.ReceptorChainId || a[atom_chain] == receptorLigandDimerA.LigandChainId)).OrderBy(a => receptorLigandDimerChainOrderA.IndexOf(a[atom_chain])).ThenBy(a => int.Parse(a.Substring(atom_resseq, atom_resseq_len))).ToList();

                    var receptorHeader = ">" + receptorLigandDimerA.ReceptorPdbId + ":" + receptorLigandDimerA.ReceptorChainId;
                    var ligandHeader   = ">" + receptorLigandDimerA.LigandPdbId + ":" + receptorLigandDimerA.LigandChainId;

                    //var monomerAcceptorTemplateLigandSequenceSuper = new Sequence(ligandHeader, receptorLigandDimerA.LigandSequenceSuper);

                    var dimerAcceptorTemplateDimerSequenceSuper = new List <Sequence> {
                        new Sequence(receptorHeader, receptorLigandDimerA.ReceptorSequenceSuper), new Sequence(ligandHeader, receptorLigandDimerA.LigandSequenceSuper)
                    };


                    /*
                     * var dimerAcceptorTemplateDimerSequenceSuperLocked = new List<Sequence>
                     *                                            {
                     *                                                new Sequence(receptorHeader, new string('-',receptorLigandDimerA.ReceptorSequenceSuper.Length)),
                     *                                                new Sequence(ligandHeader, new string('-',receptorLigandDimerA.LigandSequenceSuper.Length))
                     *                                            };
                     */

                    foreach (var sub in substitutionList)
                    {
                        // align ligand interface sequence and substitution sequence
                        var offset = AlignInside(receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper, sub.InterfacePadded);

                        if (receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper.Length < sub.InterfacePadded.Length)
                        {
                            offset = -offset;
                        }

                        var acceptorTemplateSubstitutionStart = receptorLigandDimerA.LigandInterfaceSuperStart + offset;
                        //var acceptorTemplateSubstitutionEnd = (acceptorTemplateSubstitutionStart + sub.InterfacePadded.Length) - 1;

                        var info = string.Join(Environment.NewLine, new string[] { "" + receptorLigandDimerA.ReceptorSequenceClusterIndex, "" + receptorLigandDimerA.ReceptorInterfaceSequenceClusterIndex, "" + receptorLigandDimerA.LigandSequenceClusterIndex, "" + receptorLigandDimerA.LigandInterfaceSequenceClusterIndex, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.ReceptorSequenceClusterIndex, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.ReceptorInterfaceSequenceClusterIndex, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.LigandSequenceClusterIndex, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.LigandInterfaceSequenceClusterIndex, receptorLigandDimerA.ReceptorPdbId, "" + receptorLigandDimerA.ReceptorChainId, receptorLigandDimerA.LigandPdbId, "" + receptorLigandDimerA.LigandChainId, sub.InterfaceInterfaceSequenceIdentityClusteringItem.ReceptorPdbId, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.ReceptorChainId, sub.InterfaceInterfaceSequenceIdentityClusteringItem.LigandPdbId, "" + sub.InterfaceInterfaceSequenceIdentityClusteringItem.LigandChainId, sub.Description, receptorLigandDimerA.LigandInterfaceAllAminoAcidsSuper, sub.Interface, sub.InterfacePadded });


                        //var monomerAcceptorTemplateFragmentLigandCaTracePdbFile = !structureOutputTypes.Contains("ca") ? null : monomerAcceptorTemplateLigandCaTracePdbFile.Where(a => int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= acceptorTemplateSubstitutionStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= acceptorTemplateSubstitutionEnd).ToList();
                        //var monomerAcceptorTemplateFragmentLigandBackBonePdbFile = !structureOutputTypes.Contains("mc") ? null : monomerAcceptorTemplateLigandBackBonePdbFile.Where(a => int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= acceptorTemplateSubstitutionStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= acceptorTemplateSubstitutionEnd).ToList();
                        //var monomerAcceptorTemplateFragmentLigandSideChainPdbFile = !structureOutputTypes.Contains("sc") ? null : monomerAcceptorTemplateLigandSideChainPdbFile.Where(a => int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= acceptorTemplateSubstitutionStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= acceptorTemplateSubstitutionEnd).ToList();
                        //var monomerAcceptorTemplateFragmentLigandAllAtomPdbFile = !structureOutputTypes.Contains("all") ? null : monomerAcceptorTemplateLigandAllAtomPdbFile.Where(a => int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= acceptorTemplateSubstitutionStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= acceptorTemplateSubstitutionEnd).ToList();

                        //var dimerAcceptorTemplateFragmentDimerCaTracePdbFile = !structureOutputTypes.Contains("ca") ? null : dimerAcceptorTemplateDimerCaTracePdbFile.Where(a => (a[atom_chain] == receptorLigandDimerA.ReceptorChainId && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= receptorLigandDimerA.ReceptorInterfaceResSeqStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= receptorLigandDimerA.ReceptorInterfaceResSeqEnd) || (a[atom_chain] == receptorLigandDimerA.LigandChainId && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= acceptorTemplateSubstitutionStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= acceptorTemplateSubstitutionEnd)).ToList();
                        //var dimerAcceptorTemplateFragmentDimerBackBonePdbFile = !structureOutputTypes.Contains("mc") ? null : dimerAcceptorTemplateDimerBackBonePdbFile.Where(a => (a[atom_chain] == receptorLigandDimerA.ReceptorChainId && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= receptorLigandDimerA.ReceptorInterfaceResSeqStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= receptorLigandDimerA.ReceptorInterfaceResSeqEnd) || (a[atom_chain] == receptorLigandDimerA.LigandChainId && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= acceptorTemplateSubstitutionStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= acceptorTemplateSubstitutionEnd)).ToList();
                        //var dimerAcceptorTemplateFragmentDimerSideChainPdbFile = !structureOutputTypes.Contains("sc") ? null : dimerAcceptorTemplateDimerSideChainPdbFile.Where(a => (a[atom_chain] == receptorLigandDimerA.ReceptorChainId && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= receptorLigandDimerA.ReceptorInterfaceResSeqStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= receptorLigandDimerA.ReceptorInterfaceResSeqEnd) || (a[atom_chain] == receptorLigandDimerA.LigandChainId && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= acceptorTemplateSubstitutionStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= acceptorTemplateSubstitutionEnd)).ToList();
                        //var dimerAcceptorTemplateFragmentDimerAllAtomPdbFile = !structureOutputTypes.Contains("all") ? null : dimerAcceptorTemplateDimerAllAtomPdbFile.Where(a => (a[atom_chain] == receptorLigandDimerA.ReceptorChainId && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= receptorLigandDimerA.ReceptorInterfaceResSeqStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= receptorLigandDimerA.ReceptorInterfaceResSeqEnd) || (a[atom_chain] == receptorLigandDimerA.LigandChainId && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) >= acceptorTemplateSubstitutionStart && int.Parse(a.Substring(atom_resseq, atom_resseq_len)) <= acceptorTemplateSubstitutionEnd)).ToList();

                        var modelOutputFolder = outputFolder + sub.Folder + @"\";
                        Directory.CreateDirectory(modelOutputFolder);
                        //scriptsText.ForEach(a => File.WriteAllText(modelOutputFolder + Path.GetFileName(a.Item1), a.Item2.Replace("%%chain%%", "" + receptorLigandDimerA.LigandChainId)));

                        File.WriteAllText(modelOutputFolder + "substitution.log", info);


                        if (structureOutputTypes.Contains("all"))
                        {
                            File.WriteAllLines(modelOutputFolder + "template_ligand_all.pdb", monomerAcceptorTemplateLigandAllAtomPdbFile);
                        }

                        //if (structureOutputTypes.Contains("all")) File.WriteAllLines(modelOutputFolder + "template_dimer_all.pdb", dimerAcceptorTemplateDimerAllAtomPdbFile);


                        //if (structureOutputTypes.Contains("all")) File.WriteAllLines(modelOutputFolder + "template_locked_ligand_all.pdb", monomerAcceptorTemplateLigandAllAtomPdbFile);

                        //if (structureOutputTypes.Contains("all")) File.WriteAllLines(modelOutputFolder + "template_locked_dimer_all.pdb", dimerAcceptorTemplateDimerAllAtomPdbFile);


                        //if (structureOutputTypes.Contains("all")) File.WriteAllLines(modelOutputFolder + "template_fragment_ligand_all.pdb", monomerAcceptorTemplateFragmentLigandAllAtomPdbFile);

                        //if (structureOutputTypes.Contains("all")) File.WriteAllLines(modelOutputFolder + "template_fragment_dimer_all.pdb", dimerAcceptorTemplateFragmentDimerAllAtomPdbFile);

                        /*
                         * var mutatedLigandSequenceLocked =
                         *  new Sequence(ligandHeader,
                         *
                         *  new string('-', receptorLigandDimerA.LigandSequenceSuper.Length)
                         *  .Remove(acceptorTemplateSubstitutionStart, sub.InterfacePadded.Length)
                         *  .Insert(acceptorTemplateSubstitutionStart, sub.InterfacePadded));
                         */

                        var mutatedLigandSequenceSubLigand = new Sequence(ligandHeader, receptorLigandDimerA.LigandSequenceSuper.Remove(acceptorTemplateSubstitutionStart, sub.InterfacePadded.Length).Insert(acceptorTemplateSubstitutionStart, sub.InterfacePadded));


                        var dimerSequenceAfterSubstitution = dimerAcceptorTemplateDimerSequenceSuper.Select(a => a.Id == ligandHeader ? mutatedLigandSequenceSubLigand : a).ToList();
                        //var dimerSequenceAfterSubstitutionLocked = dimerAcceptorTemplateDimerSequenceSuperLocked.Select(a => a.Id == ligandHeader ? mutatedLigandSequenceLocked : a).ToList();

                        /*
                         * var mutatedMonomerAcceptorTemplateFragmentLigandSequenceSuper = new List<Sequence>
                         *                                        {
                         *                                            new Sequence(ligandHeader, sub.InterfacePadded)
                         *                                        };
                         */
                        /*
                         * var mutatedDimerAcceptorTemplateFragmentDimerSequenceSuper = new List<Sequence>
                         *                                        {
                         *                                            new Sequence(receptorHeader, receptorLigandDimerA.ReceptorInterfaceAllAminoAcidsSuper),
                         *                                            new Sequence(ligandHeader, sub.InterfacePadded)
                         *                                        };
                         */

                        // save before
                        //if (sequenceOutputTypes.Contains("pir"))   File.WriteAllText(modelOutputFolder + "template_ligand_before_substitution.ali", Sequence.GetFormattedSequence(monomerAcceptorTemplateLigandSequenceSuper, Sequence.SequenceFormat.Pir));
                        //if (sequenceOutputTypes.Contains("fasta")) File.WriteAllText(modelOutputFolder + "template_ligand_before_substitution.fasta", Sequence.GetFormattedSequence(monomerAcceptorTemplateLigandSequenceSuper, Sequence.SequenceFormat.Fasta));
                        if (sequenceOutputTypes.Contains("pir"))
                        {
                            File.WriteAllText(modelOutputFolder + "template_ligand_after_substitution.ali", Sequence.GetFormattedSequence(mutatedLigandSequenceSubLigand, Sequence.SequenceFormat.Pir));
                        }
                        //if (sequenceOutputTypes.Contains("fasta")) File.WriteAllText(modelOutputFolder + "template_ligand_after_substitution.fasta", Sequence.GetFormattedSequence(mutatedLigandSequenceSubLigand, Sequence.SequenceFormat.Fasta));

                        //if (sequenceOutputTypes.Contains("pir")) File.WriteAllText(modelOutputFolder +   "template_dimer_before_substitution.ali", Sequence.GetFormattedSequence(dimerAcceptorTemplateDimerSequenceSuper, Sequence.SequenceFormat.Pir, ligandHeader));
                        //if (sequenceOutputTypes.Contains("fasta")) File.WriteAllText(modelOutputFolder + "template_dimer_before_substitution.fasta", Sequence.GetFormattedSequence(dimerAcceptorTemplateDimerSequenceSuper, Sequence.SequenceFormat.Fasta, ligandHeader));
                        //if (sequenceOutputTypes.Contains("pir")) File.WriteAllText(modelOutputFolder +   "template_dimer_after_substitution.ali", Sequence.GetFormattedSequence(dimerSequenceAfterSubstitution, Sequence.SequenceFormat.Pir, ligandHeader));
                        //if (sequenceOutputTypes.Contains("fasta")) File.WriteAllText(modelOutputFolder + "template_dimer_after_substitution.fasta", Sequence.GetFormattedSequence(dimerSequenceAfterSubstitution, Sequence.SequenceFormat.Fasta));

                        //if (sequenceOutputTypes.Contains("pir"))   File.WriteAllText(modelOutputFolder + "template_fragment_ligand_after_substitution.ali", Sequence.GetFormattedSequence(mutatedMonomerAcceptorTemplateFragmentLigandSequenceSuper, Sequence.SequenceFormat.Pir, ligandHeader));
                        //if (sequenceOutputTypes.Contains("fasta")) File.WriteAllText(modelOutputFolder + "template_fragment_ligand_after_substitution.fasta", Sequence.GetFormattedSequence(mutatedMonomerAcceptorTemplateFragmentLigandSequenceSuper, Sequence.SequenceFormat.Fasta));
                        //if (sequenceOutputTypes.Contains("pir"))   File.WriteAllText(modelOutputFolder + "template_fragment_dimer_after_substitution.ali", Sequence.GetFormattedSequence(mutatedDimerAcceptorTemplateFragmentDimerSequenceSuper, Sequence.SequenceFormat.Pir, ligandHeader));
                        //if (sequenceOutputTypes.Contains("fasta")) File.WriteAllText(modelOutputFolder + "template_fragment_dimer_after_substitution.fasta", Sequence.GetFormattedSequence(mutatedDimerAcceptorTemplateFragmentDimerSequenceSuper, Sequence.SequenceFormat.Fasta));

                        //if (sequenceOutputTypes.Contains("pir"))   File.WriteAllText(modelOutputFolder + "template_locked_ligand_after_substitution.ali", Sequence.GetFormattedSequence(mutatedLigandSequenceLocked, Sequence.SequenceFormat.Pir));
                        //if (sequenceOutputTypes.Contains("fasta")) File.WriteAllText(modelOutputFolder + "template_locked_ligand_after_substitution.fasta", Sequence.GetFormattedSequence(mutatedLigandSequenceLocked, Sequence.SequenceFormat.Fasta));
                        //if (sequenceOutputTypes.Contains("pir"))   File.WriteAllText(modelOutputFolder + "template_locked_dimer_after_substitution.ali", Sequence.GetFormattedSequence(dimerSequenceAfterSubstitutionLocked, Sequence.SequenceFormat.Pir, ligandHeader));
                        //if (sequenceOutputTypes.Contains("fasta")) File.WriteAllText(modelOutputFolder + "template_locked_dimer_after_substitution.fasta", Sequence.GetFormattedSequence(dimerSequenceAfterSubstitutionLocked, Sequence.SequenceFormat.Fasta));
                    }
                }
            }
            //File.WriteAllLines(@"c:\r\list.csv", list);

            /*
             * var batches = new Dictionary<string, string[]>
             *            {
             *  //{ resultsFolder + @"call_fs_modeller_monomer_full.bat", Directory.GetFiles(resultsFolder, @"modeller_monomer_full.bat", SearchOption.AllDirectories).Where(a => Path.GetDirectoryName(a).Contains("Full Structure")).ToArray()},
             *  //{ resultsFolder + @"call_fs_modeller_dimer_full.bat", Directory.GetFiles(resultsFolder, @"modeller_dimer_full.bat", SearchOption.AllDirectories).Where(a => Path.GetDirectoryName(a).Contains("Full Structure")).ToArray()},
             *  { resultsFolder + @"call_fs_modeller_monomer_and_dimer_full.bat", Directory.GetFiles(resultsFolder, @"modeller_monomer_and_dimer_full.bat", SearchOption.AllDirectories).Where(a => Path.GetDirectoryName(a).Contains("Full Structure")).ToArray()},
             *  { resultsFolder + @"call_fs_pymol_images.bat", Directory.GetFiles(resultsFolder, @"pymol_images.bat", SearchOption.AllDirectories).Where(a => Path.GetDirectoryName(a).Contains("Full Structure")).ToArray()}
             *            };
             *
             * foreach (var batch in batches)
             * {
             *  var outputCmds = new List<string>();
             *
             *  outputCmds.Add(@"echo Running """ + Path.GetFileName(batch.Key) + @"""");
             *
             *  for (var index = 0; index < batch.Value.Length; index++)
             *  {
             *      var file = batch.Value[index];
             *      var pct = (index + 1) / (decimal)batch.Value.Length;
             *
             *      outputCmds.Add(@"echo Processing """ + Path.GetDirectoryName(file) + @""" " + (index + 1) + "/" + batch.Value.Length + " (" + Math.Round(pct * 100, 2) + "%)");
             *      outputCmds.Add(@"cd """ + Path.GetDirectoryName(file) + @"""");
             *      outputCmds.Add(@"echo Calling """ + Path.GetFileName(file) + @"""");
             *      outputCmds.Add(@"call """ + file + @"""");
             *      outputCmds.Add(@"");
             *  }
             *  outputCmds.Add(@"pause");
             *  outputCmds.Add(@"");
             *
             *  File.WriteAllLines(batch.Key, outputCmds);
             * }
             */
        }