forked from tripal/tripal_synview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynview.module
executable file
·635 lines (568 loc) · 25.4 KB
/
synview.module
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
<?php
/**
* @file
* The main file for the tripal go module.
*/
// Application Programmers Interface
require_once 'api/synview.api.inc';
// insert/delete synteny blocks according to synteny file
require_once 'includes/synview.syn_parser.inc';
// synteny Node functionality
require_once 'includes/synview.node.inc';
// Functions specific to themeing (ie: preprocess)
require_once 'theme/synview.theme.inc';
// Administration for furture
//require_once 'includes/synview.admin.inc';
/**
* Implements hook_menu().
*/
function synview_menu() {
// search syntenic block form
$items['synview/search'] = array(
'title' => 'Search Syntenic Blocks',
'page callback' => 'drupal_get_form',
'page arguments' => array('synview_search_form'),
'access arguments' => array('access content'),
'file' => 'includes/synview_search_form.inc',
'type' => MENU_NORMAL_ITEM,
);
// display search result
$items['synview/search/result/%'] = array(
'title' => 'Search Result for Syntenic Blocks',
'page callback' => 'synview_search_result',
'page arguments' => array(3),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
// synteny (MCScanX) dataset Node
$items['node__syn'] = array(
'template' => 'node--syn',
'render element' => 'node',
'base hook' => 'node',
'path' => 'themesyn',
);
// Display Syntenic Block
$items['synview/block/%'] = array(
'title' => 'Display Syntenic Blocks',
'page callback' => 'display_block',
'page arguments' => array(2),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
// help
$items['admin/tripal/extension/tripal_synview'] = array(
'title' => 'Tripal Synview',
'description' => 'Tripal Synview Configuration',
'page callback' => 'drupal_get_form',
'page arguments' => array('tripal_synview_admin_settings'),
'access arguments' => array('administer tripal'),
'type' => MENU_NORMAL_ITEM,
);
// help
$items['admin/tripal/extension/tripal_synview/help'] = array(
'title' => 'Help',
'page callback' => 'theme',
'page arguments' => array('synview_help'),
'access arguments' => array('administer tripal'),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function tripal_synview_admin_settings () {
$form = array();
$form['feature_type1'] = array(
'#type' => 'select',
'#title' => 'Feature Type 1',
'#description' => t('For Genome1, synteny analysis was performed using this feaure type.'),
'#options' => array('gene' => 'gene', 'mRNA' => 'mRNA', 'CDS' => 'CDS'),
'#default_value' => variable_get('tripal_synview_feature_type1', 'mRNA'),
);
$form['feature_type2'] = array(
'#type' => 'select',
'#title' => 'Feature Type 2',
'#description' => t('For Genome2, synteny analysis was performed using this feaure type.'),
'#options' => array('gene' => 'gene', 'mRNA' => 'mRNA', 'CDS' => 'CDS'),
'#default_value' => variable_get('tripal_synview_feature_type2', 'mRNA'),
);
$form['block_examples'] = array(
'#type' => 'textfield',
'#title' => 'Block Examples',
'#description' => 'Block example to show on the Synview Search form',
'#default_value' => variable_get('tripal_synview_block_examples', t("'hjhnB1908' or 'abrjB0957'"))
);
$form['genomes'] = array(
'#type' => 'fieldset',
'#title' => 'Genome Grouping',
'#description' => 'Categorize genomes into groups so synteny comparison will be made only within each group.
For example, you can have prokaryote and eukaryote groups so that the genomes in one group
won\'t be compared to the ones in the other group. Please note that if you enable the grouping,
genomes that do not belong to any group will not be shown. Clearing all group names will reset
Synteny Viewer to no grouping.',
'#collapsible' => TRUE,
'#collapsed' => FALSE
);
$gtitle = variable_get('tripal_synview_grouping_title', 'Genome Category');
$form['genomes']['grouping_title'] = array(
'#type' => 'textfield',
'#title' => 'Title (Display Only)',
'#description' => 'Title to show on the search form for genome grouping',
'#default_value' => $gtitle,
);
$genomes = tripal_synview_get_genomes(TRUE);
asort($genomes);
$genome_groups = variable_get('tripal_synview_genome_groups', array());
$gval = array();
foreach ($genome_groups AS $k => $vals) {
foreach ($vals AS $id => $v) {
$gval[$id] = $k;
}
}
foreach ($genomes AS $analysis_id => $genome) {
$form['genomes']['genome_' . $analysis_id] = array(
'#type' => textfield,
'#title' => 'Group for ' . $genome,
'#default_value' => isset($gval[$analysis_id]) ? $gval[$analysis_id] : '',
);
}
$disabled_genomes = variable_get('tripal_synview_disabled_genomes', array());
$form['disabled_genomes'] = array(
'#type' => 'checkboxes',
'#options' => $genomes,
'#title' => 'Disable the following genome(s) from the Synview search form',
'#description' => "Check boxes for the unpublished genomes that you want to hide from the users.",
'#default_value' => $disabled_genomes
);
return system_settings_form($form);
}
function tripal_synview_admin_settings_validate($form, &$form_state) {
// featyre types
$ftype1= $form_state['values']['feature_type1'];
$ftype2= $form_state['values']['feature_type2'];
variable_set('tripal_synview_feature_type1', $ftype1);
variable_set('tripal_synview_feature_type2', $ftype2);
//block examples
$block_examples = $form_state['values']['block_examples'];
variable_set('tripal_synview_block_examples', $block_examples);
// genome grouping
$genomes = tripal_synview_get_genomes(TRUE);
$genome_groups = array();
$has_group = FALSE;
foreach ($genomes AS $analysis_id => $genome) {
$grp = trim($form_state['values']['genome_' . $analysis_id]);
if ($grp) {
$has_group = TRUE;
if (array_key_exists($grp, $genome_groups)) {
$genome_groups[$grp][$analysis_id] = $genome;
}
else {
$genome_groups[$grp] = array($analysis_id => $genome);
}
}
}
$gtitle = $form_state['values']['grouping_title'];
variable_set('tripal_synview_grouping_title', $gtitle);
if ($has_group) {
variable_set('tripal_synview_genome_groups', $genome_groups);
}
else {
variable_del('tripal_synview_genome_groups');
}
// hide genomes
$disabled_genomes = $form_state['values']['disabled_genomes'];
variable_set('tripal_synview_disabled_genomes', $disabled_genomes);
}
/**
* Implements hook_theme().
*/
function synview_theme() {
$items = array();
$path = drupal_get_path('module', 'synview');
// explain the detail
// this hook create a array of theme through array item
// the key in array is like show_goenrich_report
// the value tell drupal where to find template page
// template: template name, and file must has suffix .tpl.php
// path: where to find template file
// use theme('key') to call the them
// search result
$items['synview_search_result'] = array(
'template' => 'synview_search_result',
'path' => "$path/theme",
);
// Displays the pwy enrich results for each job
$items['display_block'] = array(
'template' => 'display_block',
'path' => "$path/theme",
);
// Module Help
$items['synview_help'] = array(
'template' => 'synview_help',
'path' => "$path/theme",
);
$items['tripal_feature_synteny'] = array(
'variables' => array('node' => NULL),
'template' => 'tripal_feature_synteny', //template file name without .tpl.php
'path' => $path . '/tripal_feature', // the path of tpl file
);
return $items;
}
/**
* Implements hook_help().
*/
function synview_help($path, $arg) {
if ($path == 'admin/help#synview') {
return theme('synview_help');
}
}
/**
* Dispaly single block
*
* @param $block_id
*
* @return $result
* Return HTML output of the block to be displayed to the user
*
*/
function display_block($block_id) {
return theme('display_block', array('block_id' => $block_id));
}
/**
* retrieve blocks from drupal database according to location
*
* @param org_id chr start end array_of_ref_org_id
*
* @return $block
* array of searched blocks
*/
function synview_search_result($action) {
if (!array_key_exists('tripal_synview_search', $_SESSION)) {
drupal_goto('synview/search');
}
$analysis_id = $_SESSION['tripal_synview_search']['SELECT_GENOME'];
$chr = $_SESSION['tripal_synview_search']['SELECT_CHR'];
//$start = $_SESSION['tripal_synview_search']['START'];
//$end = $_SESSION['tripal_synview_search']['END'];
$ref_genome = $_SESSION['tripal_synview_search']['refGenome'];
//dpm('SELECTED GENOME: ' . $analysis_id);
//dpm(array('REF GENOMES' => $ref_genome));
//$end_pos = $_SESSION['tripal_synview_search']['RLEN'][$org_id][$chr];
//dpm($_SESSION['tripal_synview_search']);
/* if ($action) {
if ($action == 'left') {
if ($start > 100000) {
$start = $start - 1000000;
} else {
$start = 1;
}
if ($end > 1000000) {
$end = $end - 1000000;
}
}
elseif ($action == 'right') {
if ($end < $end_pos - 1000000) {
$end = $end + 1000000;
} else {
$end = $end_pos;
}
if ($start < $end - 1000000) {
$start = $start + 1000000;
}
}
else {
}
} */
//$_SESSION['tripal_synview_search']['START'] = $start;
//$_SESSION['tripal_synview_search']['END'] = $end;
$genome_opts = tripal_synview_get_genomes();
get_reference($genome_opts);
// search block on one organism of select chrosome
// find block between start and end, also cover start and end,
$args = array(
':type_name' => 'syntenic_region',
':analysis_id' => $analysis_id,
':chr' => $chr
);
$where_location = '';//"AND
// ((FL.fmin < :start AND FL.fmax > :start) OR
// (FL.fmin < :end AND FL.fmax > :end) OR
// (FL.fmin > :start AND FL.fmax < :end)
// )";
//$args[':start'] = $start;
//$args[':end'] = $end;
$sql = "SELECT F.feature_id, F.name, FL.srcfeature_id, FL.fmin, FL.fmax, FL.strand
FROM chado.feature F
LEFT JOIN chado.cvterm CVT ON F.type_id = CVT.cvterm_id
LEFT JOIN chado.featureloc FL ON F.feature_id = FL.feature_id
INNER JOIN chado.analysisfeature AF ON AF.feature_id = FL.srcfeature_id
WHERE
CVT.name = :type_name AND AF.analysis_id = :analysis_id AND FL.srcfeature_id = :chr
$where_location
ORDER BY FL.fmin
";
$results = chado_query($sql, $args);
// get all the feature_id of selected synteny_region
// then retrieve all corresponding synteny_regions in other organisms of these selected synteny_region
$search_feature_id = array();
$search_results = array();
foreach ($results as $r) {
$search_feature_id[] = $r->feature_id;
$search_results[$r->feature_id] = $r;
}
$sql = "SELECT S.blockid, S.b1, S.b2, S.score, S.evalue FROM synblock S
WHERE S.b1 IN (:bid) OR S.b2 IN (:bid)";
$res = chado_query($sql, array(':bid' => $search_feature_id));
// filter the result by $ref_genome
// only the blocks in match ref_org will be exported
$blocks = array();
// the array syn_region used for store region information
$syn_region = array();
// jdata: array for json data
$jdata = array();
$sql_loc = "
SELECT
FL.srcfeature_id,
FL.feature_id,
FL.fmin,
FL.fmax,
FL.strand,
AF.analysis_id,
(SELECT name FROM {analysis} Where analysis_id = AF.analysis_id) AS genome,
(SELECT value FROM {analysisprop} Where analysis_id = AF.analysis_id AND type_id = (SELECT cvterm_id FROM {cvterm} WHERE name = 'Short Name' AND cv_id = (SELECT cv_id FROM {cv} WHERE name = 'analysis_property'))) AS short_name
FROM {featureloc} FL
INNER JOIN {analysisfeature} AF ON AF.feature_id = FL.srcfeature_id WHERE FL.feature_id = :feature_id";
$counter = 0;$option = 0;
foreach ($res as $b) {
$counter ++;
// filter the reference organism
// b1 and b2 are selected org
$loc1 = chado_query($sql_loc, array(':feature_id'=>$b->b1))->fetchObject();
$loc2 = chado_query($sql_loc, array(':feature_id'=>$b->b2))->fetchObject();
// ignore the genomes that are not selected for comparsion
if (!key_exists($loc1->analysis_id, $ref_genome) && !key_exists($loc2->analysis_id, $ref_genome)) {
continue;
}
//if ($counter == 1) {dpm(array('genome1' => $loc1->analysis_id, 'genome2' => $loc2->analysis_id));}
if ($loc1->analysis_id == $analysis_id and $loc2->analysis_id == $analysis_id)
{
// if ($option <> 1) {dpm('OPTION1: b1 an b2 are both from selected genome');$option = 1;}
$b->b1_genome = $loc1->genome;
$b->b1_sid = $_SESSION['tripal_synview_search']['REF'][$loc1->analysis_id][$loc1->srcfeature_id];
$b->b1_len = $_SESSION['tripal_synview_search']['RLEN'][$loc1->analysis_id][$loc1->srcfeature_id];
$b->b1_fmin = $loc1->fmin;
$b->b1_fmax = $loc1->fmax;
$b->b1_strand = $loc1->strand;
$b->b2_genome = $loc2->genome;
$b->b2_sid = $_SESSION['tripal_synview_search']['REF'][$loc2->analysis_id][$loc2->srcfeature_id];
$b->b2_len = $_SESSION['tripal_synview_search']['RLEN'][$loc2->analysis_id][$loc2->srcfeature_id];
$b->b2_fmin = $loc2->fmin;
$b->b2_fmax = $loc2->fmax;
$b->b2_strand = $loc2->strand;
$blocks[$b->blockid] = $b;
// build array for json
if (!array_key_exists($loc1->analysis_id, $jdata) ) {
$jdata[$loc1->analysis_id] = array();
$jdata[$loc1->analysis_id]['name'] = $loc1->genome;
$jdata[$loc1->analysis_id]['short_name'] = $loc1->short_name;
$jdata[$loc1->analysis_id]['canvas'] = 'canvas' . $loc1->analysis_id;
$jdata[$loc1->analysis_id]['ideoCollection'] = array();
$jdata[$loc1->analysis_id]['bedCollection'] = array();
$jdata[$loc1->analysis_id]['linkCollection'] = array();
$jdata[$loc1->analysis_id]['labCollection'] = array();
}
if (!array_key_exists($b->b1_sid, $jdata[$loc1->analysis_id]['ideoCollection']) ) {
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b1_sid] = array();
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b1_sid]['id'] = $b->b1_sid;
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b1_sid]['length'] = $b->b1_len / 1000000;
$loc1->srcfeature_id == $_SESSION['tripal_synview_search']['SELECT_CHR'] ? $jdata[$loc1->analysis_id]['ideoCollection'][$b->b1_sid]['color'] = 'blue' : $jdata[$loc1->analysis_id]['ideoCollection'][$b->b1_sid]['color'] = 'red';
}
if (!array_key_exists($b->b2_sid, $jdata[$loc1->analysis_id]['ideoCollection']) ) {
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b2_sid] = array();
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b2_sid]['id'] = $b->b2_sid;
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b2_sid]['length'] = $b->b2_len / 1000000;
$loc2->srcfeature_id == $_SESSION['tripal_synview_search']['SELECT_CHR'] ? $jdata[$loc1->analysis_id]['ideoCollection'][$b->b2_sid]['color'] = 'blue' : $jdata[$loc1->analysis_id]['ideoCollection'][$b->b2_sid]['color'] = 'red';
}
if (!array_key_exists($b->blockid, $jdata[$loc1->analysis_id]['bedCollection']) ) {
$jdata[$loc1->analysis_id]['bedCollection'][] = array(
'chr' => $b->b1_sid,
'start' => $b->b1_fmin / 1000000,
'end' => $b->b1_fmax / 1000000,
'id' => $b->blockid, 'color' => 'green');
$jdata[$loc1->analysis_id]['bedCollection'][] = array(
'chr' => $b->b2_sid,
'start' => $b->b2_fmin / 1000000,
'end' => $b->b2_fmax / 1000000,
'id' => $b->blockid, 'color' => 'green');
$jdata[$loc1->analysis_id]['linkCollection'][] = array(
'bid' => $b->blockid,
'source' => $jdata[$loc1->analysis_id]['bedCollection'][count($jdata[$loc1->analysis_id]['bedCollection'])-2],
'target' => $jdata[$loc1->analysis_id]['bedCollection'][count($jdata[$loc1->analysis_id]['bedCollection'])-1]);
}
}
// b1 is ref orgs, b2 is select org
elseif (array_key_exists($loc1->analysis_id, $ref_genome) and $loc2->analysis_id == $analysis_id )
{
// if ($option <> 2) {dpm('OPTION2: b1 is one of the reference genomes and b2 is from selected genome');$option = 2;}
$r = $search_results[$b->b2];
$b->b1_genome = $loc1->genome;
$b->b1_sid = $_SESSION['tripal_synview_search']['REF'][$loc1->analysis_id][$loc1->srcfeature_id];
$b->b1_len = $_SESSION['tripal_synview_search']['RLEN'][$loc1->analysis_id][$loc1->srcfeature_id];
$b->b1_fmin = $loc1->fmin;
$b->b1_fmax = $loc1->fmax;
$b->b1_strand = $loc1->strand;
$b->b2_genome = $loc2->genome;
$b->b2_sid = $_SESSION['tripal_synview_search']['REF'][$loc2->analysis_id][$r->srcfeature_id];
$b->b2_len = $_SESSION['tripal_synview_search']['RLEN'][$loc2->analysis_id][$r->srcfeature_id];
$b->b2_fmin = $r->fmin;
$b->b2_fmax = $r->fmax;
$b->b2_strand = $r->strand;
$blocks[$b->blockid] = $b;
// build array for json
if (!array_key_exists($loc1->analysis_id, $jdata) ) {
$jdata[$loc1->analysis_id] = array();
$jdata[$loc1->analysis_id]['name'] = $loc1->genome;
$jdata[$loc1->analysis_id]['short_name'] = $loc1->short_name;
$jdata[$loc1->analysis_id]['canvas'] = 'canvas' . $loc1->analysis_id;
$jdata[$loc1->analysis_id]['ideoCollection'] = array();
$jdata[$loc1->analysis_id]['bedCollection'] = array();
$jdata[$loc1->analysis_id]['linkCollection'] = array();
$jdata[$loc1->analysis_id]['labCollection'] = array();
}
if (!array_key_exists($b->b1_sid, $jdata[$loc1->analysis_id]['ideoCollection']) ) {
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b1_sid] = array();
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b1_sid]['id'] = $b->b1_sid;
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b1_sid]['length'] = $b->b1_len / 1000000;
$loc1->srcfeature_id == $_SESSION['tripal_synview_search']['SELECT_CHR'] ? $jdata[$loc1->analysis_id]['ideoCollection'][$b->b1_sid]['color'] = 'blue' : $jdata[$loc1->analysis_id]['ideoCollection'][$b->b1_sid]['color'] = 'red';
}
if (!array_key_exists($b->b2_sid, $jdata[$loc1->analysis_id]['ideoCollection']) ) {
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b2_sid] = array();
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b2_sid]['id'] = $b->b2_sid;
$jdata[$loc1->analysis_id]['ideoCollection'][$b->b2_sid]['length'] = $b->b2_len / 1000000;
$r->srcfeature_id == $_SESSION['tripal_synview_search']['SELECT_CHR'] ? $jdata[$loc1->analysis_id]['ideoCollection'][$b->b2_sid]['color'] = 'blue' : $jdata[$loc1->analysis_id]['ideoCollection'][$b->b2_sid]['color'] = 'red';
}
if (!array_key_exists($b->blockid, $jdata[$loc1->analysis_id]['bedCollection']) ) {
$jdata[$loc1->analysis_id]['bedCollection'][] = array(
'chr' => $b->b1_sid,
'start' => $b->b1_fmin / 1000000,
'end' => $b->b1_fmax / 1000000,
'id' => $b->blockid, 'color' => 'green');
$jdata[$loc1->analysis_id]['bedCollection'][] = array(
'chr' => $b->b2_sid,
'start' => $b->b2_fmin / 1000000,
'end' => $b->b2_fmax / 1000000,
'id' => $b->blockid, 'color' => 'green');
$jdata[$loc1->analysis_id]['linkCollection'][] = array(
'bid' => $b->blockid,
'source' => $jdata[$loc1->analysis_id]['bedCollection'][count($jdata[$loc1->analysis_id]['bedCollection'])-2],
'target' => $jdata[$loc1->analysis_id]['bedCollection'][count($jdata[$loc1->analysis_id]['bedCollection'])-1]);
}
}
elseif (array_key_exists($loc2->analysis_id, $ref_genome) and $loc1->analysis_id == $analysis_id )
{
// if ($option <> 3) {dpm('OPTION3: b2 is one of the reference genomes and b1 is from selected genome');$option = 3;}
$r = $search_results[$b->b1];
$b->b1_genome = $loc1->genome;
$b->b1_sid = $_SESSION['tripal_synview_search']['REF'][$loc1->analysis_id][$r->srcfeature_id];
$b->b1_len = $_SESSION['tripal_synview_search']['RLEN'][$loc1->analysis_id][$r->srcfeature_id];
$b->b1_fmin = $r->fmin;
$b->b1_fmax = $r->fmax;
$b->b1_strand = $r->strand;
$b->b2_genome = $loc2->genome;
$b->b2_sid = $_SESSION['tripal_synview_search']['REF'][$loc2->analysis_id][$loc2->srcfeature_id];
$b->b2_len = $_SESSION['tripal_synview_search']['RLEN'][$loc2->analysis_id][$loc2->srcfeature_id];
$b->b2_fmin = $loc2->fmin;
$b->b2_fmax = $loc2->fmax;
$b->b2_strand = $loc2->strand;
$blocks[$b->blockid] = $b;
// build array for json
if (!array_key_exists($loc2->analysis_id, $jdata) ) {
$jdata[$loc2->analysis_id] = array();
$jdata[$loc2->analysis_id]['name'] = $loc2->genome;
$jdata[$loc2->analysis_id]['short_name'] = $loc2->short_name;
$jdata[$loc2->analysis_id]['canvas'] = 'canvas' . $loc2->analysis_id;
$jdata[$loc2->analysis_id]['ideoCollection'] = array();
$jdata[$loc2->analysis_id]['bedCollection'] = array();
$jdata[$loc2->analysis_id]['linkCollection'] = array();
$jdata[$loc2->analysis_id]['labCollection'] = array();
}
if (!array_key_exists($b->b1_sid, $jdata[$loc2->analysis_id]['ideoCollection']) ) {
$jdata[$loc2->analysis_id]['ideoCollection'][$b->b1_sid] = array();
$jdata[$loc2->analysis_id]['ideoCollection'][$b->b1_sid]['id'] = $b->b1_sid;
$jdata[$loc2->analysis_id]['ideoCollection'][$b->b1_sid]['length'] = $b->b1_len / 1000000;
$r->srcfeature_id == $_SESSION['tripal_synview_search']['SELECT_CHR'] ? $jdata[$loc2->analysis_id]['ideoCollection'][$b->b1_sid]['color'] = 'blue' : $jdata[$loc2->analysis_id]['ideoCollection'][$b->b1_sid]['color'] = 'red';
}
if (!array_key_exists($b->b2_sid, $jdata[$loc2->analysis_id]['ideoCollection']) ) {
$jdata[$loc2->analysis_id]['ideoCollection'][$b->b2_sid] = array();
$jdata[$loc2->analysis_id]['ideoCollection'][$b->b2_sid]['id'] = $b->b2_sid;
$jdata[$loc2->analysis_id]['ideoCollection'][$b->b2_sid]['length'] = $b->b2_len / 1000000;
$loc2->srcfeature_id == $_SESSION['tripal_synview_search']['SELECT_CHR'] ? $jdata[$loc2->analysis_id]['ideoCollection'][$b->b2_sid]['color'] = 'blue' : $jdata[$loc2->analysis_id]['ideoCollection'][$b->b2_sid]['color'] = 'red';
}
if (!array_key_exists($b->blockid, $jdata[$loc2->analysis_id]['bedCollection']) ) {
$jdata[$loc2->analysis_id]['bedCollection'][] = array(
'chr' => $b->b1_sid,
'start' => $b->b1_fmin / 1000000,
'end' => $b->b1_fmax / 1000000,
'id' => $b->blockid, 'color' => 'green');
$jdata[$loc2->analysis_id]['bedCollection'][] = array(
'chr' => $b->b2_sid,
'start' => $b->b2_fmin / 1000000,
'end' => $b->b2_fmax / 1000000,
'id' => $b->blockid, 'color' => 'green');
$jdata[$loc2->analysis_id]['linkCollection'][] = array(
'bid' => $b->blockid,
'source' => $jdata[$loc2->analysis_id]['bedCollection'][count($jdata[$loc2->analysis_id]['bedCollection'])-2],
'target' => $jdata[$loc2->analysis_id]['bedCollection'][count($jdata[$loc2->analysis_id]['bedCollection'])-1]);
}
}
else
{
}
}
$jdata_tmp = array();
foreach ($jdata as $id => $data) {
$data['ideoCollection'] = array_values($data['ideoCollection']);
$jdata_tmp[] = $data;
}
$json_data = json_encode($jdata_tmp);
$json_data = "var data = $json_data";
drupal_add_js($json_data, array('type'=>'inline', 'scope'=>'footer','weight' => 50));
$cluster = array();
return theme('synview_search_result', array('cluster'=> $cluster, 'blocks' => $blocks, 'jdata' => $jdata_tmp));
}
/**
* load synteny blocks of synteny file into chado database
*
* @param $node
*
* generate job args, then trigger a tripal job for parsing synteny file and loading blocks
*/
function synteny_file_load_job($node)
{
global $user;
if ($node->syn_name) {
$job_args = array(
tripal_synview_get_organism_id($node->syn_genome1),
tripal_synview_get_organism_id($node->syn_genome2),
$node->syn_path,
);
tripal_add_job("Parse synteny file: $node->syn_path", 'tripal_synview',
'synview_parse_synfile', $job_args, $user->uid);
}
}
/**
* Adds custom templates to a node
*/
function synview_node_view_alter(&$build) {
if ($build['#bundle'] == 'chado_feature') {
//only show our template on full page views
if ($build['#view_mode'] != 'full' OR array_key_exists('tripal_feature_synteny', $build) ) {
return;
}
//add template to build
$build['tripal_feature_synteny'] = array(
'#theme' => 'tripal_feature_synteny',
'#node' => $build['#node'],
'#tripal_toc_id' => 'synteny',
'#tripal_toc_title' => 'Synteny',
);
}
}