Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
* Typically in a Tripal template, the data needed is retrieved using a call to
* chado_expand_var function. For example, to retrieve all
* of the feature alignments for this node, the following function call would be made:
*
* $feature = chado_expand_var($feature,'table','featureloc');
*
* However, this will return all records from the featureloc table without any context.
* To help provide context, a special variable is provided to this template named
* 'all_featurelocs'.
*
* $feature->all_featurelocs
*
* The records in the 'all_featurelocs' array are all properly arranged for easy iteration.
*
* However, access to the original alignment records is possible through the
* $feature->featureloc object. In the following ways:
*
* Alignment context #1:
* --------------------
* If the feature for this node is the parent in the alignment relationships,
* then those alignments are available in this variable:
*
* $feature->featureloc->srcfeature_id;
*
*
* Alignment context #2:
* ---------------------
* If the feature for this node is the child in the alignment relationsips,
* then those alignments are available in this variable:
*
* $feature->featureloc->feature_id;
*
*
* Alignment context #3:
* --------------------
* If the feature is aligned to another through an intermediary feature (e.g.
* a feature of type 'match', 'EST_match', 'primer_match', etc) then those
* alignments are stored in this variable:
* feature->matched_featurelocs
*
* Below is an example of a feature that may be aligned to another through
* an intermediary:
*
* Feature 1: Contig --------------- (left feature)
* Feature 2: EST_match -------
* Feature 3: EST --------- (right feature)
*
* The feature for this node is always "Feature 1". The purpose of this type
* alignment is to indicate cases where there is the potential for overhang
* in the alignments, or, the ends of the features are not part of the alignment
* prehaps due to poor quality of the ends. Blast results and ESTs mapped to
* contigs in Unigenes would fall under this category.
*
*/
$feature = $variables['node']->feature;
$alignments = $feature->all_featurelocs;
$genome_versions = bipaa_get_organisms_with_versions_from_chado();

Anthony Bretaudeau
committed
if(count($alignments) > 0){ ?>
<div class="tripal_feature-data-block-desc tripal-data-block-desc">The following features are aligned</div><?php
// the $headers array is an array of fields to use as the colum headers.
// additional documentation can be found here
// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
$headers = array('Aligned Feature' ,'Feature Type', 'Alignment Location');
// the $rows array contains an array of rows where each row is an array
// of values for each column of the table in that row. Additional documentation
// can be found here:
// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
$rows = array();
if (getenv('ENABLE_APOLLO') == "1")
$url_apollo_base = $GLOBALS['base_url'] . '/apollo/annotator/loadLink?';
else {
// Some url was given
$url_apollo_base = getenv('ENABLE_APOLLO');
if (strpos($url_apollo_base, '?') !== false)
$url_apollo_base .= '&';
else
$url_apollo_base .= 'annotator/loadLink?';
}
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
foreach ($alignments as $alignment){
$feature_name = $alignment->name;
if (property_exists($alignment, 'nid')) {
$feature_name = l($feature_name, "node/" . $alignment->nid);
}
$feature_loc = '';
$strand = '.';
if ($alignment->strand == -1) {
$strand = '-';
}
elseif ($alignment->strand == 1) {
$strand = '+';
}
// if this is a match then make the other location
if(property_exists($alignment, 'right_feature')){
$rstrand = '.';
if ($alignment->right_strand == -1) {
$rstrand = '-';
}
elseif ($alignment->right_strand == 1) {
$rstrand = '+';
}
$feature_loc = $feature->name .":". ($alignment->fmin + 1) . ".." . $alignment->fmax . " " . $strand;
$feature_loc .= "<br>" . $alignment->name .":". ($alignment->right_fmin + 1) . ".." . $alignment->right_fmax . " " . $rstrand;
}
else {
$feature_loc = $alignment->name .":". ($alignment->fmin + 1) . ".." . $alignment->fmax . " " . $strand;
}
if ($alignment->type == 'contig' && getenv('ENABLE_JBROWSE')) {
$links = getenv(JBROWSE_LINKS);
$cur_org = $feature->organism_id->abbreviation;
$dlist = explode(';', $links);
foreach ($dlist as $delem) {
$d = explode('>', $delem);
if ($cur_org === $d[0] || substr($alignment->name, 0, strlen($d[0])) === $d[0]) {
if (!$found_link) {
if (getenv('ENABLE_JBROWSE') == "1")
else {
// Some url was given
$url = getenv('ENABLE_JBROWSE');
if (strpos($url, '?') !== false)
$url .= '&';
else
$url .= '?';
}
}
$feature_loc = "<a href='".$GLOBALS['base_url'].$url."loc=".$alignment->name."%3A".($alignment->fmin + 1)."..".$alignment->fmax."'>".$feature_loc."</a>";
}
if ($alignment->type == 'contig' && getenv('ENABLE_APOLLO')) {
$links = getenv(APOLLO_LINKS);
if (!$links && getenv(JBROWSE_LINKS))
$links = getenv(JBROWSE_LINKS);
$cur_org = $feature->organism_id->abbreviation;
$dlist = explode(';', $links);
foreach ($dlist as $delem) {
$d = explode('>', $delem);
if ($cur_org === $d[0] || substr($alignment->name, 0, strlen($d[0])) === $d[0]) {
$url = $url_apollo_base."organism=".$d[1]."&";
$org_name = $feature->organism_id->genus . ' ' . $feature->organism_id->species;
$apollo_org = "&organism=" . $org_name;
if (array_key_exists($feature->organism_id->organism_id, $genome_versions)) {
$apollo_org .= ' ' . $genome_versions[$feature->organism_id->organism_id]->version;
}
$feature_loc .= " View in <a href='".$url."loc=".$alignment->name."%3A".($alignment->fmin + 1)."..".$alignment->fmax.$apollo_org."'>Apollo</a>";
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
}
$rows[] = array(
$feature_name,
$alignment->type,
$feature_loc
);
}
// the $table array contains the headers and rows array as well as other
// options for controlling the display of the table. Additional
// documentation can be found here:
// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
$table = array(
'header' => $headers,
'rows' => $rows,
'attributes' => array(
'id' => 'tripal_feature-table-alignments',
'class' => 'tripal-data-table'
),
'sticky' => FALSE,
'caption' => '',
'colgroups' => array(),
'empty' => '',
);
// once we have our table array structure defined, we call Drupal's theme_table()
// function to generate the table.
print theme_table($table);
}