Эх сурвалжийг харах

updated the local__gbrowse_image field so it can be species specific

Stephen Ficklin 6 жил өмнө
parent
commit
e0053a5e7b

+ 24 - 3
tripal_chado/includes/TripalFields/local__gbrowse_image/local__gbrowse_image.inc

@@ -82,8 +82,25 @@ class local__gbrowse_image extends ChadoField {
     }
     
     // Replace any tokens in the string.
+    $gbrowse_url = NULL;
+    $g_urls = $settings['gbrowse_url'];   
+    $g_urls = explode("\n", $g_urls);
+    foreach ($g_urls as $g_url) {
+      $matches = [];
+      if (preg_match('/^(.*)\s+(.*)\s+(http.*)$/', $g_url, $matches)) {
+        if ($record->organism_id->genus == $matches[1] and
+            $record->organism_id->species == $matches[2]) {
+          $gbrowse_url = $matches[3];
+        }
+      }
+      elseif (preg_match('/^http.*$/', $g_url)) {
+        $gbrowse_url = $g_url;
+      }
+    }
+    if (!$gbrowse_url) {
+      return;
+    }
     $bundle = tripal_load_bundle_entity(['name' => $this->instance['bundle']]);
-    $gbrowse_url = $settings['gbrowse_url'];   
     $gbrowse_url = tripal_replace_entity_tokens($gbrowse_url, $entity, $bundle);
         
     // Use the term associated to the db.url table of Chado.
@@ -111,7 +128,11 @@ class local__gbrowse_image extends ChadoField {
         'field values from this content type. Open the "Available Tokens" fieldset below. ' .
         'For example, to show a view of a gene from the rice genome GBrowse the ' .
         'following URL with tokens can be used: ' . 
-        'http://rice.plantbiology.msu.edu/cgi-bin/gbrowse_img/rice/?name=[schema__name];type=Landmarks%3Aregion+Genes+Rice_Annotation'),
+        'http://rice.plantbiology.msu.edu/cgi-bin/gbrowse_img/rice/?name=[schema__name];type=Landmarks%3Aregion+Genes+Rice_Annotation' . 
+        '. If you need to specify different GBrowse URLs for different ' .
+        'species, put the genus, species and URL all on one line with each separated ' . 
+        'by a space. For example: ' . 
+        '"Oryza sativa http://rice.plantbiology.msu.edu/cgi-bin/gbrowse_img/rice/?name=[schema__name];type=Landmarks%3Aregion+Genes+Rice_Annotation"'),
       '#default_value' => $settings['gbrowse_url'],
     );
     
@@ -150,4 +171,4 @@ class local__gbrowse_image extends ChadoField {
     
     return $element;
   }
-}
+}

+ 8 - 6
tripal_chado/includes/TripalFields/local__gbrowse_image/local__gbrowse_image_formatter.inc

@@ -14,13 +14,15 @@ class local__gbrowse_image_formatter extends ChadoFieldFormatter {
     $content = '';
     if (count($items) > 0) {
       $url_term = chado_get_semweb_term('db', 'url');
-      $content = '<img src="' . $items[0]['value'][$url_term] . '" class="tripal-local--gbrowse-image"/>';
+      if (is_array($items[0]['value']) and array_key_exists($url_term, $items[0]['value'])) {
+        $content = '<img src="' . $items[0]['value'][$url_term] . '" class="tripal-local--gbrowse-image"/>';
       
-      $element[0] = array(
-        // We create a render array to produce the desired markup,
-        '#type' => 'markup',
-        '#markup' => $content,
-      );
+        $element[0] = array(
+          // We create a render array to produce the desired markup,
+          '#type' => 'markup',
+          '#markup' => $content,
+        );
+      }
     }
   }
 }