Ejemplo n.º 1
0
        public static string GetStructureInchiKey(string _molfilestring)
        {
            string strInchiKey = "Inchi Not generated";

            try
            {
                MolHandler mHandler = new MolHandler(_molfilestring);
                Molecule   mol      = mHandler.getMolecule();
                try
                {
                    strInchiKey = mol.toFormat("inchi:key");
                }
                catch //Exception is inchi not generated
                {
                    // if inchi not generated
                    SetMolAbsStereo_Inchi_NotGenerated(ref mol);

                    strInchiKey = mol.toFormat("inchi:key");
                }
                if (strInchiKey != "")
                {
                    strInchiKey = Validations.GetInchiKeyFromInchiString(strInchiKey);
                }

                return(strInchiKey);
            }
            catch (Exception ex)
            {
                ErrorHandling_NTS.WriteErrorLog(ex.ToString());
            }
            return(strInchiKey);
        }
Ejemplo n.º 2
0
        public static bool DeleteAllDuplicateStructures(string filename, out int totalreccnt, out int dupreccnt)
        {
            bool blStatus       = false;
            int  intDupRecCnt   = 0;
            int  intTotalRecCnt = 0;

            try
            {
                MolInputStream molInStream = new MolInputStream(new FileInputStream(filename));
                MolImporter    molImp      = new MolImporter(molInStream);
                Molecule       objMol      = new Molecule();

                DataOutputStream dOutStream = new DataOutputStream(new FileOutputStream(filename));
                MolExporter      molExpt    = new MolExporter(dOutStream, "sdf");

                bool   blIsChiral  = false;
                string strInchiKey = "";

                ArrayList molInchiList = new ArrayList();

                while (molImp.read(objMol))
                {
                    objMol = StandardizeMolecule(objMol, out blIsChiral);

                    strInchiKey = objMol.toFormat("inchi:key");
                    strInchiKey = Validations.GetInchiKeyFromInchiString(strInchiKey);

                    if (!molInchiList.Contains(strInchiKey))
                    {
                        molInchiList.Add(strInchiKey);
                        molExpt.write(objMol);
                    }
                    else
                    {
                        intDupRecCnt++;
                    }
                    intTotalRecCnt++;
                }
                //Close all the import & export objects
                molImp.close();
                molInStream.close();
                dOutStream.close();
                molExpt.close();

                blStatus = true;
            }
            catch (Exception ex)
            {
                ErrorHandling_NTS.WriteErrorLog(ex.ToString());
            }
            totalreccnt = intTotalRecCnt;
            dupreccnt   = intDupRecCnt;
            return(blStatus);
        }
Ejemplo n.º 3
0
        public static bool CheckForDuplicateStructure(string filename, string qrymolfile, int recindex, out Molecule mol_out)
        {
            bool blStatus = false;

            try
            {
                bool blIsChiral = false;

                MolHandler mHandler = new MolHandler(qrymolfile);
                Molecule   qryMol   = mHandler.getMolecule();
                qryMol = StandardizeMolecule(qryMol, out blIsChiral);

                string strqryMolInchi = qryMol.toFormat("inchi:key");
                strqryMolInchi = Validations.GetInchiKeyFromInchiString(strqryMolInchi);

                //Specify input file to MolInputStream object
                MolInputStream molInStream = new MolInputStream(new FileInputStream(filename));
                MolImporter    molImp      = new MolImporter(molInStream);
                Molecule       objMol      = new Molecule();

                blIsChiral = false;
                string strInchiKey = "";
                int    intRecIndx  = 0;

                Molecule molObj_Stand = null;
                while (molImp.read(objMol))
                {
                    molObj_Stand = StandardizeMolecule(objMol, out blIsChiral);

                    strInchiKey = objMol.toFormat("inchi:key");
                    strInchiKey = Validations.GetInchiKeyFromInchiString(strInchiKey);

                    intRecIndx++;

                    if ((strInchiKey == strqryMolInchi) && (intRecIndx != recindex))
                    {
                        blStatus = true;
                        mol_out  = objMol;
                        return(blStatus);
                    }
                }

                molImp.close();
                molInStream.close();
            }
            catch (Exception ex)
            {
                ErrorHandling_NTS.WriteErrorLog(ex.ToString());
            }
            mol_out = null;
            return(blStatus);
        }
Ejemplo n.º 4
0
        public static int GetDuplicateRecordsCount(string filename, out int totalreccnt)
        {
            int intDupRecCnt   = 0;
            int intTotalRecCnt = 0;

            try
            {
                MolInputStream molInStream = new MolInputStream(new FileInputStream(filename));
                MolImporter    molImp      = new MolImporter(molInStream);
                Molecule       objMol      = new Molecule();

                bool   blIsChiral  = false;
                string strInchiKey = "";

                ArrayList molInchiList = new ArrayList();

                while (molImp.read(objMol))
                {
                    objMol = StandardizeMolecule(objMol, out blIsChiral);

                    strInchiKey = objMol.toFormat("inchi:key");
                    strInchiKey = Validations.GetInchiKeyFromInchiString(strInchiKey);

                    if (!molInchiList.Contains(strInchiKey))
                    {
                        molInchiList.Add(strInchiKey);
                    }
                    else
                    {
                        intDupRecCnt++;
                    }
                    intTotalRecCnt++;
                }

                molImp.close();
                molInStream.close();
            }
            catch (Exception ex)
            {
                ErrorHandling_NTS.WriteErrorLog(ex.ToString());
            }
            totalreccnt = intTotalRecCnt;
            return(intDupRecCnt);
        }
Ejemplo n.º 5
0
        public static DataTable GetDuplicateRecords(string filename, string qrymolstring, out int totalrecs_out)
        {
            DataTable dtDupRecs   = null;
            int       totalRecCnt = 0;

            try
            {
                dtDupRecs = CreateTANDetailsTable();

                dtDupRecs.Columns.Add("OrigRecIndex", typeof(Int32));

                bool   blIsChiral    = false;
                string InchiKey_Qry  = "";
                string InchiKey_Trgt = "";

                MolHandler mHandler = new MolHandler(qrymolstring);
                Molecule   qryMol   = mHandler.getMolecule();
                StandardizeMolecule(qryMol, out blIsChiral);

                InchiKey_Qry = qryMol.toFormat("inchi:key");
                InchiKey_Qry = Validations.GetInchiKeyFromInchiString(InchiKey_Qry);

                MolInputStream molInStream = new MolInputStream(new FileInputStream(filename));
                MolImporter    molImp      = new MolImporter(molInStream);
                Molecule       objMol      = new Molecule();

                DataRow dtRow = null;

                while (molImp.read(objMol))
                {
                    objMol = StandardizeMolecule(objMol, out blIsChiral);

                    InchiKey_Trgt = objMol.toFormat("inchi:key");
                    InchiKey_Trgt = Validations.GetInchiKeyFromInchiString(InchiKey_Trgt);

                    if (InchiKey_Qry == InchiKey_Trgt)
                    {
                        dtRow = dtDupRecs.NewRow();

                        //Mol Structure
                        dtRow["Structure"] = objMol.toFormat("mol");

                        //Mol Weight
                        dtRow["MolWeight"] = objMol.getMass().ToString();

                        //Mol Formula
                        dtRow["MolFormula"] = objMol.getFormula();

                        //Page No
                        dtRow["PageNumber"] = objMol.getProperty("Page Number").Trim();

                        //Page Label
                        dtRow["PageLabel"] = objMol.getProperty("Page Label").Trim();

                        //Example Number
                        dtRow["ExampleNumber"] = objMol.getProperty("Example Number").Trim();

                        //IUPAC Name
                        dtRow["IupacName"] = objMol.getProperty("IUPAC Name").Trim();

                        //en name
                        dtRow["EnName"] = objMol.getProperty("en name").Trim();

                        //Is Chiral
                        if (objMol.isAbsStereo())
                        {
                            dtRow["IsChiral"] = "True";
                        }
                        else
                        {
                            dtRow["IsChiral"] = "False";
                        }

                        dtRow["OrigRecIndex"] = totalRecCnt;

                        dtDupRecs.Rows.Add(dtRow);
                    }
                    totalRecCnt++;
                }
                molImp.close();
                molInStream.close();

                totalrecs_out = totalRecCnt;
                return(dtDupRecs);
            }
            catch (Exception ex)
            {
                ErrorHandling_NTS.WriteErrorLog(ex.ToString());
            }
            totalrecs_out = totalRecCnt;
            return(dtDupRecs);
        }