name = 'pdb'; if (!class_exists('plugin_cache')) @require_once(DOKU_PLUGIN.$this->name.'/classes/cache.php'); if (!class_exists('rcsb')||!class_exists('ncbi')||!class_exists('xml')) @require_once(DOKU_PLUGIN.$this->name.'/classes/sciencedb.php'); $this->ncbi = new ncbi(); $this->rcsb = new rcsb(); $this->xmlCache = new plugin_cache("ncbi_esummary","structure","xml.gz"); $this->imgCache = new plugin_cache("rcsb_image",'',"jpg"); $this->searchBox= DOKU_PLUGIN.'pdb/pdb_search_box.htm'; $this->imageW['small'] = 80; $this->imageW['medium'] = 250; $this->imageW['large'] = 500; } function getType(){ return 'substition'; } function getSort(){ return 158; } function connectTo($mode) { $this->Lexer->addSpecialPattern('\{\{pdb>[^}]*\}\}',$mode,'plugin_pdb'); } /** * Handle the match */ function handle($match, $state, $pos, Doku_Handler $handler){ $match = substr($match,6,-2); return array($state,explode(':',$match)); } /** * Create output */ function render($mode, Doku_Renderer $renderer, $data){ if($mode != 'xhtml'){return false;} list($state, $query) = $data; list($cmd,$pdbid) = $query; $pdbid = urlencode($pdbid); $cmd = strtolower($cmd); if ($cmd=='small' || $cmd=='medium' || $cmd=='large'){ $filename = $this->imgCache->GetMediaPath($pdbid); if ($this->rcsb->DownloadImage($pdbid,$filename)!==false) $renderer->doc.= $this->getImageHtml($pdbid,$cmd).NL; else $renderer->doc.= $this->getLang('pdb_no_image').NL; return true; }else if($cmd=='short'||$cmd=='long'){ $summaryXML = $this->getSummaryXML($pdbid); if(!empty($summaryXML)) $renderer->doc.= $this->getTextHtml($pdbid,$cmd,$summaryXML); else $renderer->doc.= $this->getLang('pdb_no_summary').NL; return true; }else if($cmd=='fullsmall'){ $filename = $this->imgCache->GetMediaPath($pdbid); if ($this->rcsb->DownloadImage($pdbid,$filename)!==false) $imageHtml = $this->getImageHtml($pdbid,"small").NL; else $imageHtml = $this->getLang('pdb_no_image').NL; $renderer->doc.='
'.$imageHtml.'
'.NL; $summaryXML = $this->getSummaryXML($pdbid); if(!empty($summaryXML)) $textHtml = $this->getTextHtml($pdbid,"long",$summaryXML); else $renderer->doc.= $this->getLang('pdb_no_summary').NL; $renderer->doc.='
'.$textHtml.'
'.NL; $renderer->doc.='
'.NL; return true; } switch($cmd){ case 'searchbox': $renderer->doc .= file_get_contents($this->searchBox); return true; case 'link': $renderer->doc .= $this->rcsb->ExplorerLink($pdbid); return true; case 'summaryxml': $summaryXML = $this->getSummaryXML($pdbid); $renderer->doc.="
".htmlspecialchars($summaryXML)."
"; return true; case 'structureid': $summaryXML = $this->getSummaryXML($pdbid); $sid = $this->ncbi->GetSearchItem("Id",$summaryXML); if (!empty($sid)){ $renderer->doc.="StructureID:".$sid; }else{ $renderer->doc.=$pdbid." was not found."; } return true; case 'clear_summary': $renderer->doc.="Summary cleared."; $this->xmlCache->ClearCache(); return true; case 'clear_image': $renderer->doc.="Image cleared."; $this->imgCache->ClearCache(); return true; case 'remove_dir': $renderer->doc.="Directory removed"; $this->xmlCache->RemoveDir(); $this->imgCache->RemoveDir(); return true; default: // Command was not found.. $renderer->doc.='
'.sprintf($this->getLang('plugin_cmd_not_found'),$cmd).'
'; $renderer->doc.='
'.$this->getLang('pdb_available_cmd').'
'; return true; } } /** * Get renderered Html of Image */ function getImageHtml($pdbid,$type){ $pdbid = $this->rcsb->PDBformat($pdbid); if ($pdbid===false) return NULL; $url = $this->imgCache->GetMediaLink($pdbid); $w = $this->imageW[$type]; $html = '
'; $html.= 'PDB image'; $html.= '
'; return $html; } /** * Get renderered Html of Texts */ function getTextHtml($pdbid,$type,$summaryXML){ $PdbAcc = $this->ncbi->GetSummaryItem("PdbAcc" ,$summaryXML); $PdbClass = $this->ncbi->GetSummaryItem("PdbClass",$summaryXML); $PdbDescr = $this->ncbi->GetSummaryItem("PdbDescr",$summaryXML); $LigCode = $this->ncbi->GetSummaryItem("LigCode" ,$summaryXML); if (empty($PdbAcc)) return false; $html ='
'; $html.=''.$PdbAcc.''; $html.=' - '.$PdbClass.''; if ($type=='long'){ $html.='
'.$PdbDescr.'
'; if (!empty($LigCode)){ $html.='
'; $ss = (strpos("|",$LigCode)===false)? $this->getLang('pdb_ligand'):$this->getlang('pdb_ligands'); $html.=$ss.$LigCode.'
'; } } $html.='
'.NL; return $html; } /** * Get summary XML from cache or NCBI */ function getSummaryXml($pdbAcc){ global $conf; $cachedXml = $this->xmlCache->GetMediaText($pdbAcc); if ($cachedXml!==false){ return $cachedXml; } // convert PDB ID to Structure ID $eSearchXml = $this->ncbi->SearchXml('structure',$pdbAcc); $ids = $this->ncbi->GetSearchItems("Id",$eSearchXml); $id=0; for ($i=0;$incbi->SummaryXML('structure',$ids[$i]); $tmpPdbId = $this->ncbi->GetSummaryItem("PdbAcc",$tmpXml); if (strtolower($pdbAcc)==strtolower($tmpPdbId)){ $id = $ids[$i]; } } if ($id==0) return NULL; // Get summary XML $summary = $this->ncbi->SummaryXml('structure',$id); if (!empty($summary)){ $cachePath = $this->xmlCache->GetMediaPath($pdbAcc); if(io_saveFile($cachePath,$summary)){ chmod($cachePath,$conf['fmode']); } } return $summary; } /* * Convert PDB ID to Structure ID */ function PDBtoStructureID($pdbAcc){ $xml = $this->SearchXml('structure',$pdbAcc); $ids = $this->GetSearchItems("Id",$xml); for ($i=0;$iSummaryXML('structure',$ids[$i]); $tmpPdbId = $this->GetSummaryItem("PdbAcc",$tmpXml); if (strtolower($pdbAcc)==strtolower($tmpPdbId)){ return $ids[$i]; } } return 0; } } ?>