123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677 |
- <?php
- function tripal_analysis_blast_init(){
-
- drupal_add_css(drupal_get_path('theme', 'tripal').
- '/css/tripal_analysis_blast.css');
- drupal_add_js(drupal_get_path('theme', 'tripal').
- '/js/tripal_analysis_blast.js');
- }
- function tripal_analysis_blast_menu() {
-
- $items['tripal_top_blast'] = array(
- 'path' => 'top_blast',
- 'title' => t('Blast Hits'),
- 'page callback' => 'tripal_get_blast_results',
- 'page arguments' => array(1,2,3,'1'),
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK
- );
-
- $items['admin/tripal/tripal_blast_regex'] = array(
- 'title' => t('Blast Regex'),
- 'page callback' => 'tripal_get_blast_regex',
- 'page arguments' => array(3),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_CALLBACK
- );
- return $items;
- }
- function tripal_analysis_blast_block($op = 'list', $delta = 0, $edit=array()){
- switch($op) {
- case 'list':
- $blocks['results']['info'] = t('Tripal Blast Analysis Results');
- $blocks['results']['cache'] = BLOCK_NO_CACHE;
- return $blocks;
- case 'view':
- if(user_access('access chado_analysis_blast content') and arg(0) == 'node' and is_numeric(arg(1))) {
- $nid = arg(1);
- $node = node_load($nid);
- $block = array();
- switch($delta){
- case 'results':
- $block['subject'] = t('Blast Results');
- $block['content'] = theme('tripal_analysis_blast_results', $node);
- break;
- default :
- }
- return $block;
- }
- }
- }
- function tripal_analysis_blast_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
- case 'view':
-
- $types_to_show = variable_get('tripal_analysis_blast_setting',
- array('chado_feature'));
-
- if (!in_array($node->type, $types_to_show, TRUE)) {
- break;
- }
-
- if (!$teaser && $node->feature->feature_id) {
- if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
- $node->content['tripal_analysis_blast_index_version'] = array(
- '#value' => theme('tripal_analysis_blast_results_index_version',$node),
- '#weight' => 8,
- );
- } else {
-
- $node->content['tripal_analysis_blast_form'] = array(
- '#value' => theme('tripal_analysis_blast_results', $node),
- '#weight' => 8
- );
- }
- }
- }
- }
- function tripal_analysis_blast_theme () {
- return array(
- 'tripal_analysis_blast_results_index_version' => array (
- 'arguments' => array('node'),
- ),
- 'tripal_analysis_blast_results' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_analysis_blast_results',
- ),
- );
- }
- function tripal_analysis_blast_preprocess_tripal_analysis_blast_results(&$variables){
- $feature = $variables['node']->feature;
- $variables['tripal_analysis_blast']['results'] = tripal_get_blast_results($feature->feature_id, 0, 10, 0);
- }
- function theme_tripal_analysis_blast_results_index_version ($node) {
- $feature = $node->feature;
- $content = tripal_get_blast_results_index_version($feature->feature_id);
- return $content;
- }
- function tripal_get_blast_results($feature_id, $db_id, $max,$ajax){
-
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_blast_output_iteration_hits' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
-
- $sql = "SELECT AP.value AS apvalue, AFP.value AS afpvalue, AF.analysis_id AS aid
- FROM {analysisfeatureprop} AFP
- INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id
- INNER JOIN analysisprop AP ON AP.analysis_id = AF.analysis_id
- WHERE feature_id = %d
- AND AFP.type_id = %d ";
- $result = db_query($sql, $feature_id, $type_id);
- tripal_db_set_active($previous_db);
-
- while ($analysisfeatureprop = db_fetch_object($result)) {
-
- $blastsettings = explode("|", $analysisfeatureprop->apvalue);
- $att_db_id = $blastsettings [0];
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT analysis_id AS aid, name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
- FROM {analysis} WHERE analysis_id = %d";
- $analysis = db_fetch_object(db_query($sql, $analysisfeatureprop->aid));
- tripal_db_set_active($previous_db);
-
- if ($ajax == 0) {
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {db} WHERE db_id=%d";
- $db = db_fetch_object(db_query($sql, $att_db_id));
- tripal_db_set_active($previous_db);
- $content .= parse_NCBI_Blast_XML($analysisfeatureprop->afpvalue,$db,$max,$feature_id,$ajax, $analysis);
-
- } else {
- if ($att_db_id == $db_id) {
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {db} WHERE db_id=%d";
- $db = db_fetch_object(db_query($sql, $att_db_id));
- tripal_db_set_active($previous_db);
- $content .= parse_NCBI_Blast_XML($analysisfeatureprop->afpvalue,$db,$max,$feature_id,$ajax, $analysis);
- }
- }
- }
-
-
-
-
- if($ajax){
- drupal_json(array('update' => $content));
- } else {
- return $content;
- }
- }
- function tripal_get_blast_results_index_version ($feature_id){
-
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_blast_output_iteration_hits' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
-
- $sql = "SELECT AP.value AS apvalue, AFP.value AS afpvalue, AF.analysis_id AS aid
- FROM {analysisfeatureprop} AFP
- INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id
- INNER JOIN analysisprop AP ON AP.analysis_id = AF.analysis_id
- WHERE feature_id = %d
- AND AFP.type_id = %d ";
- $result = db_query($sql, $feature_id, $type_id);
- tripal_db_set_active($previous_db);
-
- while ($analysisfeatureprop = db_fetch_object($result)) {
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT analysis_id AS aid, name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
- FROM {analysis} WHERE analysis_id = %d";
- $analysis = db_fetch_object(db_query($sql, $analysisfeatureprop->aid));
- tripal_db_set_active($previous_db);
- $blastsettings = explode("|", $analysisfeatureprop->apvalue);
- $att_db_id = $blastsettings [0];
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {db} WHERE db_id=%d";
- $db = db_fetch_object(db_query($sql, $att_db_id));
- tripal_db_set_active($previous_db);
-
- $max = 10;
- $content .= parse_NCBI_Blast_XML_index_version($analysisfeatureprop->afpvalue,$db,$max,$feature_id,$ajax, $analysis);
-
- }
- return $content;
- }
- function parse_NCBI_Blast_XML($xml_string,$db,$max,$feature_id,$ajax, $analysis) {
-
- $sql = "SELECT * FROM {tripal_analysis_blast} WHERE db_id = %d";
- $parser = db_fetch_object(db_query($sql, $db->db_id));
- $db_name = $parser->displayname;
- $is_genbank = $parser->genbank_style;
- $regex_hit_id = $parser->regex_hit_id;
- $regex_hit_def = $parser->regex_hit_def;
- $regex_hit_accession = $parser->regex_hit_accession;
-
- if(!$regex_hit_id){
- $regex_hit_id = '/^(.*?)\s.*$/';
- } else {
- $regex_hit_id = '/'.$regex_hit_id.'/';
- }
- if(!$regex_hit_def){
- $regex_hit_def = '/^.*?\s(.*)$/';
- } else {
- $regex_hit_def = '/'.$regex_hit_def.'/';
- }
- if(!$regex_hit_accession){
- $regex_hit_accession = '/^(.*?)\s.*$/';
- } else {
- $regex_hit_accession = '/'.$regex_hit_accession.'/';
- }
-
- if($db->url && $db_name){
- $db_name = "<a href=\"$db->url\">$db_name</a>";
- }
- $url = url("sites/all/themes/theme_tripal/images/ajax-loader.gif");
-
- if(!$ajax){
-
- $html_out .= "<div id=\"tripal_ajaxLoading\" style=\"display:none\">".
- "<div id=\"loadingText\">Loading...</div>".
- "<img src=\"$url\"></div>";
- if (!$db_name) {
- $html_out .= "<div id=\"blast-hits\" class=\"tripal_blast-info-box\">".
- "<div class=\"tripal_expandableBox\">".
- "<h3>$analysis->name</h3></div>".
- "<div class=\"tripal_expandableBoxContent\" ".
- "id=\"blast_db_$db->db_id\">";
- } else {
- $html_out .= "<div id=\"blast-hits\" class=\"tripal_blast-info-box\">".
- "<div class=\"tripal_expandableBox\">".
- "<h3>$db_name</h3></div>".
- "<div class=\"tripal_expandableBoxContent\" ".
- "id=\"blast_db_$db->db_id\">";
- }
- };
-
- $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $analysis->aid));
- $ana_url = url("node/".$ana_nid);
-
- $html_out .= "<strong>Analysis Date: </strong>$analysis->time (<a href=$ana_url>$analysis->name</a>)<br>";
-
-
-
-
- $xml_output = simplexml_load_string($xml_string);
- $iteration = '';
-
- if ($xml_output->getName() == 'Iteration') {
- foreach ($xml_output->children() as $xml_tag) {
- if ($xml_tag->getName() == 'Iteration_query-def') {
-
- } else if ($xml_tag->getName() == 'Iteration_hits') {
- $iteration = $xml_tag;
- }
- }
-
- } else {
- $iteration = $xml_output;
- }
- $number_hits = 0;
- foreach($iteration->children() as $hits){
- $number_hits ++;
- }
-
- if($max != 10){
- $url = url("tripal_top_blast/$feature_id/$db->db_id/10");
- $html_out .= "<span><a onclick=\"return tripal_update_blast(".
- "this,$db->db_id)\" href=\"$url\">Show Best 10 Hits</a></span>";
- } else {
- $html_out .= "<span>Best 10 Hits Shown</span>";
- }
- if($number_hits <= 10){
-
- } else if ($max != 25) {
- $url = url("tripal_top_blast/$feature_id/$db->db_id/25");
- $html_out .= "<span> | <a onclick=\"return tripal_update_blast(".
- "this,$db->db_id)\" href=\"$url\">Show Best 25 Hits</a></span>";
- }else {
- $html_out .= "<span> | Best 25 Hits Shown</span>";
- }
- if($number_hits <= 25){
-
- } else if ($max != 0) {
- $url = url("tripal_top_blast/$feature_id/$db->db_id/0");
- $html_out .= "<span> | <a onclick=\"return tripal_update_blast(".
- "this,$db->db_id)\" href=\"$url\">Show All Hits</a> </span>";
- } else {
- $html_out .= "<span> | All Hits Shown</span>";
- }
- $html_out .= '<br><span><i>Note:</i> Click a description for more details.'.
- '</span>';
- $html_out .= '<span><table class="tripal_blast_results_table">'.
- ' <tr>'.
- ' <th nowrap>Match Name</th>'.
- ' <th nowrap>E value</th>'.
- ' <th nowrap>Identity</th>'.
- ' <th nowrap>Description</th>'.
- ' </tr>';
-
-
- foreach($iteration->children() as $hits){
-
-
- if($max > 0 && $hit_count >= $max){
- $html_out .= '</table></span>';
- if(!$ajax){
- $html_out .= '</div></div>';
- }
- return $html_out;
- }
- $hit_count++;
- foreach($hits->children() as $hit){
- $best_evalue = 0;
- $best_identity = 0;
- $best_len = 0;
- $element_name = $hit->getName();
- if($element_name == 'Hit_id'){
-
- if ($is_genbank) {
- $hit_name = $hit;
- }
- } else if($element_name == 'Hit_def'){
- if($is_genbank){
- $description = $hit;
- } else {
- $accession = preg_replace($regex_hit_accession,"$1",$hit);
- $hit_name = preg_replace($regex_hit_id,"$1",$hit);
- $description = preg_replace($regex_hit_def,"$1",$hit);
- }
- } else if($element_name == 'Hit_accession'){
-
- if ($is_genbank){
- $accession = $hit;
- }
-
- } else if($element_name == 'Hit_hsps'){
- foreach($hit->children() as $hsp){
- foreach($hsp->children() as $hsp_info){
- $element_name = $hsp_info->getName();
- if($element_name == 'Hsp_num'){
- $hsp_num = $hsp_info;
- }
- if($element_name == 'Hsp_bit-score'){
- $hsp_bit_score = $hsp_info;
- }
- if($element_name == 'Hsp_score'){
- $hsp_score = $hsp_info;
- }
- if($element_name == 'Hsp_evalue'){
- $hsp_evalue = $hsp_info;
-
-
-
- if(!$best_evalue){
- $best_evalue = $hsp_evalue;
- }
- }
- if($element_name == 'Hsp_query-from'){
- $hsp_query_from = $hsp_info;
- }
- if($element_name == 'Hsp_query-to'){
- $hsp_query_to = $hsp_info;
- }
- if($element_name == 'Hsp_hit-from'){
- $hsp_hit_from = $hsp_info;
- }
- if($element_name == 'Hsp_hit-to'){
- $hsp_hit_to = $hsp_info;
- }
- if($element_name == 'Hsp_query-frame'){
- $hsp_query_frame = $hsp_info;
- }
- if($element_name == 'Hsp_identity'){
- $hsp_identity = $hsp_info;
-
-
-
- if(!$best_identity){
- $best_identity = $hsp_identity;
- }
- }
- if($element_name == 'Hsp_positive'){
- $hsp_positive = $hsp_info;
- }
- if($element_name == 'Hsp_align-len'){
- $hsp_align_len = $hsp_info;
-
-
-
- if(!$best_len){
- $best_len = $hsp_align_len;
- }
- }
- if($element_name == 'Hsp_qseq'){
- $hsp_qseq = $hsp_info;
- }
- if($element_name == 'Hsp_hseq'){
- $hsp_hseq = $hsp_info;
- }
- if($element_name == 'Hsp_midline'){
- $hsp_midline = $hsp_info;
- }
- }
- if($hsp_num > 1){
-
- }
- $hsp_html_out .="<b>HSP $hsp_num</b> <pre>Score: ".
- "$hsp_bit_score bits ($hsp_score), ".
- "Expect = $hsp_evalue<br>";
- $hsp_html_out .= sprintf("Identity = %d/%d (%.2f%%), ".
- "Postives = %d/%d (%.2f%%), ".
- "Query Frame = $hsp_query_frame".
- "</pre>",
- $hsp_identity, $hsp_align_len,
- $hsp_identity/$hsp_align_len*100,
- $hsp_positive, $hsp_align_len,
- $hsp_positive/$hsp_align_len*100);
- $hsp_html_out .= sprintf("<pre>Query: %4d $hsp_qseq %d".
- "<br>",
- $hsp_query_from,$hsp_query_to);
- $hsp_html_out .= sprintf(" $hsp_midline<br>");
- $hsp_html_out .= sprintf("Sbjct: %4d $hsp_hseq %d</pre>".
- "<br>",
- $hsp_hit_from,$hsp_hit_to);
- }
- }
- }
- $arrowr_url = url(drupal_get_path('theme', 'tripal')."/images/arrow_r.png");
- $html_out .= "<tr>";
- if($accession && $db->urlprefix){
- $html_out .= "<td><a href=\"$db->urlprefix$accession\" target=\"_blank\">$hit_name</a></td>";
- } else {
-
- $sql = "SELECT feature_id FROM {feature} WHERE uniquename = '%s'";
- $previous_db = db_set_active('chado');
- $hit_feature_id = db_result(db_query($sql, $hit_name));
- db_set_active($previous_db);
-
- if ($hit_feature_id) {
- $hit_url = url("ID$hit_feature_id");
- $html_out .= "<td><a href=\"$hit_url\" target=\"_blank\">$hit_name</a></td>";
- } else {
- $html_out .= "<td>$hit_name</td>";
- }
- }
- $html_out .= "<td nowrap>$best_evalue</td>";
- $percent_identity = number_format($best_identity/$best_len*100, 2);
- $html_out .= "<td nowrap>$percent_identity%</td>";
- $html_out .= "<td nowrap>$description</td>";
- $html_out .= "</tr>
- <tr>
- <td colspan=4>
- <a class=\"blast-hit-arrow-icon\"><img src=$arrowr_url align=\"top\"> View Alignment</a>
- <div class=\"tripal_expandableSubBox\"></div>
- </td>
- </tr>
- <tr>
- <td colspan=4><div class=\"tripal_expandableSubBoxContent\">$hsp_html_out</div><td>
- </tr>";
- $hsp_html_out = '';
- }
- $html_out .= '</table></span>';
- if(!$ajax){
-
- $html_out .= '</div></div>';
- }
- return $html_out;
- }
- function parse_NCBI_Blast_XML_index_version($xml_string,$db,$feature_id) {
-
- $sql = "SELECT * FROM {tripal_analysis_blast} WHERE db_id = %d";
- $parser = db_fetch_object(db_query($sql, $db->db_id));
- $db_name = $parser->displayname;
- $is_genbank = $parser->genbank_style;
- $regex_hit_id = $parser->regex_hit_id;
- $regex_hit_def = $parser->regex_hit_def;
- $regex_hit_accession = $parser->regex_hit_accession;
-
- if(!$regex_hit_id){
- $regex_hit_id = '/^(.*?)\s.*$/';
- } else {
- $regex_hit_id = '/'.$regex_hit_id.'/';
- }
- if(!$regex_hit_def){
- $regex_hit_def = '/^.*?\s(.*)$/';
- } else {
- $regex_hit_def = '/'.$regex_hit_def.'/';
- }
- if(!$regex_hit_accession){
- $regex_hit_accession = '/^(.*?)\s.*$/';
- } else {
- $regex_hit_accession = '/'.$regex_hit_accession.'/';
- }
- $html_out .= "<h3>$db_name</h3>";
-
-
-
-
- $xml_output = simplexml_load_string($xml_string);
- $iteration = '';
-
- if ($xml_output->getName() == 'Iteration') {
- foreach ($xml_output->children() as $xml_tag) {
- if ($xml_tag->getName() == 'Iteration_query-def') {
-
- $html_out .= "Query: $xml_tag<br>";
- } else if ($xml_tag->getName() == 'Iteration_hits') {
- $iteration = $xml_tag;
- }
- }
-
- } else {
- $iteration = $xml_output;
- }
-
-
- foreach($iteration->children() as $hits){
- $best_evalue = 0;
- foreach($hits->children() as $hit){
- $best_evalue = 0;
- $element_name = $hit->getName();
- if($element_name == 'Hit_id'){
-
- if ($is_genbank) {
- $hit_name = $hit;
- }
- } else if($element_name == 'Hit_def'){
- if($is_genbank){
- $description = $hit;
- } else {
- $accession = preg_replace($regex_hit_accession,"$1",$hit);
- $hit_name = preg_replace($regex_hit_id,"$1",$hit);
- $description = preg_replace($regex_hit_def,"$1",$hit);
- }
- } else if($element_name == 'Hit_accession'){
-
- if ($is_genbank){
- $accession = $hit;
- }
-
- }
- }
- $html_out .= "<p>$hit_name<br>";
- $html_out .= "$accession<br>";
- $html_out .= "<b>$description</b></br>";
- $hsp_html_out = '';
- }
- return $html_out;
- }
- function tripal_analysis_blast_get_settings() {
-
- $options = node_get_types('names');
-
- $allowedoptions ['chado_feature'] = "Show blast results on feature pages";
- $form['description'] = array(
- '#type' => 'item',
- '#value' => t("Most chado features were analyzed by blast against major sequence databases. This option allows user to display the blast analysis results. Please read user manual for storage and display of blast files. Check the box to enable the analysis results. Uncheck to disable it."),
- '#weight' => 0,
- );
- $form['tripal_analysis_blast_setting'] = array(
- '#type' => 'checkboxes',
- '#options' => $allowedoptions,
- '#default_value' => variable_get('tripal_analysis_blast_setting',
- array('chado_feature')),
- );
- $form['blast_parser'] = array(
- '#title' => t('Blast Parser Settings'),
- '#type' => 'fieldset',
- '#description' => t('Configure parsers for showing blast results. Each database is '.
- 'allowed to have one xml parser.'),
- '#weight' => 10
- );
- $previous_db = tripal_db_set_active('chado');
-
- $sql = 'SELECT db_id, name FROM {db} ORDER BY lower(name)';
- $results = db_query ($sql);
- $blastdbs = array();
- while ($db = db_fetch_object($results)){
- $blastdbs[$db->db_id] = $db->name;
- }
- $form['db_options'] = array(
- '#type' => 'value',
- '#value' => $blastdbs
- );
- $form['blast_parser']['blastdb'] = array(
- '#title' => t('Database'),
- '#type' => 'select',
- '#description' => t('The database used for the blast analysis.'),
- '#options' => $form['db_options']['#value'],
- '#attributes' => array(
- 'onChange' => "return tripal_update_regex(this)",
- )
- );
- $form['blast_parser']['displayname'] = array(
- '#title' => t('Title for the blast analysis'),
- '#type' => 'textfield',
- );
- $form['blast_parser']['gb_style_parser'] = array(
- '#title' => t('Use Genebank style parser. This will clear all regular expression settings for the selected database.'),
- '#type' => 'checkbox',
- '#attributes' => array(
- 'onClick' => "return tripal_set_genbank_style(this)",
- )
- );
- $form['blast_parser']['hit_id'] = array(
- '#title' => t('Regular expression for Hit Name'),
- '#type' => 'textfield',
- );
- $form['blast_parser']['hit_def'] = array(
- '#title' => t('Regular expression for Hit Description'),
- '#type' => 'textfield',
- );
- $form['blast_parser']['hit_accession'] = array(
- '#title' => t('Regular expression for Hit Accession'),
- '#type' => 'textfield',
- );
- $form['blast_parser']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Save settings')
- );
- tripal_db_set_active($previous_db);
- $settings->form = $form;
- $settings->title = "Tripal Blast";
- return $settings;
- }
- function tripal_analysis_blast_parseXMLFile ($analysis_id, $blastdb, $blastfile, $job_id) {
-
- $filename = preg_replace("/.*\/(.*)/", "$1", $blastfile);
- $logfile = file_directory_path() . "/tripal/tripal_analysis_blast/load_$filename.log";
- $log = fopen($logfile, 'a');
-
- if (is_file($blastfile)) {
-
- print "Parsing File:".$blastfile." ...\n";
- fwrite($log, date("D M j G:i:s Y").". Loading $blastfile\n");
-
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_blast_output_iteration_hits' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
- $blastoutput = simplexml_load_file($blastfile);
- $no_iterations = 0;
- foreach($blastoutput->children() as $tmp) {
- if ($tmp->getName() == 'BlastOutput_iterations') {
- foreach($tmp->children() as $itr) {
- if ($itr->getName() == 'Iteration') {
- $no_iterations ++;
- }
- }
- }
- }
- print "$no_iterations iterations to be processed.\n";
-
- $interval = intval($no_iterations * 0.01);
- $idx_iterations = 0;
- foreach ($blastoutput->children() as $blastoutput_tags) {
- if ($blastoutput_tags->getName() == 'BlastOutput_iterations') {
- foreach($blastoutput_tags->children() as $iterations) {
- if ($iterations->getName() == 'Iteration') {
-
- $idx_iterations ++;
- if ($idx_iterations % $interval == 0) {
- $percentage = (int) ($idx_iterations / $no_iterations * 100);
- tripal_db_set_active($previous_db);
- tripal_job_set_progress($job_id, $percentage);
- $previous_db = tripal_db_set_active('chado');
- print $percentage."% ";
- }
-
-
- $feature_id = 0;
- foreach($iterations->children() as $iteration_tags) {
-
-
- $featurenaem_xml = '';
- if($iteration_tags->getName() == 'Iteration_query-def'){
-
-
- if (preg_match("/^(\d+)\|.+/", $iteration_tags, $matches)) {
- $feature_id = $matches[1];
-
- } else {
-
- $first_word = $iteration_tags;
- if (preg_match('/^(.*?)\s.*$/', $iteration_tags, $matches)) {
- $first_word = $matches[1];
- }
-
- $sql = "SELECT count(feature_id) FROM {feature} ".
- "WHERE uniquename = '%s' ";
- $no_features = db_result(db_query($sql, $first_word));
-
- if ($no_features == 1) {
- $sql = "SELECT feature_id FROM {feature} ".
- "WHERE uniquename = '%s' ";
- $feature_id = db_result(db_query($sql, $first_word));
-
- } else if ($no_features > 1) {
- fwrite($log, "Ambiguous: ".$first_word." matches more than one feature and is not processed.\n");
- continue;
-
- } else {
- fwrite($log, "Failed: ".$first_word."\n");
- }
- }
-
- if ($feature_id) {
- fwrite($log, "Succeeded: ".$first_word." => feature id:".$feature_id);
- $featurename_xml = $iteration_tags->asXML();
- }
-
- } else if($iteration_tags->getName() == 'Iteration_hits'){
- if ($feature_id) {
-
- $sql = "SELECT analysisfeatureprop_id FROM {analysisfeatureprop} AFP ".
- "INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id ".
- "WHERE feature_id=%d ".
- "AND analysis_id=%d ".
- "AND type_id=%d ";
- $result = db_query($sql, $feature_id, $analysis_id, $type_id);
- $analysisfeatureprop = db_fetch_object($result);
- $xml_content = "<Iteration>\n".$featurename_xml."\n".$iteration_tags->asXML()."\n</Iteration>";
-
- if ($analysisfeatureprop) {
- $sql = "UPDATE {analysisfeatureprop} ".
- "SET value = '%s' ".
- "WHERE analysisfeatureprop_id = %d ";
-
- db_query($sql, $xml_content, $analysisfeatureprop->analysisfeatureprop_id);
- fwrite($log, " (Update)\n");
-
- } else {
-
-
-
- $sql = "INSERT INTO {analysisfeature} (feature_id, analysis_id) ".
- "VALUES (%d, %d)";
- db_query ($sql, $feature_id, $analysis_id);
-
- $sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE feature_id = %d AND analysis_id = %d";
- $analysisfeature_id = db_result(db_query($sql, $feature_id, $analysis_id));
-
-
-
- $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank)".
- "VALUES (%d, %d, '%s', %d)";
- db_query($sql, $analysisfeature_id, $type_id, $xml_content, '0');
- fwrite($log, " (Insert)\n");
- }
- }
- }
- }
- }
- }
- }
- }
- tripal_db_set_active ($previous_db);
-
- } else {
- $dir_handle = @opendir($blastfile) or die("Unable to open $blastfile");
- $pattern = sql_regcase($blastfile . "/*.XML");
- $total_files = count(glob($pattern));
- print "$total_files file(s) to be parsed.\n";
- $interval = intval($total_files * 0.01);
- $no_file = 0;
-
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_blast_output_iteration_hits' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
-
- while ($file = readdir($dir_handle)) {
- if(preg_match("/^.*\.XML/i",$file)){
-
- if ($no_file % $interval == 0) {
- $percentage = (int) ($no_file / $total_files * 100);
- tripal_db_set_active($previous_db);
- tripal_job_set_progress($job_id, $percentage);
- $previous_db = tripal_db_set_active('chado');
- print $percentage."% ";
- }
-
- print "Parsing File:".$file.". ";
- fwrite($log, date("D M j G:i:s Y").". Loading $file\n");
-
- $blastoutput = simplexml_load_file($blastfile."/".$file);
- $no_iterations = 0;
- foreach($blastoutput->children() as $tmp) {
- if ($tmp->getName() == 'BlastOutput_iterations') {
- foreach($tmp->children() as $itr) {
- if ($itr->getName() == 'Iteration') {
- $no_iterations ++;
- }
- }
- }
- }
- print "$no_iterations iterations to be processed.\n";
- foreach ($blastoutput->children() as $blastoutput_tags) {
- if ($blastoutput_tags->getName() == 'BlastOutput_iterations') {
- foreach($blastoutput_tags->children() as $iterations) {
- if ($iterations->getName() == 'Iteration') {
-
-
- $feature_id = 0;
- foreach($iterations->children() as $iteration_tags) {
-
-
- $featurenaem_xml = '';
- if($iteration_tags->getName() == 'Iteration_query-def'){
-
-
- if (preg_match("/^(\d+)\|.+/", $iteration_tags, $matches)) {
- $feature_id = $matches[1];
-
- } else {
-
- $first_word = $iteration_tags;
- if (preg_match('/^(.*?)\s.*$/', $iteration_tags, $matches)) {
- $first_word = $matches[1];
- }
-
- $sql = "SELECT count(feature_id) FROM {feature} ".
- "WHERE uniquename = '%s' ";
- $no_features = db_result(db_query($sql, $first_word));
-
- if ($no_features == 1) {
- $sql = "SELECT feature_id FROM {feature} ".
- "WHERE uniquename = '%s' ";
- $feature_id = db_result(db_query($sql, $first_word));
-
- } else if ($no_features > 1) {
- fwrite($log, "Ambiguous: ".$first_word." matches more than one feature and is not processed.\n");
- continue;
-
- } else {
- fwrite($log, "Failed: ".$first_word."\n");
- }
- }
-
- if ($feature_id) {
- fwrite($log, "Succeeded: ".$first_word." => feature id:".$feature_id);
- $featurename_xml = $iteration_tags->asXML();
- }
-
- } else if($iteration_tags->getName() == 'Iteration_hits'){
- if ($feature_id) {
-
- $sql = "SELECT analysisfeatureprop_id FROM {analysisfeatureprop} AFP ".
- "INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id ".
- "WHERE feature_id=%d ".
- "AND analysis_id=%d ".
- "AND type_id=%d ";
- $result = db_query($sql, $feature_id, $analysis_id, $type_id);
- $analysisfeatureprop = db_fetch_object($result);
- $xml_content = "<Iteration>\n".$featurename_xml."\n".$iteration_tags->asXML()."\n</Iteration>";
-
- if ($analysisfeatureprop) {
- $sql = "UPDATE {analysisfeatureprop} ".
- "SET value = '%s' ".
- "WHERE analysisfeatureprop_id = %d ";
- db_query($sql, $xml_content, $analysisfeatureprop->analysisfeatureprop_id);
- fwrite($log, " (Update)\n");
-
- } else {
-
-
-
- $sql = "INSERT INTO {analysisfeature} (feature_id, analysis_id) ".
- "VALUES (%d, %d)";
- db_query ($sql, $feature_id, $analysis_id);
-
- $sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE feature_id = %d AND analysis_id = %d";
- $analysisfeature_id = db_result(db_query($sql, $feature_id, $analysis_id));
-
-
-
- $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank)".
- "VALUES (%d, %d, '%s', %d)";
- db_query($sql, $analysisfeature_id, $type_id, $xml_content, '0');
- fwrite($log, " (Insert)\n");
- }
- }
- }
- }
- }
- }
- }
- }
- $no_file ++;
- }
- }
- tripal_db_set_active ($previous_db);
- }
- print "Done.\nSuccessful and failed entries have been saved in the log file:\n $logfile\n";
- fwrite($log, "\n");
- fclose($log);
- return;
- }
- function tripal_get_blast_regex ($db_id) {
- $sql = "SELECT * FROM {tripal_analysis_blast} WHERE db_id = %d";
- $blast_regexs = db_fetch_object(db_query($sql, $db_id));
- drupal_json(
- array(
- 'name' => $blast_regexs->displayname,
- 'genbank_style' => $blast_regexs->genbank_style,
- 'reg1' => $blast_regexs->regex_hit_id,
- 'reg2' => $blast_regexs->regex_hit_def,
- 'reg3' => $blast_regexs->regex_hit_accession,
- )
- );
- }
- function tripal_analysis_blast_node_info() {
- $nodes = array();
- $nodes['chado_analysis_blast'] = array(
- 'name' => t('Analysis: Blast'),
- 'module' => 'chado_analysis_blast',
- 'description' => t('A blast analysis from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Analysis: Blast'),
- 'has_body' => FALSE,
- 'body_label' => t('Blast Analysis Description'),
- 'locked' => TRUE
- );
- return $nodes;
- }
- function chado_analysis_blast_form ($node){
-
- $type = node_get_types('type', $node);
- $form = array();
- $form['title']= array(
- '#type' => 'hidden',
- '#default_value' => $node->title,
- );
- $form['analysisname']= array(
- '#type' => 'textfield',
- '#title' => t('Analysis Name'),
- '#required' => FALSE,
- '#default_value' => $node->analysisname,
- '#weight' => 1
- );
- $form['program']= array(
- '#type' => 'textfield',
- '#title' => t('Program'),
- '#required' => TRUE,
- '#default_value' => $node->program,
- '#weight' => 2
- );
- $form['programversion']= array(
- '#type' => 'textfield',
- '#title' => t('Program Version'),
- '#required' => TRUE,
- '#default_value' => $node->programversion,
- '#weight' => 3
- );
- $form['algorithm']= array(
- '#type' => 'textfield',
- '#title' => t('Algorithm'),
- '#required' => FALSE,
- '#default_value' => $node->algorithm,
- '#weight' => 4
- );
- $form['sourcename']= array(
- '#type' => 'textfield',
- '#title' => t('Source Name'),
- '#required' => FALSE,
- '#default_value' => $node->sourcename,
- '#weight' => 5
- );
- $form['sourceversion']= array(
- '#type' => 'textfield',
- '#title' => t('Source Version'),
- '#required' => FALSE,
- '#default_value' => $node->sourceversion,
- '#weight' => 6
- );
- $form['sourceuri']= array(
- '#type' => 'textfield',
- '#title' => t('Source URI'),
- '#required' => FALSE,
- '#default_value' => $node->sourceuri,
- '#weight' => 7
- );
-
- $default_time = $node->timeexecuted;
- $year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
- $month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
- $day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
-
- if (!$default_time) {
- $default_time = time();
- $year = format_date($default_time, 'custom', 'Y');
- $month = format_date($default_time, 'custom', 'n');
- $day = format_date($default_time, 'custom', 'j');
- }
- $form['timeexecuted']= array(
- '#type' => 'date',
- '#title' => t('Time Executed'),
- '#required' => TRUE,
- '#default_value' => array(
- 'year' => $year,
- 'month' => $month,
- 'day' => $day,
- ),
- '#weight' => 8
- );
- $form['description']= array(
- '#type' => 'textarea',
- '#rows' => 15,
- '#title' => t('Description and/or Program Settings'),
- '#required' => FALSE,
- '#default_value' => check_plain($node->description),
- '#weight' => 9
- );
-
- if (preg_match("/.*\|.*\|.*/",$node->blastdb)) {
- $prop_values = explode("|", $node->blastdb);
- $node->blastdb = $prop_values[0];
- $node->blastfile = $prop_values[1];
- $node->blastparameters = $prop_values[2];
- }
- $form['blast'] = array(
- '#title' => t('Blast Settings'),
- '#type' => 'fieldset',
- '#description' => t('Specific Settings for Blast Analysis.'),
- '#collapsible' => TRUE,
- '#attributes' => array('id' => 'blast-extra-settings'),
- '#weight' => 11
- );
- $previous_db = tripal_db_set_active('chado');
-
- $sql = 'SELECT db_id, name FROM {db} ORDER BY lower(name)';
- $results = db_query ($sql);
- tripal_db_set_active($previous_db);
- $blastdbs = array();
- while ($db = db_fetch_object($results)){
- $blastdbs[$db->db_id] = $db->name;
- }
- $form['db_options'] = array(
- '#type' => 'value',
- '#value' => $blastdbs
- );
- $form['blast']['blastdb'] = array(
- '#title' => t('Database'),
- '#type' => 'select',
- '#description' => t('The database used for the blast analysis.'),
- '#options' => $form['db_options']['#value'],
- '#default_value' => $node->blastdb,
- );
- $form['blast']['blastfile'] = array(
- '#title' => t('Blast xml File: (if you input a directory without the tailing slash, all xml files in the directory will be loaded)'),
- '#type' => 'textfield',
- '#description' => t('The xml output file generated by blast in full path.'),
- '#default_value' => $node->blastfile,
- );
- $form['blast']['blastjob'] = array(
- '#type' => 'checkbox',
- '#title' => t('Submit a job to parse the xml output into analysisfeatureprop table'),
- '#description' => t('Note: features associated with the blast results must '.
- 'exist in chado before parsing the file. Otherwise, blast '.
- 'results that cannot be linked to a feature will be '.
- 'discarded. Also, Triapl Blast module needs to be enabled.'),
- '#default_value' => $node->blastjob
- );
- $form['blast']['blastparameters'] = array(
- '#title' => t('Parameters'),
- '#type' => 'textfield',
- '#description' => t('The parameters for running the blast analysis.'),
- '#default_value' => $node->blastparameters,
- );
- return $form;
- }
- function chado_analysis_blast_validate($node, &$form){
-
-
-
-
-
-
- if($node->nid){
-
-
-
-
- }
- else{
-
-
- if($node->analysis_id){
-
-
-
- }
- else{
-
-
-
-
-
-
-
- $sql = "SELECT analysis_id ".
- "FROM {analysis} ".
- "WHERE program='%s'".
- "AND programversion='%s'".
- "AND sourcename='%s'";
- $previous_db = tripal_db_set_active('chado');
- $analysis_id = db_result(db_query($sql, $node->program, $node->programversion, $node->sourcename));
- tripal_db_set_active($previous_db);
-
- if($analysis_id){
-
-
-
-
-
- $sql = "SELECT nid FROM {chado_analysis} ".
- "WHERE analysis_id = %d";
- $node_id = db_result(db_query($sql, $analysis_id));
- if($node_id){
-
-
-
-
- $error = 'This analysis already exists in the chado database (analysis id ';
- $error .= $analysis_id.') and has been synchronized ';
- $error .= 'with drupal. See node '.$node_id.' if you wish to update that analysis. ';
- $error .= ' For a new analysis, please select a unique primary key ';
- $error .= '(primary key consists of sourcename, program and programversion).';
- form_set_error('sourcename', t($error));
- }
-
- else{
-
-
-
-
- $error = 'This analysis already exists in the chado database (analysis id ';
- $error .= $analysis_id.') but has not been synchronized ';
- $error .= 'with drupal. See the tripal admin pages to synchronize. ';
- $error .= ' For a new analysis, please select a unique primary key ';
- $error .= '(primary key consists of sourcename, program and programversion).';
- form_set_error('sourcename', t($error));
- }
- }
- }
- }
- }
- function chado_analysis_blast_insert($node){
- global $user;
-
- $time = $node->timeexecuted;
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $month.'/'.$day.'/'.$year;
-
-
-
- $sql = "INSERT INTO {analysis} ".
- " (name, description, program, programversion, algorithm, ".
- " sourcename, sourceversion, sourceuri, timeexecuted) ".
- "VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')";
- $previous_db = tripal_db_set_active('chado');
- db_query($sql,$node->analysisname, $node->description,
- $node->program,$node->programversion,$node->algorithm,
- $node->sourcename, $node->sourceversion, $node->sourceuri,
- $timestamp);
-
- $sql = "SELECT analysis_id ".
- "FROM {analysis} ".
- "WHERE program='%s'".
- "AND programversion='%s'".
- "AND sourcename='%s'";
- $analysis_id = db_result(db_query($sql, $node->program,
- $node->programversion, $node->sourcename));
-
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_blast_settings' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
-
-
- $sql = "INSERT INTO {analysisprop} (analysis_id, type_id, value) ".
- "VALUES (%d, %d, '%s')";
- $blastsettings = $node->blastdb."|".$node->blastfile."|".$node->blastparameters;
- db_query($sql, $analysis_id, $type_id, $blastsettings);
- tripal_db_set_active($previous_db);
-
-
-
- if($node->blastjob) {
- $job_args[0] = $analysis_id;
- $job_args[1] = $node->blastdb;
- $job_args[2] = $node->blastfile;
- if (is_readable($node->blastfile)) {
- $fname = preg_replace("/.*\/(.*)/", "$1", $node->blastfile);
- tripal_add_job("Parse blast: $fname",'tripal_analysis_blast',
- 'tripal_analysis_blast_parseXMLFile', $job_args, $user->uid);
- } else {
- drupal_set_message("Can not open blast output file. Job not scheduled.");
- }
- }
-
- $sql = "INSERT INTO {chado_analysis} (nid, vid, analysis_id) ".
- "VALUES (%d, %d, %d)";
- db_query($sql,$node->nid,$node->vid,$analysis_id);
-
-
- $record = new stdClass();
-
-
- if ($node->analysisname) {
- $record->title = $node->analysisname;
- } else {
-
- $record->title = "$node->program ($node->programversion)";
- }
- $record->nid = $node->nid;
- drupal_write_record('node',$record,'nid');
- drupal_write_record('node_revisions',$record,'nid');
- }
- function chado_analysis_blast_delete($node){
-
-
- $sql_drupal = "SELECT analysis_id ".
- "FROM {chado_analysis} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- $analysis_id = db_result(db_query($sql_drupal, $node->nid, $node->vid));
-
- $sql_del = "DELETE FROM {chado_analysis} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node_revisions} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE analysis_id=%d";
- $results = db_query($sql, $analysis_id);
- while ($af = db_fetch_object($results)) {
- db_query("DELETE FROM {analysisfeatureprop} WHERE analysisfeature_id = %d", $af->analysisfeature_id);
- }
- db_query("DELETE FROM {analysisfeature} WHERE analysis_id = %d", $analysis_id);
- db_query("DELETE FROM {analysisprop} WHERE analysis_id = %d", $analysis_id);
- db_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
- tripal_db_set_active($previous_db);
- }
- function chado_analysis_blast_update($node){
- global $user;
- if($node->revision){
-
- } else {
-
- $time = $node->timeexecuted;
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $month.'/'.$day.'/'.$year;
-
- $sql = "SELECT analysis_id ".
- "FROM {chado_analysis} ".
- "WHERE vid = %d";
- $analysis_id = db_fetch_object(db_query($sql, $node->vid))->analysis_id;
- $sql = "UPDATE {analysis} ".
- "SET name = '%s', ".
- " description = '%s', ".
- " program = '%s', ".
- " programversion = '%s', ".
- " algorithm = '%s', ".
- " sourcename = '%s', ".
- " sourceversion = '%s', ".
- " sourceuri = '%s', ".
- " timeexecuted = '%s' ".
- "WHERE analysis_id = %d ";
- $previous_db = tripal_db_set_active('chado');
- db_query($sql, $node->analysisname, $node->description, $node->program,
- $node->programversion,$node->algorithm,$node->sourcename,
- $node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
-
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv CV ON CV.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_blast_settings' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
- $sql = "UPDATE {analysisprop} ".
- "SET value = '%s' ".
- "WHERE analysis_id = %d AND type_id = %d";
- $blastsettings = $node->blastdb."|".$node->blastfile."|".$node->blastparameters;
- db_query($sql, $blastsettings, $analysis_id, $type_id);
- tripal_db_set_active($previous_db);
-
- if($node->blastjob) {
- $job_args[0] = $analysis_id;
- $job_args[1] = $node->blastdb;
- $job_args[2] = $node->blastfile;
- if (is_readable($node->blastfile)) {
- $fname = preg_replace("/.*\/(.*)/", "$1", $node->blastfile);
- tripal_add_job("Parse blast: $fname",'tripal_analysis_blast',
- 'tripal_analysis_blast_parseXMLFile', $job_args, $user->uid);
- } else {
- drupal_set_message("Can not open blast output file. Job not scheduled.");
- }
- }
-
-
- $record = new stdClass();
-
-
- if ($node->analysisname) {
- $record->title = $node->analysisname;
- } else {
-
- $record->title = "$node->program ($node->programversion)";
- }
- $record->nid = $node->nid;
- drupal_write_record('node',$record,'nid');
- drupal_write_record('node_revisions',$record,'nid');
- }
- }
- function chado_analysis_blast_load($node){
-
- $sql = "SELECT analysis_id FROM {chado_analysis} WHERE vid = %d";
- $ana_node = db_fetch_object(db_query($sql, $node->vid));
- $additions = new stdClass();
- if ($ana_node) {
-
- $sql = "SELECT Analysis_id, name AS analysisname, description, program, ".
- " programversion, algorithm, sourcename, sourceversion, ".
- " sourceuri, timeexecuted ".
- "FROM {Analysis} ".
- "WHERE Analysis_id = $ana_node->analysis_id";
- $previous_db = tripal_db_set_active('chado');
- $additions = db_fetch_object(db_query($sql));
-
- $sql = "SELECT count(feature_id) as featurecount ".
- "FROM {Analysisfeature} ".
- "WHERE Analysis_id = %d";
- $additions->featurecount = db_result(db_query($sql, $ana_node->analysis_id));
-
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_blast_settings' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
- $sql = "SELECT value FROM {analysisprop} ".
- "WHERE analysis_id = %d ".
- "AND type_id = %d";
- $analysisprop = db_result(db_query($sql, $ana_node->analysis_id, $type_id));
- $prop_values = explode ("|", $analysisprop, 1);
- $additions->blastdb = $prop_values[0];
- $additions->blastfile = $prop_values[1];
- $additions->blastparameters = $prop_values[2];
- tripal_db_set_active($previous_db);
- }
-
-
- if ($additions->analysisname) {
- $additions->title = $additions->analysisname;
- } else {
-
- $additions->title = "$additions->program ($additions->programversion)";
- }
-
- return $additions;
- }
- function chado_analysis_blast_view ($node, $teaser = FALSE, $page = FALSE) {
-
-
- if (!$teaser) {
- $node = node_prepare($node, $teaser);
-
-
- $time = $node->timeexecuted;
- if(is_array($time)){
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $year.'-'.$month.'-'.$day;
- $node->timeexecuted = $timestamp;
- }
-
-
- if (preg_match("/.*\|.*\|.*/",$node->blastdb)) {
- $prop_values = explode("|", $node->blastdb);
- $node->blastdb = $prop_values[0];
- $node->blastfile = $prop_values[1];
- $node->blastparameters = $prop_values[2];
- }
- }
- return $node;
- }
- function tripal_analysis_blast_perm(){
- return array(
- 'access chado_analysis_blast content',
- 'create chado_analysis_blast content',
- 'delete chado_analysis_blast content',
- 'edit chado_analysis_blast content',
- );
- }
- function chado_analysis_blast_access($op, $node, $account){
- if ($op == 'create') {
- return user_access('create chado_analysis_blast content', $account);
- }
- if ($op == 'update') {
- if (user_access('edit chado_analysis_blast content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'delete') {
- if (user_access('delete chado_analysis_blast content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'view') {
- if (user_access('access chado_analysis_blast content', $account)) {
- return TRUE;
- }
- }
- return FALSE;
- }
|