This repository has been archived by the owner on Jul 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
PathParams.pm
executable file
·1873 lines (1666 loc) · 48.1 KB
/
PathParams.pm
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright SRA International
#
# Distributed under the OSI-approved BSD 3-Clause License.
# See http://ncip.github.com/pathway-interaction-database/LICENSE.txt for details.
package PathParams;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
ReadParams
CheckParams
);
use strict;
use PWLabel;
use Scan;
use constant ORACLE_LIST_LIMIT => 500;
use constant PRINT => "print";
use constant SHOW => "show";
use constant MACRO_PROCESS => "macro_process";
use constant SKIP_MOL_ID => "skip_mol_id";
use constant SKIP_COMPLEXES => "skip_complexes";
use constant SOURCE_ID => "source_id";
use constant COLLAPSE => "collapse";
use constant COLOR => "color";
use constant VALUE => "value";
use constant CHANNEL => "channel";
use constant CONNECT_MOLECULE => "connect_molecule";
use constant CONNECT_MOL_NAME => "connect_mol_name";
use constant CONNECT_MOL_ID => "connect_mol_id";
use constant CONNECT_MOL_EXT_ID => "connect_mol_ext_id";
use constant PRUNE_MOL_NAME => "prune_mol_name";
use constant PRUNE_MOL_ID => "prune_mol_id";
use constant PRUNE_MOL_EXT_ID => "prune_mol_ext_id";
use constant PATHWAY => "pathway";
use constant PATHWAY_ID => "pathway_id";
use constant PATHWAY_NAME => "pathway_name";
use constant PATHWAY_EXT_ID => "pathway_ext_id";
use constant ATOM_ID => "atom_id";
use constant EVIDENCE_CODE => "evidence_code";
use constant PRUNE_ATOM_ID => "prune_atom_id";
use constant MOLECULE => "molecule";
use constant MOL_NAME => "mol_name";
use constant MOL_ID => "mol_id";
use constant MOL_EXT_ID => "mol_ext_id";
use constant INCLUDE => "include";
use constant EDGE => "edge";
use constant DEGREE_BACK => "degree_back";
use constant DEGREE_FORWARD => "degree_forward";
use constant DB_USER => "db_user";
use constant DB_PASS => "db_pass";
use constant DB_INST => "db_inst";
use constant DB_SCHEMA => "db_schema";
use constant SIM_CYCLE => "sim_cycle";
use constant SIM_MOL_ID => "sim_mol_id";
use constant SIM_OUTPUT => "sim_output";
use constant SIM_METHOD => "sim_method";
use constant SIM_SIMPLE => "sim_simple";
use constant SIM_COMPETE => "sim_compete";
use constant MAX_DEGREE => 5;
my %mol_types = ("CM" => "compound", "CX" => "complex",
"RN" => "rna", "PR" => "protein");
my %id_types = (
"EC" => 1,
"LL" => 1,
"UP" => 1,
"CA" => 1,
"KG" => 1
);
my %printopts = (
"sql" => 1,
"table" => 1,
"xml" => 1,
"xaml" => 1,
"biopax" => 1,
"sbml" => 1,
"dot" => 1,
"bp3" => 1,
"rssm" => 1
);
######################################################################
sub new {
my ($self, $lv) = @_;
my $x = {};
$x->{lv} = $lv;
return bless $x;
}
######################################################################
sub Errors {
my ($self) = @_;
return $self->{errors};
}
######################################################################
sub AddError {
my ($self, $msg) = @_;
#print STDERR "$msg\n";
push @{ $self->{errors} }, $msg;
}
######################################################################
sub Trim {
my ($x) = @_;
$x =~ s/^\s+//;
$x =~ s/\s+$//;
return $x;
}
######################################################################
sub DoDbUser {
my ($self, $user) = @_;
$self->{db}{user} = $user;
}
######################################################################
sub DoDbPass {
my ($self, $pass) = @_;
$self->{db}{pass} = $pass;
}
######################################################################
sub DoDbInst {
my ($self, $inst) = @_;
$self->{db}{inst} = $inst;
}
######################################################################
sub DoDbSchema {
my ($self, $schema) = @_;
$self->{db}{schema} = $schema;
}
######################################################################
sub DoPrint {
my ($self, $what) = @_;
$what = lc(Trim($what));
if (not defined $printopts{$what}) {
$self->AddError("unrecognized print option $what");
return;
}
$self->{print}{$what} = 1;
}
######################################################################
sub DoSourceId {
my ($self, $id) = @_;
$id = lc(Trim($id));
if ($id =~ /^\d+$/) {
$self->{source_id}{$id} = 1;
}
}
######################################################################
sub DoMacroProcess {
my ($self, $name) = @_;
## Don't lower-case; PWLabel retains case-sensitivitiy
$name = Trim($name);
$self->{macroprocess_name}{$name} = 1;
}
######################################################################
sub DoShow {
my ($self, $what) = @_;
$what = lc(Trim($what));
if (
$what eq "atom_id" ||
$what eq "subtype_line" ||
0 ) {
$self->{show}{$what} = 1;
} else {
$self->AddError("unrecognized option $what for show");
return;
}
}
######################################################################
sub DoSkip {
my ($self, $cmd, $mol_id) = @_;
$cmd = lc(Trim($cmd));
if ($cmd eq "complexes") {
$self->{skip}{complexes} = 1;
} elsif ($cmd eq "mol_id") {
$self->{skip}{mol_id}{$mol_id} = 1;
}
}
######################################################################
sub DoCollapse {
my ($self, $cmd) = @_;
$cmd = lc(Trim($cmd));
if ($cmd eq "processes") {
$self->{collapse}{processes} = 1;
} elsif ($cmd eq "molecules") {
$self->{collapse}{molecules} = 1;
} elsif ($cmd eq "subnets") {
$self->{collapse}{subnets} = 1;
} else {
$self->AddError("unrecognized print option $cmd");
return;
}
}
######################################################################
sub DoColor {
my ($self, $number, $color) = @_;
# $boundtype = lc(Trim($boundtype));
$number = lc(Trim($number));
$color = lc(Trim($color));
# if ($boundtype ne "upper" || $boundtype ne "lower") {
# $self->AddError("unrecognized bound $boundtype in color command");
# return;
# }
if ($number !~ /^(-|\+)?\d+(\.\d*)?$/ && $number !~ /^(-|\+)?\.\d+$/) {
$self->AddError("number expected for $number in color command");
return;
}
if ($color !~ /^#?([0-9A-Fa-f]{6})/) {
$self->AddError("six-place hexadecimal color specification " .
"expected for $color");
return;
} else {
$color = $1;
}
$self->{color}{$number} = $color;
}
######################################################################
sub DoSim {
my ($self, $cmd, @vars) = @_;
if ($cmd eq "cycle") {
my $ncycle = Trim(shift @vars);
if ($ncycle !~ /^\d+$/) {
$self->AddError("need numeric argument for 'sim'");
return;
}
$self->{sim}{ncycle} = $ncycle;
} elsif ($cmd eq "mol_id") {
my ($mol_id, $pct) = @vars;
$self->{sim}{mol}{$mol_id} = $pct;
} elsif ($cmd eq "output") {
my $output_type = lc(Trim(shift @vars));
$self->{sim}{output} = $output_type;
} elsif ($cmd eq "method") {
my $meth = lc(Trim(shift @vars));
$self->{sim}{method} = $meth;
if ($meth eq "boolean") {
my $default = shift @vars;
if ($default ne "") {
$self->{sim}{booleandefault} = $default;
}
}
} elsif ($cmd eq "simple") {
my $flag = Trim(shift @vars);
if ($flag ne "0" && $flag ne "" && $flag ne "1") {
$self->AddError("unrecognized sim_simple option $flag");
return;
}
$self->{sim}{simple} = $flag;
} elsif ($cmd eq "compete") {
my $flag = Trim(shift @vars);
if ($flag ne "0" && $flag ne "" && $flag ne "1") {
$self->AddError("unrecognized sim_compete option $flag");
return;
}
$self->{sim}{compete} = $flag;
} else {
$self->AddError("unrecognized sim command $cmd");
return;
}
}
######################################################################
sub DoEdge {
my ($self, @vars) = @_;
my ($interaction_id, $edge_type, $mol_name, $mol_ext_id,
$activity, $location) = @vars;
$interaction_id = Trim($interaction_id);
$edge_type = lc(Trim($edge_type));
$mol_name = Trim($mol_name);
$mol_ext_id = Trim($mol_ext_id);
$activity = lc(Trim($activity));
$location = lc(Trim($location));
if ($interaction_id eq "") {
$self->AddError("missing interaction id in edge command: " .
join("\t", @vars) );
return;
}
if ($edge_type eq "") {
$self->AddError("missing edge type in edge command: " .
join("\t", @vars) );
return;
}
$edge_type = lc($edge_type);
if ($edge_type ne "input" && $edge_type ne "output" &&
$edge_type ne "agent" && $edge_type ne "inhibitor") {
$self->AddError("illegal edge type '$edge_type' in edge command: " .
join("\t", @vars) );
return;
}
if ($mol_name eq "" && $mol_ext_id eq "") {
$self->AddError("must specify mol name and/or mol external id in edge command: " .
join("\t", @vars) );
return;
}
if ($activity) {
$self->{privateactivity}{$activity} = 1;
}
if ($location) {
$self->{privatelocation}{$location} = 1;
}
if ($mol_ext_id =~ /^\d+$/) {
$self->{privatells}{$mol_ext_id} = 1;
}
push @{ $self->{privateedges} }, join("\t", $interaction_id, $edge_type,
$mol_name, $mol_ext_id, $activity, $location);
}
######################################################################
sub DoDegree {
my ($self, $direction, @vars) = @_;
my $n = Trim(shift @vars);
if ($direction ne "back" && $direction ne "forward") {
$self->AddError("unrecognized degree direction");
return;
}
if ($n !~ /^\d+$/) {
$self->AddError("illegal value $n for degree $direction");
return;
} elsif ($n > MAX_DEGREE) {
$self->AddError("value for degree $n exceeds maximum " . MAX_DEGREE);
return;
} else {
$self->{degree}{$direction} = $n;
}
}
######################################################################
sub DoInclude {
my ($self, $what) = @_;
$what = lc(Trim($what));
if ($what eq "complex_uses") {
$self->{include_complex_uses} = 1;
} elsif ($what eq "family_uses") {
$self->{include_family_uses} = 1;
} elsif ($what eq "transcription") {
$self->{transcription} = 1;
} else {
$self->AddError("Illegal option $what for include");
return;
}
}
######################################################################
sub MouseTrap {
my ($self) = @_;
##! Traps only LocusLink ids for mouse
my (%temp);
for $_ (keys %{ $self->{mol_ext_id} }) {
if (/^\d+$/) {
$temp{$_} = 1;
}
}
for $_ (keys %{ $self->{mol_ext_id_value} }) {
if (/^\d+$/) {
$temp{$_} = 1;
}
}
for $_ (keys %{ $self->{privatells} }) {
$temp{$_} = 1;
}
my @temp = keys %temp;
if (@temp == 0) {
return;
}
my ($db_inst, $db_user, $db_pass, $schema) =
("cgdev", "web", "readonly", "cgap");
my ($db, $sql, $stm, $i, $list);
my ($hs_locus, $mm_locus);
$db = DBI->connect("DBI:Oracle:" . $db_inst, $db_user, $db_pass);
if (not $db or $db->err()) {
print STDERR "Cannot connect to " . $db_user . "@" . $db_inst . "\n";
die;
}
for($i = 0; $i < @temp; $i += ORACLE_LIST_LIMIT) {
if(($i + ORACLE_LIST_LIMIT - 1) < @temp) {
$list = "'" . join("','", @temp[$i..$i+ORACLE_LIST_LIMIT-1]) . "'";
}
else {
$list = "'" . join("','", @temp[$i..@temp-1]) . "'";
}
$sql = qq!
select
hs.locus_id,
mm.locus_id
from
$schema.hg_entry mm,
$schema.hg_entry hs
where
mm.taxon_id = 10090
and hs.taxon_id = 9606
and hs.entry_id = mm.entry_id
and mm.locus_id in ($list)
!;
$stm = $db->prepare($sql);
if(not $stm) {
print STDERR "$sql\n";
print STDERR "$DBI::errstr\n";
print STDERR "prepare call failed\n";
die;
}
if(!$stm->execute()) {
print STDERR "$sql\n";
print STDERR "$DBI::errstr\n";
print STDERR "execute call failed\n";
die;
}
while (($hs_locus, $mm_locus) = $stm->fetchrow_array()) {
push @{ $self->{mousetrap}{$mm_locus} }, $hs_locus;
}
}
$db->disconnect();
for $mm_locus (keys %{ $self->{mol_ext_id} }) {
if (defined $self->{mol_ext_id}{$mm_locus}) {
if (defined $self->{mousetrap}{$mm_locus}) {
for $hs_locus (@{ $self->{mousetrap}{$mm_locus} }) {
$self->{mol_ext_id}{$hs_locus} = $self->{mol_ext_id}{$mm_locus};
}
delete $self->{mol_ext_id}{$mm_locus};
if (keys %{ $self->{mol_ext_id}{$mm_locus} } == 0) {
delete $self->{mol_ext_id}{$mm_locus};
}
}
}
}
for $mm_locus (keys %{ $self->{mol_ext_id_value} }) {
if (defined $self->{mol_ext_id_value}{$mm_locus}) {
if (defined $self->{mousetrap}{$mm_locus}) {
for $hs_locus (@{ $self->{mousetrap}{$mm_locus} }) {
for my $subtype (keys %{ $self->{mol_ext_id_value}{$mm_locus} }) {
$self->{mol_ext_id_value}{$hs_locus}{$subtype} =
$self->{mol_ext_id_value}{$mm_locus}{$subtype};
}
}
delete $self->{mol_ext_id_value}{$mm_locus};
if (keys %{ $self->{mol_ext_id_value}{$mm_locus} } == 0) {
delete $self->{mol_ext_id_value}{$mm_locus};
}
}
}
}
}
######################################################################
sub DoChannel {
my ($self, $channel, $molecule, $is_mol_id) = @_;
my $lv = $self->{lv};
$channel = uc(Trim($channel));
if ($channel eq "") {
$self->AddError("No channel specified for channel command: " .
join("\t", $channel, $molecule));
return;
}
if ($channel !~ /^(A|B)$/) {
$self->AddError("Illegal channel specified for channel command: " .
join("\t", $channel, $molecule));
return;
}
if ($is_mol_id eq "mol_id") {
$molecule = Trim($molecule);
if ($molecule =~ /^\d+$/) {
$self->{mol_id_channel}{$molecule}{$channel} = 1;
} else {
$self->AddError("Illegal mol_id for channel command: " .
join("\t", $channel, $molecule, $is_mol_id));
}
} else {
$self->{mol_name}{lc(Trim($molecule))}{channel} = 1;
$self->{mol_ext_id}{lc(Trim($molecule))}{channel} = 1;
$self->{molecule_channel}{lc(Trim($molecule))}{$channel} = 1;
}
}
######################################################################
sub DoValue {
my ($self, $value, $what, @vars) = @_;
my $lv = $self->{lv};
my ($molid, $name, $extid, $activity, $location);
$value = Trim($value);
if ($value eq "") {
$self->AddError("No value specified for value command: " .
join("\t", $what, $value, @vars));
return;
}
if ($value !~ /^(-|\+)?(\d+)?(\.\d+)?$/) {
$self->AddError("Illegal value specified for value command: " .
join("\t", $what, $value, @vars));
return;
}
if ($what eq "mol_name" || $what eq "molecule") {
($name, $activity, $location) = @vars;
} elsif ($what eq "mol_id") {
($molid, $activity, $location) = @vars;
$molid = Trim($molid);
if ($molid !~ /^\d+$/) {
$self->AddError("illegal molecule id $molid for DoMol");
return;
}
} elsif ($what eq "mol_ext_id" || $what eq "molecule") {
($extid, $activity, $location) = @vars;
} else {
$self->AddError("Illegal molecular specifier for value command: " .
join("\t", $what, $value, @vars));
return;
}
$activity = lc(Trim($activity));
$location = Trim($location);
if ($activity ne "") {
my $lvid = $lv->StringToLabelValue("activity-state", $activity);
if (! $lvid) {
$self->AddError("illegal activity value: $activity");
return;
} else {
# $activity = $lvid;
}
}
if ($location ne "") {
my $lvid = $lv->StringToLabelValue("location", $location);
if (! $lvid) {
$self->AddError("illegal location value: $location");
return;
} else {
# $location = $lvid;
}
}
my $subtype = "$activity\t$location";
if ($what eq "mol_name" || $what eq "molecule") {
$self->{mol_name_value}{lc(Trim($name))}{$subtype} = $value;
$self->{mol_name}{lc(Trim($name))}{value} = 1;
} elsif ($what eq "mol_id") {
$molid = Trim($molid);
$self->{mol_id_value}{$molid}{$subtype} = $value;
} elsif ($what eq "mol_ext_id" || $what eq "molecule") {
$self->{mol_ext_id}{lc(Trim($extid))}{value}{$subtype} = $value;
$self->{mol_ext_id_value}{lc(Trim($extid))}{$subtype} = $value;
}
}
######################################################################
sub DoMol {
my ($self, $op, $what, @vars) = @_;
my ($name, $molid, $extid);
if ($what eq "name") {
($name) = @vars;
$self->{mol_name}{lc(Trim($name))}{$op} = 1;
} elsif ($what eq "id") {
($molid) = @vars;
$molid = Trim($molid);
if ($molid !~ /^\d+$/) {
$self->AddError("illegal molecule id $molid for DoMol");
return;
} else {
if ($op eq "prune") {
$self->{prune_mol_id}{$molid} = 1; ## may still be an unknown molid
} elsif ($op eq "get") {
$self->{mol_id}{$molid} = 1; ## may still be an unknown molid
} elsif ($op eq "connect") {
$self->{connect}{$molid} = 1;
} else {
$self->AddError("unrecognized prune/get/connect action $op");
return;
}
}
} elsif ($what eq "ext_id") {
($extid) = @vars;
$self->{mol_ext_id}{lc(Trim($extid))}{$op} = 1;
} elsif ($what eq "general") {
## by name
($name) = @vars;
$self->{mol_name}{lc(Trim($name))}{$op} = 1;
## by ext id
($extid) = @vars;
$self->{mol_ext_id}{lc(Trim($extid))}{$op} = 1;
} else {
$self->AddError("unrecognized subtype $what for DoMol");
return;
}
}
######################################################################
sub DoAtomId {
my ($self, $what, $atom_id) = @_;
$atom_id = Trim($atom_id);
if ($atom_id =~ /^\*$/) {
if ($what eq "get") {
$self->{atom}{$atom_id} = 1;
}
} elsif ($atom_id =~ /^\d+$/) {
if ($what eq "get") {
$self->{atom}{$atom_id} = 1;
} elsif ($what eq "prune") {
$self->{prune_atom_id}{$atom_id} = 1;
}
} else {
$self->AddError("illegitimate atom id $atom_id");
return;
}
}
######################################################################
sub DoEvidenceCode {
my ($self, $what, $evidence_code) = @_;
$evidence_code = uc(Trim($evidence_code));
if ($evidence_code =~ /^\*$/) {
if ($what eq "get") {
$self->{evidence_code}{$evidence_code} = 1;
}
} elsif ($evidence_code =~ /^[INRT][A-S]{1,2}$/i) {
if ($what eq "get") {
$self->{evidence_code}{$evidence_code} = 1;
}
} else {
$self->AddError("illegitimate evidence_code $evidence_code");
return;
}
}
######################################################################
sub DoPathway {
my ($self, $what, @vars) = @_;
my ($pathway_id, $pathway_ext_id, $pathway_name);
if ($what eq "id") {
($pathway_id) = @vars;
$pathway_id = Trim($pathway_id);
if ($pathway_id !~ /^\d+$/ && $pathway_id ne "*") {
$self->AddError("illegitimate pathway id $pathway_id");
return;
}
$self->{pathway}{id}{$pathway_id} = 1;
} elsif ($what eq "extid") {
($pathway_ext_id) = @vars;
$self->{pathway}{ext_id}{$pathway_ext_id} = 1;
} elsif ($what eq "name") {
($pathway_name) = @vars;
if ($pathway_name !~ /^\s+$/) {
$self->{pathway}{name}{lc(Trim($pathway_name))} = 1;
}
} elsif ($what eq "general") {
($pathway_name) = @vars;
if ($pathway_name !~ /^\s+$/) {
$self->{pathway}{name}{lc(Trim($pathway_name))} = 1;
}
($pathway_ext_id) = @vars;
$self->{pathway}{ext_id}{$pathway_ext_id} = 1;
} else {
$self->AddError("unrecognized subtype $what for DoPathway");
return;
}
}
######################################################################
sub CheckMol {
my ($self, $db) = @_;
if (defined $self->{mol_name}) {
print STDOUT "In CheckMolName call\n";
my @temp = keys %{ $self->{mol_name} };
my $scan = 0;
# for (my $i = 0; $i <= $#temp; $i++) {
# my $scancheck = Scan($temp[$i]);
# $scan = $scan + $scancheck;
# print STDOUT "After Scan: $temp[$i] $scancheck\n";
#}
if ($scan == 0) {
CheckMolName($self, $db);
}
}
## doing privatells to catch them in mousetrap
if (defined $self->{mol_ext_id} || defined $self->{privatells} ||
defined $self->{mol_ext_id_value}) {
CheckMolExtId($self, $db);
}
for my $x (keys %{ $self->{mol_name} }, keys %{ $self->{mol_ext_id} }) {
if (! defined $self->{molmap}{$x}) {
$self->{no_molmap}{$x} = 1;
}
}
}
######################################################################
sub CheckMolName {
my ($self, $db) = @_;
##!!!!!!! We aren't going to require mol type any longer
my ($sql, $stm);
my ($molid, $molname, $nametype, $moltype, $what, $ll_id, $ll_list);
my ($alias, $alias_list, $symbol, $name_type);
my $schema = $self->{db}{schema};
my @temp = keys %{ $self->{mol_name} };
my $list;
# for(my $i = 0; $i < ($#temp + 1); $i += ORACLE_LIST_LIMIT) {
# if(($i + ORACLE_LIST_LIMIT - 1) < @temp) {
# $list = "'" . join("','", @temp[$i..$i+ORACLE_LIST_LIMIT-1]) . "'";
# }
# else {
# $list = "'" . join("','", @temp[$i..@temp-1]) . "'";
# }
# print STDERR "List2: $list\n";
## Find exact matches to the name in PID
$sql = qq!
select
mol_id,
lower(s1.map_name)
from
$schema.pw_mol_srch s1
where
s1.map_name like ?
!;
print STDERR "Sql: $sql\n";
$stm = $db->prepare($sql);
if(not $stm) {
$self->AddError("$sql");
$self->AddError("$DBI::errstr");
$self->AddError("prepare call failed");
return;
}
for my $id (@temp) {
my $tempMolName = $id;
$id = lc $id;
$id =~s/, /,/g;
$id =~s/ ,/,/g;
$id =~s/\*/%/g;
print STDERR "ID: $id\n";
my $lengthTest = $id;
$lengthTest =~s/%//g;
my $lengthValue = length($lengthTest);
print STDERR "Length: $lengthValue\n";
if ($lengthValue < 3) {
$id =~s/%//g;
}
print STDERR "ID: $id\n";
if(!$stm->execute($id)) {
# if(!$stm->execute()) {
$self->AddError("$sql");
$self->AddError("$DBI::errstr");
$self->AddError("execute call failed");
print STDERR "In error\n";
return;
}
print STDERR "Before while\n";
while (($molid, $molname) =
$stm->fetchrow_array()) {
print STDERR "In while: $molid $molname\n";
$self->{molmap}{$molname}{$molid} = 1;
# if (defined $self->{mol_name}{$molname}) {
print STDERR "In defined\n";
for $what (keys %{ $self->{mol_name}{$tempMolName} }) {
print STDERR "In for $tempMolName\n";
if ($what eq "prune") {
$self->{prune_mol_id}{$molid} = 1;
} elsif ($what eq "get") {
$self->{mol_id}{$molid} = 1;
} elsif ($what eq "connect") {
$self->{connect}{$molid} = 1;
} elsif ($what eq "value") {
# handled immediately below
} elsif ($what eq "channel") {
# handled immediately below
} else {
$self->AddError("unrecognized action $what in CheckMolName");
return;
}
if (defined $self->{mol_name_value}{$molname}) {
for my $subtype (keys %{ $self->{mol_name_value}{$molname} }) {
$self->{mol_id_value}{$molid}{$subtype} =
$self->{mol_name_value}{$molname}{$subtype};
}
}
if (defined $self->{molecule_channel}{$molname}) {
for my $channel (keys %{ $self->{molecule_channel}{$molname} }) {
$self->{mol_id_channel}{$molid}{$channel} = 1;
}
}
}
# }
}
}
}
######################################################################
sub CheckMolExtId {
my ($self, $db) = @_;
##!! convert Mm locus ids to Hs locus ids
$self->MouseTrap();
my ($sql, $stm);
my ($molid, $extid, $what);
my $schema = $self->{db}{schema};
my @temp = keys %{ $self->{mol_ext_id} };
my $list;
for(my $i = 0; $i < @temp; $i += ORACLE_LIST_LIMIT) {
if(($i + ORACLE_LIST_LIMIT - 1) < @temp) {
$list = "'" . join("','", @temp[$i..$i+ORACLE_LIST_LIMIT-1]) . "'";
}
else {
$list = "'" . join("','", @temp[$i..@temp-1]) . "'";
}
## Find direct matches of ext ids
$sql = qq!
select
e.mol_id,
lower(e.ext_mol_id)
from
$schema.pw_ext_mol_id e
where
e.id_type \!= 'SG' and
lower(e.ext_mol_id) in ($list)
!;
$stm = $db->prepare($sql);
if(not $stm) {
$self->AddError("$sql");
$self->AddError("$DBI::errstr");
$self->AddError("prepare call failed");
return;
}
if(!$stm->execute()) {
$self->AddError("$sql");
$self->AddError("$DBI::errstr");
$self->AddError("execute call failed");
return;
}
while (($molid, $extid) =
$stm->fetchrow_array()) {
$self->{molmap}{$extid}{$molid} = 1;
if (defined $self->{mol_ext_id}{$extid}) {
for $what (keys %{ $self->{mol_ext_id}{$extid} }) {
if ($what eq "prune") {
$self->{prune_mol_id}{$molid} = 1;
} elsif ($what eq "get") {
$self->{mol_id}{$molid} = 1;
} elsif ($what eq "connect") {
$self->{connect}{$molid} = 1;
} elsif ($what eq "value") {
# handled below
} elsif ($what eq "channel") {
# handled below
} else {
$self->AddError("unrecognized action $what in CheckMolExtId");
return;
}
}
}
if (defined $self->{mol_ext_id_value}{$extid}) {
for my $subtype (keys %{ $self->{mol_ext_id_value}{$extid} }) {
$self->{mol_id_value}{$molid}{$subtype} =
$self->{mol_ext_id_value}{$extid}{$subtype};
}
}
if (defined $self->{molecule_channel}{$extid}) {
for my $channel (keys %{ $self->{molecule_channel}{$extid} }) {
$self->{mol_id_channel}{$molid}{$channel} = 1;
}
}
}
}
undef @temp;
for my $num (keys %{ $self->{mol_ext_id} }) {
if ($num =~ /^\d+$/) {
push @temp, $num;
}
}
my $list;
for(my $i = 0; $i < @temp; $i += ORACLE_LIST_LIMIT) {
if(($i + ORACLE_LIST_LIMIT - 1) < @temp) {
$list = "'" . join("','", @temp[$i..$i+ORACLE_LIST_LIMIT-1]) . "'";
}
else {
$list = "'" . join("','", @temp[$i..@temp-1]) . "'";
}
## Find matches of gene ids to proteins in PID
$sql = qq!
select
e.mol_id,
g.ll_id
from
$schema.pw_ext_mol_id e,
cgap.ll2sp s,
cgap.sp_primary p,
cgap.ll_gene g
where
p.sp_id_or_secondary = e.ext_mol_id
and p.sp_id_or_secondary = s.sp_primary
and s.organism = 'Hs'
and s.ll_id = g.ll_id
and e.id_type \!= 'SG'
and g.ll_id in ($list)