예제 #1
0
        private void ColorColumnSelector_EditValueChanged(object sender, EventArgs e)
        {
#if false
            if (InSetup)
            {
                return;
            }

            InSetup = true;

            QueryColumn qc = ColorColumnSelector.QueryColumn;
            ColorBy.QueryColumn = qc;
            if (qc != null)
            {                   // setup for this column
                ColorByColumn.Checked = true;
                if (qc.CondFormat == null || qc.CondFormat.Rules.Count == 0)
                {                 // define default rules
                    qc.CondFormat = new CondFormat();
                    ResultsField rfld = View.ResultsFormat.GetResultsField(qc);
                    if (rfld != null)
                    {
                        CondFormatStyle cfStyle = qc.CondFormat.Rules.ColoringStyle;
                        ColorRulesControl.SetupControl(rfld.QueryColumn.MetaColumn.DataType, cfStyle, rfld);
                        //ColorRulesControl.SetupForResultsField(rfld, qc.CondFormat.Rules.ColoringStyle);
                    }
                    InitializeRulesBasedOnDataValues();
                    qc.CondFormat.Rules = ColorRulesControl.GetRules();                     // get rules back
                }

                ResetBackgroundColors(ColorBy.QueryColumn);
                SetupColorSchemeGrid(ColorBy.QueryColumn, View);
            }

            else
            {
                ColorByFixedColor.Checked = true;              // no col selected, goto fixed mode
            }
            InSetup = false;

            FireEditValueChanged(ColorColumnSelector);
#endif

            return;
        }
예제 #2
0
        /// <summary>
        /// ExportToMOE
        /// </summary>
        /// <param name="mtName"></param>
        /// <param name="mcName"></param>
        /// <param name="url"></param>

        void ExportToMOEMethod(
            string url,
            QueryManager qm,
            ResultsFormatter fmtr,
            ResultsField rfld)
        {
            List <string> fileList = ExportToFilesMethod(url, qm, fmtr, rfld);            // download the files first

            string moeExecutable, moeArgs = "";

            if (!GetMoeExecutable(out moeExecutable, out moeArgs))
            {
                return;                         // failed
            }
            if (UseExistingMoeInstance.Checked) // -openfiles uses any existing instance, if not included then starts new instance
            {
                moeArgs += " -openfiles ";
            }

            for (int fi = 0; fi < fileList.Count; fi++)
            {
                moeArgs += Lex.AddDoubleQuotes(fileList[fi]) + " ";
            }

            try
            {
                Progress.Show("Passing data to MOE...");
                Process p = Process.Start(moeExecutable, moeArgs);
                Progress.Hide();
                return;
            }

            catch (Exception ex)
            {
                try { Progress.Hide(); } catch { }
                throw new Exception(ex.Message, ex);
            }
        }
예제 #3
0
        /// <summary>
        /// Setup the conditional formatting control for marker colors
        /// </summary>

        public void SetupColorSchemeGrid(
            QueryColumn qc,
            ViewManager view)
        {
            return;             // todo

            if (qc == null || qc.CondFormat == null)
            {
                CondFormatRules rules = new CondFormatRules();
                SetupControl(MetaColumnType.Unknown, rules);
            }

            else             // column assigned to color rules
            {
                ResultsField rfld = view.ResultsFormat.GetResultsField(qc);
                if (rfld != null)
                {
                    SetupControl(rfld, qc.CondFormat.Rules);                     // setup existing rules
                }
            }

            return;
        }
예제 #4
0
/// <summary>
/// Initialize coloring rules for newly selected QueryColumn
/// </summary>

#if false
        internal CondFormatRules InitializeRulesBasedOnDataValues()
        {
            CondFormatRule r;

            Color[] colors = GetColors();

            CondFormatRules rules = new CondFormatRules();

            if (ResultsField == null)
            {
                return(rules);
            }

            QueryColumn      qc    = ResultsField.QueryColumn;
            ColumnStatistics stats = ResultsField.GetStats();

            if (qc.MetaColumn.DataType == MetaColumnType.Structure)
            {             // setup substructure search rules if structures
                for (int i1 = 0; i1 < stats.DistinctValueList.Count; i1++)
                {
                    MobiusDataType mdt = stats.DistinctValueList[i1];
                    r        = new CondFormatRule();
                    r.Op     = "SSS";
                    r.OpCode = CondFormatOpCode.SSS;
                    ChemicalStructureMx cs = mdt as ChemicalStructureMx;
                    if (cs != null)
                    {
                        r.Value = cs.ChimeString;
                    }
                    r.BackColor1 = colors[i1 % colors.Length];
                    rules.Add(r);
                }
            }

            else             // setup equality rules for other types
            {
                for (int i1 = 0; i1 < stats.DistinctValueList.Count; i1++)
                {
                    MobiusDataType mdt = stats.DistinctValueList[i1];
                    r            = new CondFormatRule();
                    r.Op         = "Equal to";
                    r.OpCode     = CondFormatOpCode.Eq;
                    r.Value      = mdt.FormattedText;
                    r.BackColor1 = colors[i1 % colors.Length];
                    rules.Add(r);
                    //				if (i1 + 1 >= 25) break; // limit number of items
                }
            }

            if (stats.NullsExist)
            {
                r            = new CondFormatRule();
                r.Name       = "Missing Data";
                r.Op         = "Missing";
                r.OpCode     = CondFormatOpCode.NotExists;
                r.BackColor1 = CondFormatMatcher.DefaultMissingValueColor;
                rules.Add(r);
            }

            SetRules(ResultsField, rules);             // put into the grid
            return(rules);
        }
예제 #5
0
        /// <summary>
        /// Export to Vida
        /// </summary>
        /// <param name="mtName"></param>
        /// <param name="mcName"></param>
        /// <param name="url"></param>

        //void ExportToVidaMethod(
        //    string url,
        //    QueryManager qm)
        //{
        //    StreamWriter sw;
        //    string scriptSourceFile = "", script;
        //    bool includeProtein = false; // IncludeProtein.Checked;
        //    if (!includeProtein) QcProtein = null;

        //    bool includeElectronDensity = false; // IncludeElectronDensityVida.Checked;
        //    if (!includeElectronDensity) QcDensity = null;

        //    if (!includeProtein && !includeElectronDensity)
        //        throw new Exception("Either the protein or the electron density must be selected for VIDA export");

        //    string csvFile = ClientDirs.TempDir + @"\VidaBatchLoad.csv";

        //    WriteCsvFile(csvFile, ExportSingle.Checked, QcProtein, QcDensity, QcTarget, qm, url);

        //    try
        //    {
        //        scriptSourceFile = CommonConfigInfo.MiscConfigDir + @"\VidaBatchLoad.py";
        //        StreamReader sr = new StreamReader(scriptSourceFile);
        //        script = sr.ReadToEnd();
        //        sr.Close();
        //    }
        //    catch (Exception ex)
        //    { throw new Exception("Error reading " + scriptSourceFile + ": " + ex.Message); }

        //    // Modify script & send to client for opening by VIDA

        //    script += "\r\nLoadMobiusExport(" + Lex.AddDoubleQuotes(csvFile) + ")\r\n";
        //    scriptSourceFile = ClientDirs.TempDir + @"\VidaBatchLoad.py";
        //    sw = new StreamWriter(scriptSourceFile);
        //    sw.Write(script);
        //    sw.Close();

        //    string vidaPaths = SS.I.ServicesIniFile.Read("VidaPaths", @"Software\Openeye\vida");
        //    scriptSourceFile = Lex.AddSingleQuotes(scriptSourceFile); // quote file name since it includes spaces
        //    string args = vidaPaths + "\t" + scriptSourceFile;

        //    Progress.Show("Passing data to VIDA...");
        //    StartVida(args);
        //    System.Threading.Thread.Sleep(3000); // leave message up a bit while VIDA is starting/being activated
        //    Progress.Hide();
        //}

        /// <summary>
        /// ExportFiles
        /// </summary>

        List <string> ExportToFilesMethod(
            string url,
            QueryManager qm,
            ResultsFormatter fmtr,
            ResultsField rfld)
        {
            List <int>    markedRows;
            List <string> fileList = new List <string>();
            DataRowMx     dr;
            StringMx      sx;
            string        clientPath, clientFolder, clientFileName;

            clientPath = FileName.Text;             // path to file

            clientFolder = Path.GetDirectoryName(clientPath);
            if (Lex.IsUndefined(clientFolder) || !Directory.Exists(clientFolder))
            {
                clientFolder = Preferences.Get("DefaultExportFolder", ClientDirs.DefaultMobiusUserDocumentsFolder);
                if (Lex.IsUndefined(clientFolder) || !Directory.Exists(clientFolder))
                {
                    clientFolder = ClientDirs.TempDir;
                }
            }

            clientFileName = Path.GetFileName(clientPath);

            if (ExportSingle.Checked)             // put single row to export in table
            {
                if (Lex.IsUndefined(clientFileName))
                {
                    return(fileList);
                }

                Progress.Show("Retrieving " + clientFileName + " ...");
                clientPath = clientFolder + @"\" + clientFileName;
                try
                {
                    bool downloadOk = DownloadFile(url, clientPath);

                    fileList.Add(clientPath);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex);
                }
                finally
                {
                    Progress.Hide();
                }
            }

            else             // multiple files
            {
                markedRows = fmtr.MarkedRowIndexes;


                foreach (int ri in markedRows)
                {
                    if (ri < 0)
                    {
                        url = url;                             // single selected url
                    }
                    else
                    {
                        dr = qm.DataTable.Rows[ri];
                        sx = dr[rfld.VoPosition] as StringMx;
                        if (sx == null || sx.Hyperlink == null)
                        {
                            continue;
                        }
                        url = sx.Value;                         // link is in value rather than HyperLink currently
                    }
                    if (String.IsNullOrEmpty(url))
                    {
                        continue;
                    }

                    clientFileName = Path.GetFileName(url);
                    clientPath     = clientFolder + @"\" + clientFileName;
                    Progress.Show("Retrieving " + clientFileName + " ...");
                    try
                    {
                        bool downloadOk = DownloadFile(url, clientPath);
                        fileList.Add(clientPath);
                    }
                    catch (Exception ex)
                    {
                        Progress.Hide();
                        throw ex;
                    }
                }

                Progress.Hide();
                if (markedRows.Count > 0 && fileList.Count == 0)
                {
                    throw new Exception("No files downloaded");
                }
            }

            return(fileList);
        }
예제 #6
0
        /// <summary>
        /// Handle a click on a link to a 3D structure & open in Vida
        /// If clicked from an XtraGrid give the user a range of options for the data
        /// to be exported. If clicked from a HTML page give limited options.
        /// </summary>
        /// <param name="mtName"></param>
        /// <param name="mcName"></param>
        /// <param name="url"></param>

        public void ClickFunction(
            string mtName,
            string mcName,
            string url)
        {
            ResultsFormatter fmtr = null;
            ResultsField     rfld = null;
            //DataRowMx dr;
            StringMx     sx;
            StreamWriter sw;
            int          markedCount   = 0;
            string       densityMapUrl = null;
            string       target        = null;

            _currentMetaTable     = mtName;
            _currentPdbColumnName = mcName;

            IncludeElectronDensityPyMol.Checked = false;

            MetaTable mt = MetaTableCollection.Get(mtName);

            if (mt == null)
            {
                return;
            }

            MetaColumn mc = mt.GetMetaColumnByName(mcName);

            if (mc == null)
            {
                return;
            }

            _xRay2Request = Lex.Contains(mtName, "XRay2");    // newer XRay2 database table?
            _urlFileName  = Path.GetFileName(url);            // extract file name from url

            QueryManager qm = ClickFunctions.CurrentClickQueryManager;

            if (qm != null)
            {
                Query         q  = qm.Query;
                ResultsFormat rf = qm.ResultsFormat;
                fmtr = qm.ResultsFormatter;

                rfld = rf.GetResultsField(mc);
                if (rfld == null)
                {
                    return;
                }

                QueryTable qt = q.GetQueryTableByNameWithException(mtName);
                _qcProtein = qt.GetQueryColumnByNameWithException(mcName);

                if (_xRay2Request)                 // newer XRay2 database
                {
                    string mapUrl = "";
                    if (mcName == "ALIGNED_SPLIT_COMPLEX_URL")
                    {
                        mapUrl = "ALIGNED_SPLIT_MAP_URL";
                    }
                    else if (mcName == "ALIGNED_FULL_COMPLEX_URL")
                    {
                        mapUrl = "ALIGNED_FULL_MAP_URL";
                    }
                    else if (mcName == "ORIGINAL_PDB_URL")
                    {
                        mapUrl = "ORIGINAL_MAP_URL";
                    }                                                                 //{ mapUrl = "ORIGINAL_MAP_URL"; }

                    _qcDensity = qt.GetQueryColumnByName(mapUrl);                     //("ALIGNED_SPLIT_MAP_URL");
                    if (_qcDensity != null && !_qcDensity.Selected)
                    {
                        _qcDensity = null;
                    }

                    _qcTarget = qt.GetQueryColumnByName("primary_gene_name_alias");
                    if (_qcTarget != null && !_qcTarget.Selected)
                    {
                        _qcTarget = null;
                    }
                }

                if (_qcDensity != null)
                {
                    // if there is a density map url located in the density column, enable the PyMol CheckEdit
                    DataRowMx dr = qm.DataTable.Rows[qm.MoleculeGrid.LastMouseDownCellInfo.DataRowIndex];
                    densityMapUrl = Lex.ToString(dr[_qcDensity.VoPosition]);
                }
                else
                {
                    // user did not select the map column, try to retrieve the XRay1 or Xray2 density map url fromt he metatable
                    densityMapUrl = _xRay2Request ? GetXray2DensityMapUrl(url, qt.MetaTable.Name, mcName) : GetXray1DensityMapUrl(url, qt.MetaTable.Name);
                }

                // default checkbox to false so user does not load electron density maps everytime, since these take
                // extra time to load.
                IncludeElectronDensityPyMol.Checked = false;

                IncludeElectronDensityPyMol.Enabled = !string.IsNullOrEmpty(densityMapUrl);

                if (_qcProtein == null && _qcDensity == null)
                {
                    throw new Exception("Neither the PDB nor the MAP column is selected in the query");
                }

                markedCount = fmtr.MarkedRowCount;
                int unmarkedCount = fmtr.UnmarkedRowCount;

                if (markedCount == 0 || unmarkedCount == 0)                 // if no specific selection assume user wants single structure
                {
                    ExportSingle.Checked = true;
                    FileName.Text        = _urlFileName;
                }
                else
                {
                    ExportMarked.Checked = true;                  // assume wants marked structures
                }
                ExportMarked.Enabled = true;
            }

            else              // simple setup for click from HTML display
            {
                ExportSingle.Checked = true;
                ExportMarked.Enabled = false;
                FileName.Text        = _urlFileName;

                densityMapUrl = GetXray2DensityMapUrl(url, _currentMetaTable, mcName);
                target        = GetTarget(url, _currentMetaTable, mcName);


                ////IncludeProtein.Enabled = IncludeElectronDensityEnabled = false;

                ////if (Lex.Eq(mcName, "bsl_xray_cmplx_url"))
                ////  IncludeProtein.Checked = true;

                ////else if (Lex.Eq(mcName, "bsl_xray_edensity_url"))
                ////  IncludeElectronDensityChecked = true;
            }

            if (mcName == "ALIGNED_SPLIT_MAP_URL" || mcName == "ALIGNED_FULL_MAP_URL" || mcName == "ORIGINAL_MAP_URL")              // not viewable fileds
            {
                DisablePymol();
                DisableMoe();
                ExportToFile.Enabled = ExportToFile.Checked = true;
            }

            else if (mcName == "ALIGNED_FULL_COMPLEX_URL" || mcName == "ORIGINAL_PDB_URL" || mcName == "ALIGNED_SPLIT_COMPLEX_URL")             // viewable by PyMol
            {
                EnableMoe();
                EnablePymol();
                ExportToFile.Enabled = true;
                ExportToFile.Checked = false;
            }
            else             //everything else should be viewable by MOE
            {
                EnableMoe();
                DisablePymol();
                ExportToFile.Enabled = true;
                ExportToFile.Checked = false;
            }

            DialogResult dlgRslt = ShowDialog(SessionManager.ActiveForm);

            if (dlgRslt == DialogResult.Cancel)
            {
                return;
            }

            bool exportSingle = ExportSingle.Checked;
            bool exportMarked = !exportSingle;

            if (!IncludeElectronDensityPyMol.Checked)
            {
                densityMapUrl = null;
            }

            if (exportMarked)             // see if reasonable count if exporting marked rows
            {
                string msg;
                if (markedCount == 0)
                {
                    msg = "No rows have been marked for export";
                    MessageBoxMx.Show(msg, "Mobius", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (markedCount > 10)
                {
                    msg =
                        markedCount + " structures have been selected out export.\n" +
                        "Are you sure these are the structures you want to export?";
                    dlgRslt = MessageBoxMx.Show(msg, "Mobius", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (dlgRslt != DialogResult.Yes)
                    {
                        return;
                    }
                }
            }

            // Export to PyMol (Schrodinger) - Collab with Paul Sprengeler and Ken Schwinn
            // Relavant Files:
            // 1. Plugin: CorpView.py (in Mobius config dir)
            // 2. Script: CorpView.pml - Runs the plugin and then passes in the .csv file (in Mobius config dir)
            //		 Expected content (note: <csv-file-name> gets replaced):
            //			import pymol
            //			pluginLocation = 'C:\Progra~1\PyMOL\PyMOL\modules\pmg_tk\startup\CorpView.py'
            //			cmd.do('run ' + pluginLocation)
            //			cmd.do('lv_create_environment')
            //			cmd.do('lv_import_mobius <csv-file-name>')
            //			cmd.do('lv_destroy_environment')
            // 3. Csv file: PyMolBatchLoad.csv - Csv file in format expected by plugin (in Mobius temp dir)

            if (ExportToPyMol.Checked)
            {
                ExportToPyMolMethod(url, densityMapUrl, target, qm);
            }

            else if (ExportToMOE.Checked)             // Export to MOE
            {
                ExportToMOEMethod(url, qm, fmtr, rfld);
            }

            else
            {
                ExportToFilesMethod(url, qm, fmtr, rfld);
            }
        }