/// <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); } }
public Cinemas() { _formatter = new ResultsFormatter(); }
public string Execute(CommandOption fetchScope, CommandOption sortOrder, CommandOption period) { FetchScope scope = FetchScope.All; if (fetchScope.HasValue()) { switch (fetchScope.Value().ToUpperInvariant()) { case "MINE": scope = FetchScope.Mine; break; case "ALL": break; default: Console.WriteLine($"Fetch value {fetchScope.Value()} couldn't be parsed - fetching all"); scope = FetchScope.All; break; } } string[] cinemasToCheck = null; if (scope == FetchScope.Mine) { cinemasToCheck = new SettingsReader().GetCinemas(); } SortOrder sort = SortOrder.Date; if (sortOrder.HasValue()) { switch (sortOrder.Value().ToUpperInvariant()) { case "D": sort = SortOrder.Date; break; case "F": sort = SortOrder.Film; break; case "C": sort = SortOrder.Cinema; break; default: Console.WriteLine($"Sort value {sortOrder.Value()} couldn't be parsed - sorting by Date"); sort = SortOrder.Date; break; } } Period periodToFetch = Period.All; if (period.HasValue()) { switch (period.Value().ToUpperInvariant()) { case "T": periodToFetch = Period.Today; break; case "M": periodToFetch = Period.Tomorrow; break; default: Console.WriteLine($"Period value {period.Value()} couldn't be parsed - fetching all"); periodToFetch = Period.All; break; } } var checker = new SiteChecker(); var result = checker.GetShowings(cinemasToCheck); result = result.SortThisBy(sort); result = result.JustThisPeriod(periodToFetch); var formatter = new ResultsFormatter(); var toPrint = formatter.GetResultsTable(result); return(toPrint.ToString()); //Console.WriteLine(toPrint); //Console.ReadLine(); //return 0; }
/// <summary> /// Write Csv file of data /// </summary> /// <param name="csvFile"></param> /// <param name="includeProtein"></param> /// <param name="includeElectronDensity"></param> void WriteCsvFile( string csvFile, bool exportSingle, QueryColumn qcProtein, QueryColumn qcDensity, QueryColumn qcTarget, QueryManager qm, string url, string densityMapUrl, string target) { string rec; DataRowMx dr; StringMx sx; List <int> markedRows; //string finalUrl; StreamWriter sw = new StreamWriter(csvFile); rec = "BSL_XRAY_CMPLX_URL,BSL_XRAY_EDENSITY_URL,TRGT_LABEL"; sw.WriteLine(rec); // header string filePath = DownloadFile(url); string mapFilePath = DownloadFile(densityMapUrl); if (qm == null) // export from HTML { rec = ""; //if (!Lex.Contains(url, "edensity")) // assume protein/ligand rec += filePath; rec += ","; if (mapFilePath != null) { rec += mapFilePath; } rec += ","; // nothing for target for now if (target != null) { rec += target; } sw.WriteLine(rec); } else // export from XtraGrid { ResultsFormatter fmtr = qm.ResultsFormatter; if (exportSingle) // put single row to export in table { markedRows = new List <int>(); CellInfo cinf = qm.MoleculeGrid.LastMouseDownCellInfo; markedRows.Add(cinf.DataRowIndex); // indicate current row } else { markedRows = fmtr.MarkedRowIndexes; } foreach (int ri in markedRows) { dr = qm.DataTable.Rows[ri]; rec = ""; if (qcProtein != null) { url = Lex.ToString(dr[qcProtein.VoPosition]); filePath = DownloadFile(url); if (String.IsNullOrEmpty(filePath)) { continue; } rec += filePath; } rec += ","; if (qcDensity != null) { string mapUrl = Lex.ToString(dr[qcDensity.VoPosition]); mapFilePath = DownloadFile(mapUrl); rec += mapFilePath; } else if (!IncludeElectronDensityPyMol.Checked) { // do nothing, user does not want map } else if (densityMapUrl == null && !exportSingle) { densityMapUrl = _xRay2Request ? GetXray2DensityMapUrl(url, _currentMetaTable, _currentPdbColumnName) : GetXray1DensityMapUrl(url, _currentMetaTable); mapFilePath = DownloadFile(densityMapUrl); rec += mapFilePath; } else if (densityMapUrl != null) { mapFilePath = DownloadFile(densityMapUrl); rec += mapFilePath; } rec += ","; if (qcTarget != null) { target = Lex.ToString(dr[qcTarget.VoPosition]); rec += target; } densityMapUrl = null; //we only get the map from the first record sw.WriteLine(rec); } } sw.Close(); return; }
/// <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); }
/// <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); } }