예제 #1
0
/// <summary>
/// Execute structure search for structures stored in an Oracle text column
/// </summary>
/// <param name="sql">Basic sql to select key & structure</param>

        public void ExecuteInternalOracleStructureColumnSearch(
            string sql,
            MoleculeFormat structureFormat)
        {
            string cid, molString;

            object[]   vo;
            MoleculeMx cs;
            bool       match = false;

            QueryColumn molsimQc = Eqp.QueryTable.GetSelectedMolsimQueryColumn();             // get any column to return similarity score in

            DbCommandMx drd = new DbCommandMx();

            if (Eqp.SearchKeySubset == null)
            {
                drd.Prepare(sql);
                drd.ExecuteReader();
            }

            else             // limit to list
            {
                sql += " where " + Eqp.QueryTable.MetaTable.KeyMetaColumn.Name + " in (<list>)";
                drd.PrepareListReader(sql, DbType.String);

                List <string> dbKeySubset = new List <string>();
                foreach (string key in Eqp.SearchKeySubset)
                {
                    string dbKey = CompoundId.NormalizeForDatabase(key, Eqp.QueryTable.MetaTable);
                    dbKeySubset.Add(dbKey);
                }
                drd.ExecuteListReader(dbKeySubset);
            }

            drd.CheckForCancel = Eqp.CheckForCancel;             // set cancel check flag

            StructureMatcher matcher = new StructureMatcher();   // allocate structure matcher
            List <object[]>  results = new List <object[]>();

            int matchCount = 0;

            while (drd.Read())
            {
                cid = drd.GetObject(0).ToString();
                cid = CompoundId.Normalize(cid, Eqp.QueryTable.MetaTable);                 // normalize adding prefix as needed

                molString = drd.GetString(1);
                if (String.IsNullOrEmpty(molString))
                {
                    continue;
                }

                cs = new MoleculeMx(structureFormat, molString);
                if (Pssc.SearchType == StructureSearchType.Substructure)
                {
                    if (matcher.IsSSSMatch(Pssc.Molecule, cs))
                    {
                        vo    = new object[SelectList.Count];
                        vo[0] = CompoundId.Normalize(cid, Eqp.QueryTable.MetaTable);                         // normalize adding prefix
                        results.Add(vo);
                    }
                }

                else if (Pssc.SearchType == StructureSearchType.MolSim)
                {
                    double score = matcher.Molsim(Pssc.Molecule, cs, Pssc.SimilarityType);
                    if (score >= Pssc.MinimumSimilarity)
                    {
                        vo    = new object[SelectList.Count];
                        vo[0] = CompoundId.Normalize(cid, Eqp.QueryTable.MetaTable);                         // normalize adding prefix
                        if (vo.Length >= 2)
                        {
                            vo[1] = (float)score;
                        }

                        results.Add(vo);
                    }
                }

                else if (Pssc.SearchType == StructureSearchType.FullStructure)
                {
                    if (matcher.FullStructureMatch(Pssc.Molecule, cs, Pssc.Options))
                    {
                        vo    = new object[SelectList.Count];
                        vo[0] = CompoundId.Normalize(cid, Eqp.QueryTable.MetaTable);                         // normalize adding prefix
                        results.Add(vo);
                    }
                }
                matchCount++;

//				if (matchCount >100) break; // debug

                if (drd.Cancelled)
                {
                    Eqp.Qe.Cancelled = true;
                    drd.Dispose();
                    Results = null;
                    return;
                }
            }

            drd.Dispose();

            Results = results;
            return;
        }