Drupal Views is a powerful 3rd-party module that allows an authorized user to query database tables in novel and unique ways and to create custom pages and search forms. Tripal has fully integrated the Chado database tables with Drupal Views.
Adding a New View
As an introduction to Drupal Views, we will create a new page without any PHP or HTML programming. To create a new view navigate to Structure → Views and click the Add new view link near the top of the page. Here you see brief configuration page:
Suppose we want to create a species page for our site that lists all of the available species that our site houses. Tripal provides "teasers" for all of its pages. A teaser is a brief set of contents about a page. So, we want the species page to be a list of organism page teasers. To do this, enter the following
- View name: All species
- Show: Content
- of type: Organism
- sorted by: Title
- Page title: Species
- Path: http://localhost/species
- Display format: Unformatted, list of teasers, with links, without comments
- Items to Display: 10
- Use a Pager: checked
- Create a menu link: checked
- Menu: Main menu
- Link text: Species
Despite that we will be creating a list of species, we select Show as Content. This is because all nodes (nodes are pages in Drupal lingo) have teasers. So, we want to use the node teasers. If however, we wanted to use content directly from the Chado organism table then we would have selected Chado Organism. The settings above also specify a page title, a filter to include only nodes (pages) of the Organism type, a URL for the page and details for adding the page to the main menu of the site. Click the Save & Exit button. There should now be a link in the main menu at the top left of the page titled Species. If we click that link we can now see our new species page:
You can make changes to the view by click the cog in the upper right corner of the content section, or navigate to Structure → Views and click the edit link next to the view we just added.
Editing Existing Views
Many of the basic search tools available under the Search Data menu item are Drupal Views and hence can be customized using the Views interface. As a brief introduction to views we will examine one of these views and customize it. In order to use Views you need a basic understanding of the Chado tables.
First, navigate to Structure → Views
Here we see the list of the views that have already been created. All of the Tripal views were created automatically by Tripal modules when they were enabled. At the bottom of the page are inactive views that come by default with the Views module. Scroll to the view titled Feature User Search and click the Edit button to the right of it. You will see the following page:
On this page you will see several sections: Title, Format, Fields, Filter Criteria, Sort Criteria, Page Settings and a few others. This tutorial will not describe all of these settings. There are tutorials on the web that better explain these fields. For this tutorial we will discuss only a few of them.
Briefly, the Fields section lists the fields that will be used for the view. For example, in this view we will be using the feature's uniquename, name, type, organism common name and a few other fields from the Chado feature table. We also have the node ID of the Drupal node that corresponds to the feature.
The Sort criteria section lists the order in which results will be shown. The results will be sorted by organism common name, feature type and feature name, in that order.
The Filters section provides a set of criteria for limiting which records will be shown. We want to limit the results by common name, feature type and feature name. The filters are used to create the search form at the top of the features search page:
Suppose we do not like the way our search pages behaves. Currently, for features, when search results are returned we see the unique name, name, feature type, common name of the organism, sequence length, if the sequence is obsolete and the date it was accessioned. We do not want the sequence length, or if the sequence is obsolete or the date it was accessioned to appear in our search results. And, suppose we want the genus and species to be listed instead of the common name. We can make these changes by editing the view settings.
First, we need to add the genus and species as fields to show. To do this, click Add in the header of the Fields section. In the overlay a list of available fields will appear:
In the Filter Drop down you can see the Groups of fields associated with features. These groups correspond to Chado tables. Select the group Chado Organism. This reduces the list of fields to only those associated with the Chado orgnaism table. Click the checkbox for Chado Organism: Genus and Chado Organism: Species and click Apply (all displays).
Next we see a set of configuration settings for the fields we selected. In this case, we see configuration settings for the Genus field first.
Views will let you control a lot of how the field is seen (or not seen) in the page results. Here we want to leave all the defaults. click the Apply (all displays) button at the bottom. The configuration settings for the Species field now appears. Leave the defaults as well and click Apply (all displays). Now that we are done configuring our new fields we can preview the changes by viewing the example at the bottom of the page. Below is a screen shot of the view after we have added our new fields:
Now, we want to remove the unwanted fields. In the Fields section, click on the field named Chado Feature: Seqlen (Sequence Length). A configuration page appears similar to what we saw previously for Genus and Species. Check the box Exclude from display. This will leave the field present in the list of fields but will not show it in the resulting view. Click the Apply (all displays) button. Do the same for the common name, and is obsolete fields. Alternatively, if we no longer want to keep this field in the view, then we could remove the field by clicking the Remove button. Our view now appears as follows:
Next, we want to limit results to only those with synced pages. Currently any feature present in the database is visible in the list, but we only have pages for genes and mRNA features. To limit the results only to synced features first locate the Filter Criteria' section and click the Add button in the header. In the Filter dropdown, select Content. The list of available fields for a Drupal node are available to select. All nodes must have a node ID. Therefore, we can filter results to exclude those that do not have a node ID. Look for the element titled Content: Nid, select it, and click the Apply (all displays button. A configuration screen appears:
We want to only show features that have a page which means that the Node ID (Nid) must not be empty. Therefore, select the is not empty(NOT NULL) from the operator dropdown and click Apply (all displays). Now, only synced features (those with pages) will appear in the list.
Next, in the view preview the Type Id dropdown field used for filtering the results by feature type contains all available feature types. However, because we have limited our view to only show features with pages we also need to limit this list. We can easily do this by clicking the Chado Feature: Type Id field in the Filter Criteria section. On the configuration overlay that appears, click the Grouped Filters radio button under Filter type to expose. A new box appears that allows you to add the values that should appear in the drop down. We will limit search capabilities to just mRNA and genes as these are the two types of features that we have pages for. Add these two values as shown in the screen shot below and click the Apply (all displays button.
Now, the Type Id dropdown only contains gene and mRNA. We can similarly limit the values that appear in the Organism Common Name dropdown as well. If we click the Save button at the top right of the page, then this will save all of the changes we have made to the view and the Features search page under Search Data will be updated.
We have only touched on a few of the capabilities of the Views interface. You can create advanced looking forms and pages using Views.