Repository navigation
Expand file tree
/
Copy pathQA_Mod.txt
More file actions
2153 lines (1709 loc) · 53.9 KB
/
Copy pathQA_Mod.txt
File metadata and controls
2153 lines (1709 loc) · 53.9 KB
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
package ChromDB::QualityAssessment;
#nomenclature:
#MHND = Mahalanobis Distance
use version; our $VERSION = qv('3.6');
#orginal version created by Tara Paulson
#version 3.1 created by Stephen Bolaris
#with with help from Karla Gendler and Walt
#import packages
use strict;
#ChromDB packages
use ChromDB::Protein;
use ChromDB::Domain;
use ChromDB::ProteinSelector;
use ChromDB::Taxon;
#perl data language
use PDL;
use PDL::Matrix;
use PDL::Ops;
use PDL::Ufunc;
use PDL::Slatec; #this is needed for condition number problems
use Data::Dumper;
#Statistics packages
use Statistics::Distributions;
#define package varibles
#seed_mu (average)
my %averages_of_features;
#seed standard deviation
my %stds_of_features;
#zbars for the features
my %z_bars_of_features;
#arry to keeptrack of all seed z scores
my @seed_z_scores;
#array of bad feature numbers
my @bad_feat;
#hash of necessary features features
my %necessary_features;
#the covariance matrix
my $matrix;
#the canidate vector
my $vector;
#spacial limit used for color representation
my $d_max;
#limit for D^2 distrobution
my $alpha = 0.2;
#red limit
my $gamma = 0.05;
#domain db to use
my $db = "pfam";
#z score for the canidate length
my $canidate_z_length;
#global for feature check
my $has_features;
#an array to keep track of feature order
my @order;
#check to see if the matrix is defined
my $co_var_defined;
#shows that the options are set
my $opts = 0;
#gives back error message
my $errorMess = undef;
# hash containing the seed features
my %seeds;
#number of seeds (for pos calc)
my $numSeeds;
#global verbose option
my $verbose = 0;
#degrees of freedom
my $deg_free;
# group array to allow for multiple protein groups.
my @groups;
my $prot_type;
my $tester;
my %feat_test;
my @seed_prots = ();
my $seed_test = 0;
my $ret_feat = 0;
my $rem_tax = 0;
my $usrt = 0;
my @user_taxa =();
my $recursive =0;
my $req_num_seeds = 4; #increase number required seeds to help with big p small n problem
my @feature_vals = ();
=for
DEPRICATED
#define sql hash (if needed) DEPRICATED
#my %SQL : SQL = (
# insert_seed_data => q{INSERT INTO calculated_quality_data SET protein_id=?, feature=?, z_score=?, type=?},
# fetch_seed_data => q{SELECT FROM calculated_quality_data WHERE protein_id=? }
# );
=cut
sub init(){
$co_var_defined =0;
$has_features = 0;
if($opts == 0){
$d_max = 0;
}
unless($recursive == 1){
$req_num_seeds =4;
}
$vector = undef;
$matrix = undef;
@order = ();
@bad_feat = ();
@seed_z_scores = ();
%necessary_features =();
%averages_of_features = ();
%stds_of_features = ();
%z_bars_of_features = ();
$errorMess = undef;
%seeds = ();
$recursive = 0;
@seed_prots =();
@feature_vals = ();
}
#options method
#allow the script to be able to pass options like to get a graphical
#out put as well as standard text?
#other options? -set what cut offs should be
sub set_options(){
my $self = shift;
my $option = shift;
my $value = shift;
if($option =~ m/dmax/i){
$d_max = $value;
$opts =1;
}
elsif($option =~ m/alpha/i){
$alpha = $value;
}
elsif($option =~ m/gamma/i){
$gamma = $value;
}
elsif($option =~ m/db/i){
$db = $value;
}
elsif($option =~ m/reset/i){
$opts = 0;
ChromDB::QualityAssessment->init();
}
elsif($option =~m/verbose/){
$verbose = $value;
}
elsif($option =~m/pg/){
@groups= @{$value};
}
elsif($option =~ m/seeder/i){
$seed_test = $value;
}
elsif($option =~ m/nf/i){
$ret_feat = $value;
}
elsif($option =~ m/exclude/i){
$rem_tax = $value;
}
elsif($option =~ m/taxa/i){
$usrt = 1;
@user_taxa = @{$value};
}
elsif($option =~ m/length/i){
$req_num_seeds = $value;
}
else{
print "your option parameter did not match 'dmax', 'alpha', 'gamma', or 'db' default values will now be used";
}
}
#retrieve set from user request (input)
sub input_by_prot(){
#what type of input should it expect? - either protien ids and length, and e values
my $self = shift;
my $name = shift;
$tester = $name;
my %canidate_features;
#used in case of multiple domains under the same name
my $i = 0;
#gather protein object
my $prot = ChromDB::Protein->fetch($name);
#stor protein object
$canidate_features{"protein"} = $prot;
#get length
my $length = $prot->fetch_protein_sequence()->get_sequence_length();
$canidate_features{"length"} = $length;
#domain data
my @domains = $prot->fetch_domains_by_db($db);
#go through all domains corrisponding to the database specified
foreach(@domains){
my $pd = $_;
#get domain name
my $domain = ChromDB::Domain->fetch($pd->get_domain())->get_name();
#if there are multiple domains with the same name incrament name with pipe
if(exists($canidate_features{$domain})){
$i++;
if($pd->get_e_value() == 0){
$canidate_features{$domain."|".$i} = (2**31-1);
}
else{
$canidate_features{$domain."|".$i} = log10($pd->get_e_value());
}
}
#if there is only one domain with that name or it is the first one
else{
if($pd->get_e_value() ==0){
$canidate_features{$domain} = (2**31-1);
}
else{
$canidate_features{$domain} = log10($pd->get_e_value());
}
}
}
#return the out put that controller retuns
my $type = "protein";
#print $type;
return ChromDB::QualityAssessment->controller(\%canidate_features,$type);
} #end input_by_prot()
sub input_by_features(){ #expect hash of hashes refs
#%features{feature1} = %features
my $self = shift;
my %features = shift;
return ChromDB::QualityAssessment->controller(\%features,"features");
} #end input by features
#called by input methods to handle processing of a canidate
#returns the out back to the input methods
sub controller(){
my $self = shift;
my $feat = shift;
my $input = shift;
ChromDB::QualityAssessment->init();
my $name = ChromDB::Protein->fetch($tester)->get_chromdb_syn();
if($verbose ==1){
print $name."\n";
}
my $phylo = ChromDB::Protein->fetch($tester)->fetch_protein_class()->get_phylogenetic_code();
#print "$name \n";
#print $input;
#get seeds and necessary features, and seed features
my %seeds_of_canidate = %{ChromDB::QualityAssessment->get_seeds($feat,$input)};
if($errorMess){
my %error;
$error{"error"} = $phylo."\t".$name."\t".$errorMess;
$error{"prot"} = ChromDB::Protein->fetch($tester)->get_chromdb_syn();
$error{"seeds"} = ChromDB::QualityAssessment->generate_seed_list(\@seed_prots);
return \%error;
}
if($ret_feat ==1){
my @features = keys(%seeds_of_canidate);
my $seeds = ChromDB::QualityAssessment->generate_seed_list(\@seed_prots);
my %hash = (
"feature" => \@features,
"seeds" => $seeds,
);
return \%hash;
}
#check that canidate has the necessary features
my @can_feature = ChromDB::QualityAssessment->has_necessary_features($feat);
#if canidate has all necessary features
if($has_features == 1){
#calculate z scores for each seed feature
ChromDB::QualityAssessment->calc_seed_values(\%seeds_of_canidate);
if($errorMess eq " Determinant is zero with out Zero feature"){
if($rem_tax == 0){
$req_num_seeds++;
$recursive =1;
return ChromDB::QualityAssessment->input_by_prot($tester);
}
#print $errorMess."\n";
}
if($errorMess){
my %error;
$error{"error"} = $phylo."\t".$name."\t".$errorMess;
$error{"prot"} = ChromDB::Protein->fetch($tester)->get_chromdb_syn();
$error{"seeds"} = ChromDB::QualityAssessment->generate_seed_list(\@seed_prots);
return \%error;
}
#calculate z scores for each canidate feature
my $distance = ChromDB::QualityAssessment->calc_canidate_values($feat);
if($errorMess){
my %error;
$error{"error"} = $phylo."\t".$name."\t".$errorMess;
$error{"prot"} = ChromDB::Protein->fetch($tester)->get_chromdb_syn();
$error{"seeds"} = ChromDB::QualityAssessment->generate_seed_list(\@seed_prots);
return \%error;
}
#return the out put to user through input
return ChromDB::QualityAssessment->generate_output($distance);
}
#if the canidate does not have the necessary features
else{
#return error message saying what features were missing
my $errorMess = "$phylo\t$name\tThis canidate lacks the necessary features ";
if($verbose ==1){
print "missing ".scalar(@can_feature)." features\n";
}
foreach(@can_feature){
print $_." ";
$errorMess .= $_." ";
if($verbose == 1){
print "$name\tThis canidate lacks $_ feature";
}
}
if($verbose ==1){
print "seeds are :\n";
print ChromDB::QualityAssessment->generate_seed_list(\@seed_prots);
print "\n";
}
my %error;
$error{"error"} = $errorMess;
$error{"prot"} = ChromDB::Protein->fetch($tester)->get_chromdb_syn();
$error{"seeds"} = ChromDB::QualityAssessment->generate_seed_list(\@seed_prots);
return \%error;
}
}# end controller
#method to get seed based on the canidate protein,
sub get_seeds(){
my $self = shift;
my $hash_ref = shift;
my %canidate = %{$hash_ref};
my $input_type = shift;
#print $input_type." this is the input type";
my %NF;
my %seed_feat;
#set up protein selector based on input type
my $prot_sel = ChromDB::ProteinSelector->new();
my $taxon;
if($input_type =~ m/protein/i){
my @seed_prots;
my $protein = $canidate{"protein"};
#print $protein."is the protein";
my @terminal_node;
if(@groups == undef){
@terminal_node = $protein->fetch_protein_class()->fetch_terminal_classes();
}
else{
## for each of the groups
foreach my $node(@groups){
## get group object
my $prot_class = 0;
## push on to terminal nodes
push(@terminal_node, $prot_class);
#@terminal_node = @groups;
}
#end for
}
if($verbose == 1){
print "Groups =";
foreach my $node(@terminal_node){
print $node->get_phylogenetic_code()."\n";
}
}
if($rem_tax == 0){
if(exists($canidate{"taxon"})){
$taxon = $canidate{"taxon"};
#print "working ".$taxon->get_name()."\n";
}
else{
$taxon = $protein->fetch_organism()->fetch_taxon();
}
if($taxon){
my @taxa = $taxon->get_id();
if($usrt ==1){
push(@taxa, @user_taxa);
}
print @taxa;
$prot_sel->set_taxa(\@taxa);
}
else{
if($verbose ==1){
print $protein->get_chromdb_syn()." does not have taxon id\n";
}
$errorMess = "This protein's taxon was returned as undfined by the database";
my %error = {"e" => $errorMess};
return \%error;
}
}
$prot_sel->set_seed("Y");
$prot_sel->set_class(\@terminal_node);
#### also go to line 408 to remove taxon
}
else{
$prot_sel->set_seed("Y");
my $abbrev;
my $phylo;
if(exists($canidate{"pg"}) && exists($canidate{"phylocode"})){
$abbrev = $canidate{"pg"};
$phylo = $canidate{"phylocode"};
delete($canidate{"pg"});
delete($canidate{"phylocode"});
}
else{
die and print "Error feature has has not been given proper keys for
protein group (pg) and phylogenetic code (phylocode)";
}
#need method to use Phylo code and protein group to give correct protein class
# abbrev = group abbreviation like CHR phylocode = phylogenetic code
#ChromDB::ProteinClass->fetch_pgroup_by_phycode(abbrev, phylocode);
my $pc = ChromDB::ProteinClass->fetch_pgroub_by_phycode($abbrev, $phylo);
#have to do null check since it wont return anything if it cant find it
#return error code
$prot_sel->set_class($pc);
#enter feature data in to prot selector
#for input by features
}
#get seeds
my @temp = $prot_sel->proteins();
if(scalar(@temp) == 0){
my $name = ChromDB::Protein->fetch($tester)->get_chromdb_syn();
$errorMess = "has no seeds availible for comparison";
my %s;
return \%s;
}
if($seed_test == 1){
# remove test protein from the protein list
my $name = ChromDB::Protein->fetch($tester)->get_chromdb_syn();
for(my $i = 0; $i<scalar(@temp); $i++){
my $prot = ChromDB::Protein->fetch($temp[$i]);
my $prot_name = $prot->get_chromdb_syn();
if($prot_name eq $name){
if($verbose){
print "removing seed from list";
}
splice(@temp, $i, 1);
last;
}
}
}
$numSeeds = scalar(@temp);
@seed_prots = @temp;
#print "seeds = ".$seed_prots[1]."\t";
#print "temp = @temp\n";
#get all domains for seeds
#finding necessary features
MAIN:for(my $i = 0; $i < @temp; $i++){
my $p = ChromDB::Protein->fetch($temp[$i]);
#returns an array with every odd being the name every even how many
#ChromDB::ProteinDomain->domain_counts_by_protein($prot,$db);
my @domain_count = ChromDB::ProteinDomain->domain_counts_by_protein($p, $db);
#print $p->get_chromdb_syn()."\t";
#print "@domain_count";
#print "\n";
if($i==0){
#print "First loop\n";
for(my $j =0; $j<@domain_count; $j = $j+2){
$NF{ChromDB::Domain->fetch($domain_count[$j])->get_name()} = $domain_count[$j+1];
}
next MAIN;
}
#one array with domain names as keys => values
#print keys(%NF)."\n";
#print "Second loop\n";
#for each protein go through and:
for(my $k =0; $k<@domain_count; $k = $k+2){
#if its not there do nothing
if(exists($NF{ChromDB::Domain->fetch($domain_count[$k])->get_name()})){
#if domain name is there value => lower of the two;
if($domain_count[$k+1] < $NF{$domain_count[$k]}){
$NF{$domain_count[$k]} = $domain_count[$k+1];
}
}
}
#back check to make sure that the domains are constistant with all seeds
#print keys(%NF)."\n";
#print "Third Loop\n";
OUTER:foreach(keys %NF){
my $dom_name = $_;
for(my $l =0; $l<@domain_count; $l = $l+2){
#do backwards comparison
if($dom_name eq ChromDB::Domain->fetch($domain_count[$l])->get_name()){
#print "found $dom_name\n";
next OUTER;
}
if($l+2 == scalar(@domain_count)){
#print "DELETING $dom_name\n";
delete($NF{$dom_name});
}
}
}
}
$NF{"length"} = 1;
%necessary_features = %NF;
#create seed features hash
#print "$numSeeds";
################################
if($rem_tax ==0){
###comment out to remove taxon from the equation
if(( keys(%necessary_features) ==1 ||$numSeeds < $req_num_seeds) && $input_type eq "protein"){
if($verbose == 1){
while(my ($key, $val) = each(%necessary_features)){
print $key." is the key and ".$val."is the value\n";
#my @array = @{$val};
#foreach(@array){
# print "\t".$_."\n";
#}
}
}
if(keys(%necessary_features) == 1 && $verbose == 1){
print "only one necessary feature for the this protein\n";
print "key =".keys(%necessary_features)."\n";
}
if($numSeeds < $req_num_seeds && $verbose == 1){
print "less than 3 seeds moving to next parent\n";
print "parent =".$taxon->fetch_parent()."\n";
}
#print "here";
unless(keys(%necessary_features) == 1 && exists($necessary_features{"length"})){
$canidate{"taxon"} = ($taxon->fetch_parent());
return ChromDB::QualityAssessment->get_seeds(\%canidate,"protein");
}
else{
$errorMess = "This protein contained length as its only necessary feature";
if(scalar(@temp) == 0){
$errorMess .= "\tNo seeds were found for use";
}
my %error = {"e" => $errorMess};
return \%error;
}
}
}
else{
if($numSeeds < $req_num_seeds){
$errorMess = "This protein has less than the required number of seed proteins and will not run";
my %error = {"e" => $errorMess};
return \%error;
}
}
#my %seed_hash;
my @length;
foreach(@temp){
my $prot = ChromDB::Protein->fetch($_);
#need to get distinct domains
$seeds{$prot} = {"length" =>$prot->fetch_protein_sequence()->get_sequence_length()};
push(@length, $prot->fetch_protein_sequence()->get_sequence_length());
my @doms = $prot->get_distinct_domains_by_db($db);
#print $prot->get_distinct_domains_by_db("pfam");
#print ChromDB::Domain->fetch($doms[0])->get_name()." \n";
foreach(@doms){
my $domain = ChromDB::Domain->fetch($_);
if(exists($NF{$domain->get_name()})){
#print "works";
my @prot_domain = $prot->fetch_domain_specs($domain->get_id());
#print @prot_domain[0]->get_e_value()."\n";
if(scalar(@prot_domain) > 1){
#this where you need to check for multiple domains
#print scalar(@prot_domain);
#check if number in NF == the scalar @prot_dom
#if they match just go through and add all
if($NF{$domain->get_name()} == scalar(@prot_domain)){
my $count =0;
foreach(@prot_domain){
my $pd = $_;
if(exists($seed_feat{$domain->get_name()})){
if($count == 0){
#print $prot->get_chromdb_syn()." if 2 ".$domain->get_name()."\n";
my @f = @{$seed_feat{$domain->get_name()}};
my $eval;
if($pd->get_e_value() == 0){
$eval = -2**31-1;
}
else{
$eval = log10($pd->get_e_value());
}
push(@f, $eval);
if(exists($seeds{$prot})){
my %inner = %{$seeds{$prot}};
$inner{$domain->get_name()} = $eval;
$seeds{$prot} = \%inner;
}else{
$seeds{$prot} = {$domain->get_name() => $eval};
}
$seed_feat{$domain->get_name()} = \@f;
}
else{
if(exists($seed_feat{$domain->get_name()."|".$count})){
#print $prot->get_chromdb_syn()." else 2".$domain->get_name()."\n";
my @f = @{$seed_feat{$domain->get_name()."|".$count}};
my $eval;
if($pd->get_e_value() == 0){
$eval = -2**31-1;
}
else{
$eval = log10($pd->get_e_value());
}
push(@f, $eval);
if(exists($seeds{$prot})){
my %inner = %{$seeds{$prot}};
$inner{$domain->get_name()."|".$count} = $eval;
$seeds{$prot} = \%inner;
}else{
$seeds{$prot} = {$domain->get_name()."|".$count => $eval};
}
$seed_feat{$domain->get_name()."|".$count} = \@f;
}
else{
#print $prot->get_chromdb_syn()." else 3".$domain->get_name()."\n";
my @f;
my $eval;
if($pd->get_e_value() == 0){
$eval = -2**31-1;
}
else{
$eval = log10($pd->get_e_value());
}
push(@f, $eval);
if(exists($seeds{$prot})){
my %inner = %{$seeds{$prot}};
$inner{$domain->get_name()."|".$count} = $eval;
$seeds{$prot} = \%inner;
}else{
$seeds{$prot} = {$domain->get_name()."|".$count => $eval};
}
$seed_feat{$domain->get_name()."|".$count} = \@f;
}
}
$count++;
}
else{
#if the hash requires a key entry add it and starting value
my @f;
my $eval;
if($pd->get_e_value() == 0){
$eval = -2**31-1;
}
else{
$eval = log10($pd->get_e_value());
}
push(@f, $eval);
if(exists($seeds{$prot})){
my %inner = %{$seeds{$prot}};
$inner{$domain->get_name()} = $eval;
$seeds{$prot} = \%inner;
}else{
$seeds{$prot}={$domain->get_name() => $eval};
}
$seed_feat{$domain->get_name()} = \@f;
$count++;
#print $prot->get_chromdb_syn()." else 1".$domain->get_name()."\n";
}
}
}
#if not....??
else{
#take as many as are in NF in order
my $numDom = $NF{$domain->get_name()};
for(my $d = 0; $d < $numDom; $d++){
#print "\n\n$tester\tDomain name: ".$domain->get_name()."\n";
if(!$prot_domain[$d]){
next;
}
#add multiples in order seperate out in
if(exists($seed_feat{$domain->get_name()})){
if($d !=0){
my @f = @{$seed_feat{$domain->get_name()}};
print ChromDB::Protein->fetch($tester)->get_chromdb_syn()." fails at domain ".$domain->get_name()."\n";
print $prot_domain[$d]." d is $d \n";
print "Num dom = $numDom\n";
my $eval;
if($prot_domain[$d]->get_e_value() == 0){
$eval = -2**31-1;
}
else{
$eval = log10($prot_domain[$d]->get_e_value());
}
push(@f, $eval);
$seed_feat{$domain->get_name()."|".$d} = \@f;
if(exists($seeds{$prot})){
my %inner = %{$seeds{$prot}};
$inner{$domain->get_name()."|".$d} = $eval;
$seeds{$prot} = \%inner;
}else{
$seeds{$prot} = {$domain->get_name()."|".$d => $eval};
}
#print $NF{$domain->get_name()}."\t";
#print $d."\t";
}
else{
my @f = @{$seed_feat{$domain->get_name()}};
my $eval;
if($prot_domain[$d]->get_e_value() == 0){
$eval = -2**31-1;
}
else{
$eval = log10($prot_domain[$d]->get_e_value());
}
push(@f, $eval);
if(exists($seeds{$prot})){
my %inner = %{$seeds{$prot}};
$inner{$domain->get_name()} = $eval;
$seeds{$prot} = \%inner;
}else{
$seeds{$prot} = {$domain->get_name() => $eval};
}
$seed_feat{$domain->get_name()} = \@f;
}
}
else{
#if the hash requires a key entry add it and starting value
my @f;
my $eval;
if($prot_domain[0]->get_e_value() == 0){
$eval = -2**31-1;
}
else{
$eval = log10($prot_domain[0]->get_e_value());
}
push(@f, $eval);
$seed_feat{$domain->get_name()} = \@f;
#my @a = @{$seed_feat{$domain->get_name()}};
if(exists($seeds{$prot})){
my %inner = %{$seeds{$prot}};
$inner{$domain->get_name()} = $eval;
$seeds{$prot} = \%inner;
}else{
$seeds{$prot} = {$domain->get_name() => $eval};
}
#print "@a\n";
#print $d."\t";
#print "here3\n";
}
}
}
}
else{
#if the key is already in the hash just a value
if(exists($seed_feat{$domain->get_name()})){
my @f = @{$seed_feat{$domain->get_name()}};
my $eval;
if($prot_domain[0]->get_e_value() == 0){
$eval = -2**31-1;
}
else{
$eval = log10($prot_domain[0]->get_e_value());
}
push(@f,$eval);
$seed_feat{$domain->get_name()} = \@f;
if(exists($seeds{$prot})){
my %inner = %{$seeds{$prot}};
$inner{$domain->get_name()} = $eval;
$seeds{$prot} = \%inner;
#print Dumper(%seeds);
#print "TRUE2\n";
}
else{
$seeds{$prot}={$domain->get_name()=>$eval};
}
}
else{
#if the hash requires a key entry add it and starting value
my @f;
my $eval;
if($prot_domain[0]->get_e_value() == 0){
$eval = -2**31-1;
}
else{
$eval = log10($prot_domain[0]->get_e_value());
}
push(@f, $eval);
$seed_feat{$domain->get_name()} = \@f;
#$seed_hash{$domain->get_name()} = log10(@prot_domain[0]->get_e_value());
if(exists($seeds{$prot})){
my %inner = %{$seeds{$prot}};
$inner{$domain->get_name()} = $eval;
$seeds{$prot} = \%inner;
#print Dumper(%seeds);
#print "TRUE2\n";
}
else{
$seeds{$prot}={$domain->get_name()=>$eval};
}
#need to fix rest of hash this way from seed hash!!!####
}
}
}
#my @keys = keys(%seed_feat);
# print $prot->get_name."\t"."@keys\n";
# <>;
}
#$seeds{$prot} = \%seed_hash;
#%seed_hash = {};
}
$seed_feat{"length"} = \@length;
if($verbose == 1){
print "\n";
foreach my $key (keys(%seed_feat)){
print " Key = $key \n";
print " Value = ".scalar(@{$seed_feat{$key}})."\n";
}
print "the seeds used are:\n";
foreach(@temp){
my $prot = ChromDB::Protein->fetch($_);
print $prot->get_chromdb_syn();
print "\n";
}
}
%seed_feat = %{ChromDB::QualityAssessment->necessary_feature_check(\%seed_feat, $numSeeds)};
if(scalar(keys(%seed_feat)) == 1){
my @key = keys(%seed_feat);
$errorMess = "Seeds contain only 1 necessary feature: ".$key[0];
return \%seed_feat;
}
%feat_test = %seed_feat;
return \%seed_feat;
}# get seeds
#takes in the canidate features and compares to see if it has at least
#the necessary features in order to continue
sub has_necessary_features(){
my $self = shift;
my $hash_ref = shift;
my %can_feat= %{$hash_ref};
my @missing_feat;
my %feat_to_use;
my $multi_domain =0;
#if using seeds remove the domains that dont match even if the other seeds have
#since this seed is feature limit
if($seed_test == 1){
foreach my $key(keys(%necessary_features)){
if(exists($can_feat{$key})){
next;
}
elsif($key =~ m/(\w*)\|(\d)/){
my $temp_key = $1;
my $number = $2;
if(exists($necessary_features{$temp_key}) && $necessary_features{$temp_key} > $number){
next;
}
}
else{
#print "$key is beiong removed\n";
delete $necessary_features{$key};
## need to update seed list here
##
##
##
if($verbose == 1){
print scalar(keys(%necessary_features));
print "\n";
}
}
}
if($verbose == 1){
print "\n the keys are\n";
print keys(%necessary_features);
print "\n";
}
}
#outer loop of canidate features (domains at this point)
foreach my $key(keys(%can_feat)){
if(exists($necessary_features{$key})){
$feat_to_use{$key} = $can_feat{$key};
}
else{