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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?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 relationships for this node, the following function call would
* be made:
*
* $feature = chado_expand_var($feature,'table','feature_relationship');
*
* However, this function call can be extremely slow when there are numerous
* relationships. This is because the chado_expand_var function is recursive
* and expands all data following the foreign key relationships tree.
* Therefore, to speed retrieval of data, a special variable is provided to
* this template:
*
* $feature->all_relationships;
*
* This variable is an array with two sub arrays with the keys 'object' and
* 'subject'. The array with key 'object' contains relationships where the
* feature is the object, and the array with the key 'subject' contains
* relationships where the feature is the subject
*/
$feature = $variables['node']->feature;
$all_relationships = $feature->all_relationships;
$object_rels = $all_relationships['object'];
$subject_rels = $all_relationships['subject'];
if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
<div class="tripal_feature-data-block-desc tripal-data-block-desc"></div> <?php
// first add in the subject relationships.
foreach ($subject_rels as $rel_type => $rels){
foreach ($rels as $obj_type => $objects){
// Make the verb in the sentence make sense in English.
switch ($rel_type) {
case 'integral part of':
case 'instance of':
$verb = 'is an';
break;
case 'proper part of':
case 'transformation of':
case 'genome of':
case 'part of':
case 'position of':
case 'sequence of':
case 'variant of':
$verb = 'is a';
break;
case 'derives from':
case 'connects on':
case 'contains':
case 'finishes':
case 'guides':
case 'has origin':
case 'has part':
case 'has quality':
case 'is consecutive sequence of':
case 'maximally overlaps':
case 'overlaps':
case 'starts':
$verb = '';
break;
default:
$verb = 'is';
} ?>
<p>This <?php print $feature->type_id->name;?> <?php print $verb ?> <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> feature(s): <?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('Feature Name' ,'Unique Name', 'Species', 'Type', 'Position');
// 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();
foreach ($objects as $object){
// link the feature to it's node
$feature_name = $object->record->object_id->name;
if (property_exists($object->record, 'nid')) {
$feature_name = l($feature_name, "node/" . $object->record->nid, array('attributes' => array('target' => "_blank")));
}
// link the organism to it's node
$organism = $object->record->object_id->organism_id;
$organism_name = $organism->genus ." " . $organism->species;
if (property_exists($organism, 'nid')) {
$organism_name = l("<i>" . $organism->genus . " " . $organism->species . "</i>", "node/" . $organism->nid, array('html' => TRUE));
}
$location = '?';
if (isset($object->parent_featurelocs[0])) {
$loc = $object->parent_featurelocs[0];
$location = $loc->srcfeature_name.' '. ($loc->fmin + 1) . ".." . $loc->fmax . " " . ($loc->strand == -1 ? '-' : '+');
}
$rows[] = array(
array('data' => $feature_name, 'width' => '28%'),
array('data' => $object->record->object_id->uniquename, 'width' => '25%'),
array('data' => $organism_name, 'width' => '25%'),
array('data' => $object->record->object_id->type_id->name, 'width' => '12%'),
array('data' => $location, 'width' => '12%'),
);
}
// 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-relationship-object',
'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); ?>
</p>
<br><?php
}
}
// second add in the object relationships.
foreach ($object_rels as $rel_type => $rels){
foreach ($rels as $subject_type => $subjects){
// Make the verb in the sentence make sense in English.
switch ($rel_type) {
case 'integral part of':
case 'instance of':
$verb = 'are an';
break;
case 'proper part of':
case 'transformation of':
case 'genome of':
case 'part of':
case 'position of':
case 'sequence of':
case 'variant of':
$verb = 'are a';
break;
case 'derives from':
case 'connects on':
case 'contains':
case 'finishes':
case 'guides':
case 'has origin':
case 'has part':
case 'has quality':
case 'is consecutive sequence of':
case 'maximally overlaps':
case 'overlaps':
case 'starts':
$verb = '';
break;
default:
$verb = 'are';
} ?>
<p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> feature(s) <?php print $verb ?> <?php print $rel_type ?> this <?php print $feature->type_id->name;?>: <?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('Feature Name' ,'Unique Name', 'Species', 'Type', 'Position');
// 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();
foreach ($subjects as $subject){
// link the feature to it's node
$feature_name = $subject->record->subject_id->name;
if (property_exists($subject->record, 'nid')) {
$feature_name = l($feature_name, "node/" . $subject->record->nid, array('attributes' => array('target' => "_blank")));
}
// link the organism to it's node
$organism = $subject->record->subject_id->organism_id;
$organism_name = $organism->genus ." " . $organism->species;
if (property_exists($organism, 'nid')) {
$organism_name = l("<i>" . $organism->genus . " " . $organism->species . "</i>", "node/" . $organism->nid, array('html' => TRUE));
}
$location = '?';
if (isset($subject->child_featurelocs[0])) {
$loc = $subject->child_featurelocs[0];
$location = $loc->srcfeature_name.' '. ($loc->fmin + 1) . ".." . $loc->fmax . " " . ($loc->strand == -1 ? '-' : '+');
}
$rows[] = array(
array('data' => $feature_name, 'width' => '28%'),
array('data' =>$subject->record->subject_id->uniquename, 'width' => '25%'),
array('data' =>$organism_name, 'width' => '25%'),
array('data' =>$subject->record->subject_id->type_id->name, 'width' => '12%'),
array('data' => $location, 'width' => '12%'),
);
}
// 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-relationship-subject',
'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); ?>
</p>
<br><?php
}
}
}