Source

GeneDesign-dev / lib / Bio / GeneDesign / RestrictionEnzyme.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
#
# GeneDesign module for restriction enzyme handing
#

=head1 NAME

Bio::GeneDesign::RestrictionEnzyme

=head1 VERSION

Version 5.00

=head1 DESCRIPTION

GeneDesign object that represents a type II restriction enzyme

=head1 AUTHOR

Sarah Richardson <SMRichardson@lbl.gov>

=cut

package Bio::GeneDesign::RestrictionEnzyme;

use Bio::GeneDesign::Basic qw(:GD);
use Carp;

use strict;
use warnings;

use base qw(Bio::Root::Root);

our $VERSION = 5.00;

my $IIPreg  = qr/   ([A-Z]*)   \^ ([A-Z]*)      /x;
my $IIAreg  = qr/\A \w+ \(([\-]*\d+) \/ ([\-]*\d+)\)\Z  /x;
my $IIBreg  = qr/\A\(([\-]*\d+) \/ ([\-]*\d+)\) \w+ \(([\-]*\d+) \/ ([\-]*\d+)\)\Z  /x;

my %RE_vendors = (
  B => "Invitrogen", C => "Minotech", E => "Stratagene Agilent",
  F => "Thermo Scientific Fermentas", I => "SibEnzyme", J => "Nippon Gene Co.",
  K => "Takara", M => "Roche Applied Science", N => "New England Biolabs",
  O => "Toyobo Technologies", Q => "Molecular Biology Resources",
  R => "Promega", S => "Sigma Aldrich", U => "Bangalore Genei", V => "Vivantis",
  X => "EURx", Y => "CinnaGen"
);

my %methtrans = (b => "blocked", blocked => "blocked",
                 i => "inhibited", inhibited => "inhibited",
                 u => "unknown", unknown => "unknown"
);

=head1 CONSTRUCTOR METHODS

=head2 new

You can create a new enzyme or clone an existing enzyme to create a new instance
of an abstract enzyme definition. To do this, provide the -enzyme flag; the
constructor will ignore every other argument except for -start.

Required arguments:

    EITHER
        
        -enzyme : a Bio::GeneDesign::RestrictionEnzyme object to clone
    
    OR
        -id     : The name of the enzyme (i.e., BamHI)
        -cutseq : The string describing the enzyme's recognition and cleavage
                  site

Optional arguments:

        -temp     : The incubation temperature for the enzyme
        -tempin   : The heat inactivation temperature for the enzyme
        -score    : A float score, usually the price of the enzyme in dollars
        -methdam  : Sensitivity to dam methylation; can take the values
                      b or blocked,
                      i or inhibited,
                      u or unknown,
                    if undefined, will take the value indifferent.
        -methdcm  : Sensitivity to dcm methylation; can take the values
                      b or blocked,
                      i or inhibited,
                      u or unknown,
                    if undefined, will take the value indifferent.
        -methcpg  : Sensitivity to cpg methylation; can take the values
                      b or blocked,
                      i or inhibited,
                      u or unknown,
                    if undefined, will take the value indifferent.
        -vendors  : a string of single letter codes that represent vendor
                    availability - no spaces.  see vendor() for a list of the
                    codes.
        -staract  : Whether or not the enzyme exhibits star activity - 1 or 0.
        -buffers  : a hash reference; keys are buffer names and values are the
                    enzyme activity in that buffer. For example:
                    NEB1 => 50, NEB2 => 100, etc.
        -start    : An integer representing an offset; usually used only in
                    cloned instances, as opposed to abstract instances.
        -exclude  : An arrayref full of ids for enzymes that should be
                    considered mutually exclusive to this enzyme - see exclude()

=cut

sub new
{
  my ($class, @args) = @_;
  my $self = $class->SUPER::new(@args);
  
  my ($object, $id, $cutseq, $temp, $tempin, $score, $methdam, $methdcm,
      $methcpg, $vendors, $staract, $buffers, $start, $exclude, $aggress) =
     $self->_rearrange([qw(ENZYME ID CUTSEQ TEMP TEMPIN SCORE METHDAM METHDCM
       METHCPG VENDORS STARACT BUFFERS START EXCLUDE AGGRESS)], @args);

  if ($object)
  {
    $self->throw("object of class " . ref($object) . " does not implement ".
        "Bio::GeneDesign::RestrictionEnzyme.")
      unless $object->isa("Bio::GeneDesign::RestrictionEnzyme");
    $self = $object->clone();
  }
  else
  {
    
    $self->throw("No enzyme id defined") unless ($id);
    $self->{'id'} = $id;

    $self->throw("No cut sequence defined") unless ($cutseq);
    $self->{'cutseq'} = $cutseq;

    my $recseq = $cutseq;
    $recseq =~ s/\W*\d*//xg;
    $self->{'recseq'} = $recseq;

    #Regular expression arrayref to use for enzyme searching
    #Should store as compiled regexes instead
    $self->{'regex'} = _regarr($recseq);

    my $sitelen = length($recseq);
    $self->{'length'} = $sitelen;

    #Enzyme Class and Palindromy
    my ($lef, $rig) = (q{}, q{});
    if ($cutseq =~ $IIPreg)
    {
      $lef = length($1);
      $rig = length($2);
      $self->{'class'} = "IIP";
      $self->{'classex'} = $IIPreg;
      
      if ($lef == $rig)
      {
        $self->{'palindromy'} = "unknown";
      }
      else
      {
        my $inlef = $lef;
        $inlef = length($recseq) - $inlef if ($inlef > (.5 * length($recseq)));
        my $mattersbit = substr($recseq, $inlef, length($recseq) - (2 * $inlef));
        if ($mattersbit && $mattersbit =~ $ambnt && length($mattersbit) % 2 == 0)
        {
          $self->{'palindromy'} = "pnon";
        }
        elsif ($mattersbit && $mattersbit eq _complement($mattersbit, 1))
        {
          $self->{'palindromy'} = "pal";
        }
        elsif ($mattersbit)
        {
          $self->{'palindromy'} = "nonpal";
        }
      }
    }
    elsif ($cutseq =~ $IIBreg)
    {
      $lef = int($1);
      $rig = int($2);
      $self->{'class'} = "IIB";
      $self->{'classex'} = $IIBreg;
      $self->{'palindromy'} = "pnon";
    }
    elsif ($cutseq =~ $IIAreg)
    {
      $lef = int($1);
      $rig = int($2);
      $self->{'class'} = "IIA";
      $self->{'classex'} = $IIAreg;
      $self->{'palindromy'} = "pnon";
    }
    else
    {
      $self->{'class'} = "unknown";
    }

    #Enzyme type
    my $type;
    if ($lef < $rig)
    {
      $type .= "5'";
      $self->{'inside_cut'} = $lef;
      $self->{'outside_cut'} = $rig;
    }
    elsif ($lef > $rig)
    {
      $type .= "3'";
      $self->{'inside_cut'} = $rig;
      $self->{'outside_cut'} = $lef;
    }
    elsif ($lef == $rig)
    {
      $type .= "b";
    }
    $self->{'onebpoverhang'} = 1 if (abs($lef - $rig) == 1);
    $self->{'type'} = $type;

    $self->{'temp'} = $temp if ($temp);
    if ($tempin)
    {
      my ($intime, $intemp) = split q{@}, $tempin;
      $self->{'tempin'} = $intemp;
      $self->{'timein'} = $intime;
    }

    $self->{'score'} = $score if ($score);
    $self->{'aggress'} = $aggress;
    
    $self->{'staract'} = 1 if ($staract);

    if (exists $methtrans{$methdam})
    {
      $self->{'methdam'} = $methtrans{$methdam};
    }
    else
    {
      $self->{'methdam'} = "indifferent";
    }

    if (exists $methtrans{$methdcm})
    {
      $self->{'methdcm'} = $methtrans{$methdcm};
    }
    else
    {
      $self->{'methdcm'} = "indifferent";
    }
    
    if (exists $methtrans{$methcpg})
    {
      $self->{'methcpg'} = $methtrans{$methcpg};
    }
    else
    {
      $self->{'methcpg'} = "indifferent";
    }

    if ($vendors)
    {
      my %vhsh = ();
      foreach my $v (split(q{}, $vendors))
      {
        $vhsh{$v} = $RE_vendors{$v} if (exists $RE_vendors{$v});
        carp("$v not in vendor list!") unless (exists $RE_vendors{$v});
      }
      $self->{'vendors'} = \%vhsh;
    }
    
    $self->{'buffers'} = $buffers if ($buffers);
  }
  
  $self->{'start'} = $start if ($start);
  
  $self->{'exclude'} = $exclude if ($exclude);
  
  return $self;
}

=head1 FUNCTIONAL METHODS

=head2 clone

By default in GeneDesign code, RestrictionEnzyme objects are meant to stand as
abstracts - that is, they stand for BamHI in general, and not for a particular
instance of a BamHI recognition site. If you want to use the objects in the
latter sense, you will need to clone the abstract object instantiated when the
definition file is read in, thus generating an arbitrary number of BamHI
instances that can then be differentiated by their start attributes.

=cut

sub clone
{
   my ($self) = @_;
   my $copy;
   foreach my $key (keys %$self)
   {
     if (ref $self->{$key} eq "ARRAY")
     {
       $copy->{$key} = [@{$self->{$key}}];
     }
     elsif (ref $self->{$key} eq "HASH")
     {
       $copy->{$key} = {%{$self->{$key}}};
     }
     else
     {
      $copy->{$key} = $self->{$key};
     }
   }
   bless $copy, ref $self;
   return $copy;
}

=head2 positions

Generates a hash describing the positions of the enzyme's recognition
sites in a nucleotide sequence. Keys are offset in nucleotides, and values are
the recognition site found at said offset as a string.
  
=cut

sub positions
{
  my ($self, $seq) = @_;
  my $total = {};
  foreach my $sit (@{$self->{regex}})
  {
    while ($seq =~ /(?=($sit))/ixg)
    {
      $total->{pos $seq} = $1;
    }
  }
  return $total;
}

=head2 overhang

Given a nucleotide sequence context, what overhang does this enzyme leave, and
how far away from the cutsite is it?

Arguments:

=cut

sub overhang
{
  my ($self, $dna, $context, $strand) = @_;
  my ($ohangstart, $mattersbit) = (0, q{});
  my $lef;
  my $rig;
  if ($self->{class} eq "IIP")
  {
    ($lef, $rig) = (length($1), length($2)) if ($self->{cutseq} =~ $IIPreg);
    ($lef, $rig) = ($rig, $lef) if ($rig < $lef);
    $ohangstart = $lef + 1;
    $mattersbit = substr($dna, $ohangstart-1, $rig-$lef);
  }
  elsif ($self->{class} eq "IIA")
  {
    ($lef, $rig) = ($1, $2) if ($self->{cutseq} =~ $IIAreg);
    ($lef, $rig) = ($rig, $lef) if ($rig < $lef);
    if ($strand == 1)
    {
      $ohangstart = length($dna) + $lef + 1;
    }
    else
    {
      $ohangstart = length($context) - length($dna) - $rig + 1;
    }
    $mattersbit = substr($context, $ohangstart-1, $rig-$lef);
    $ohangstart = $strand == 1  ? length($dna) + $lef :   0 - ($rig);
  }
  else
  {
    return ();
  }
  return ($ohangstart, $mattersbit);
}

=head2 display

Generates a tab delimited display string that can be used to print enzyme
information out in a tabular format.

=cut

sub display
{
  my ($self) = @_;
  my $staract = $self->{staract}  ? "*" : q{};
  my (@blocked, @inhibed) = ((), ());
  push @blocked, "cpg" if ($self->{methcpg} eq "blocked");
  push @blocked, "dam" if ($self->{methdam} eq "blocked");
  push @blocked, "dcm" if ($self->{methdcm} eq "blocked");
  push @inhibed, "cpg" if ($self->{methcpg} eq "inhibited");
  push @inhibed, "dam" if ($self->{methdam} eq "inhibited");
  push @inhibed, "dcm" if ($self->{methdcm} eq "inhibited");
  my $buffstr = undef;
  foreach (sort keys %{$self->{buffers}})
  {
    $buffstr .= "$_ (" . $self->{buffers}->{$_} . ") " if ($self->{buffers}->{$_});
  }
  my $vendstr = join(", ", values %{$self->{vendors}});
  my $display = undef;
  my $inact = $self->{tempin} ? " (". $self->{timein} . q{@} . $self->{tempin} . ")" : q{};
  $display .= $self->{id} . "\t";
  $display .= $self->{cutseq} . $staract . "\t";
  $display .= $self->{type} . "\t";
  $display .= $self->{start} . "\t" if ($self->{start});
  $display .= $self->{temp} . $inact . "\t";
  $display .= join(", ", @blocked) . "\t";
  $display .= join(", ", @inhibed) . "\t";
  $display .= $self->{score} . "\t";
  $display .= $buffstr . "\t";
  $display .= $vendstr . "\t";
  return $display;
}

=head2 common_buffers

Returns an array reference listing the buffers, if any, in which two enzymes
both have 100% activity. in boolean mode returns the number of buffers

=cut

sub common_buffers
{
  my ($self, $buddy, $bool) = @_;
  $self->throw("Argument is not a Bio::GeneDesign::RestrictionEnzyme")
    unless $buddy->isa("Bio::GeneDesign::RestrictionEnzyme");

  my $sbuffs = $self->{buffers};
  my $bbuffs = $buddy->{buffers};
  my @answer;
  foreach my $skey (sort keys %{$sbuffs})
  {
    my $sval = $sbuffs->{$skey};
    my $bval = $bbuffs->{$skey};
    if ($skey eq "Other" && $sval && $bval && "$sval" eq "$bval")
    {
      push @answer, $skey;
    }
    elsif ($sval && $bval && "$sval" == 100 && "$bval" == 100)
    {
      push @answer, $skey;
    }
  }
  return $bool  ? scalar(@answer)  : \@answer;
}

=head2 acceptable_buffer

Returns a buffer in which both enzymes will have at least a thresholded amount
of activity.

=cut

sub acceptable_buffer
{
  my ($self, $buddy, $level) = @_;
  $self->throw("Argument is not a Bio::GeneDesign::RestrictionEnzyme")
    unless $buddy->isa("Bio::GeneDesign::RestrictionEnzyme");

  $level = $level || 75;
  my $sbuffs = $self->{buffers};
  my $bbuffs = $buddy->{buffers};
  my %answers;
  foreach my $skey (sort keys %{$sbuffs})
  {
    my $sval = $sbuffs->{$skey};
    my $bval = $bbuffs->{$skey};
    if ($skey eq "Other" && $sval && $bval && $sval == $bval)
    {
      $answers{$skey} = 200;
    }
    elsif ($sval && $bval && $sval >= $level && $bval >= $level)
    {
      $answers{$skey} = $sval + $bval;
    }
  }
  my @keys = sort {$answers{$b} <=> $answers{$a} && $b cmp $a} keys %answers;
  return scalar @keys  ? $keys[0]  : undef;
}

=head2 units

Returns the number of units needed to cleave some sequence

=cut

sub units
{
  my ($self, @args) = @_;
  
  my ($buffer, $sequence) = $self->_rearrange([qw(buffer sequence)], @args);
  
  
  my $poshsh = $self->positions($sequence);
  my $count = scalar keys %{$poshsh};
  
  my $freq = $count / (length $sequence);
  
  my $aggr = $self->aggress() || .000001;
  $aggr = 1 / $aggr;
  
  $buffer = $buffer || $self->acceptable_buffer($self, 100);
  my $buff = $self->buffers->{$buffer} || 1;
  my $jad = $buff / 100;
  my $adj = $jad > 0  ? 1 / $jad : 0;
  
  my $units = sprintf("%.1f", $freq * $aggr * $adj);
  
  return $units;
}


=head1 FILTERING METHODS

=head2 filter_by_sequence

  Arguments: an arrayref of string nucleotide sequences (may be ambiguous)
             a flag indicating whether or not the sequences in the array are
              required (1 means they must NOT match; default 0 means they must
              match)
  
  Returns : 1 if the enzyme passes;
            0 if the enzyme fails.

=cut

sub filter_by_sequence
{
  my ($self, $arrref, $req) = @_;
  $req = 0 if (! $req);
  my $result = 1;
  foreach my $seq (@$arrref)
  {
    my $regex = _regres($seq, 1);
    if ($regex =~ /\[ X \]/x)
    {
      print "\tWARNING: Can't parse sequence $seq containing non-nucleotide "
        . "characters - ignoring.\n";
      next;
    }
    $result = 0 if ( $req == 1 && $self->{recseq} =~ $regex );
    $result = 0 if ( $req == 0 && $self->{recseq} !~ $regex );
  }
  return $result;
}

=head2 filter_by_score

  Arguments : a float

  Returns   : 1 if the enzyme's score is less than or equal to the argument,
              0 if the enzyme's score is higher.

=cut

sub filter_by_score
{
  my ($self, $score) = @_;
  my $result = 1;
  $result = 0 if ($self->{score} > $score);
  return $result;
}

=head2 filter_by_vendor

  Arguments : an arrayref of vendor abbreviations; see vendor().

  Returns   : 1 if the enzyme is supplied by any of the vendors queried,
              0 else.

=cut

sub filter_by_vendor
{
  my ($self, $vendlist) = @_;
  my $result = 1;
  my $flag = 0;
  foreach my $vend (@$vendlist)
  {
    unless (exists($RE_vendors{$vend}))
    {
      print "\tWARNING: Can't parse vendor argument $vend - ignoring.\n";
      next;
    }
    $flag++ if ( exists( $self->{vendors}->{$vend} ) );
  }
  $result = $flag == 0 ? 0 : 1;
  return $result;
}

=head2 filter_by_buffer_activity

  Arguments : a hashref of buffer thresholds; the key is the buffer name, the
                value is an activity threshold.
                
  Returns   : 1 if the enzyme meets all the buffer requirements,
              0 else.

=cut

sub filter_by_buffer_activity
{
  my ($self, $hshref) = @_;
  my $result = 1;
  my $rebuff = $self->{buffers};
  foreach my $buff (keys %$hshref)
  {
    my $val = $hshref->{$buff};
    $result = 0 if ( ! exists($rebuff->{$buff}) || $rebuff->{$buff} < $val );
  }
  
  return $result;
}

=head2 filter_by_dcm_sensitivity

  Arguments : an arrayref of sensitivity values; the key is the sensitivity
                blocked, inhibited, or indifferent
              
  Returns   : 1 if the enzyme meets the dcm sensitivity requirements,
              0 else.
            
=cut

sub filter_by_dcm_sensitivity
{
  my ($self, $arrref) = @_;
  my $result = 1;
  my %sensehsh;
  foreach my $sense (@$arrref)
  {
    if ($sense ne "blocked" && $sense ne "inhibited" && $sense ne "indifferent")
    {
      $sense = lc $sense;
      print "\tWARNING: Can't parse dcmsense argument $sense - ignoring.\n";
      next;
    }
    $sensehsh{$sense}++;
  }
  $result = 0 unless ( exists($sensehsh{$self->{methdcm}}) );
  return $result;
}

=head2 filter_by_dam_sensitivity

  Arguments : an arrayref of sensitivity values; the key is the sensitivity
                blocked, inhibited, or indifferent
              
  Returns   : 1 if the enzyme meets the dam sensitivity requirements,
              0 else.
            
=cut

sub filter_by_dam_sensitivity
{
  my ($self, $arrref) = @_;
  my $result = 1;
  my %sensehsh;
  foreach my $sense (@$arrref)
  {
    if ($sense ne "blocked" && $sense ne "inhibited" && $sense ne "indifferent")
    {
      $sense = lc $sense;
      print "\tWARNING: Can't parse damsense argument $sense - ignoring.\n";
      next;
    }
    $sensehsh{$sense}++;
  }
  $result = 0 unless ( exists($sensehsh{$self->{methdam}}) );
  return $result;
}

=head2 filter_by_cpg_sensitivity

  Arguments : an arrayref of sensitivity values; the key is the sensitivity
                blocked, inhibited, or indifferent
              
  Returns   : 1 if the enzyme meets the cpg sensitivity requirements,
              0 else.
            
=cut

sub filter_by_cpg_sensitivity
{
  my ($self, $arrref) = @_;
  my $result = 1;
  my %sensehsh;
  foreach my $sense (@$arrref)
  {
    if ($sense ne "blocked" && $sense ne "inhibited" && $sense ne "indifferent")
    {
      $sense = lc $sense;
      print "\tWARNING: Can't parse cpgsense argument $sense - ignoring.\n";
      next;
    }
    $sensehsh{$sense}++;
  }
  $result = 0 unless ( exists($sensehsh{$self->{methcpg}}) );
  return $result;
}

=head2 filter_by_star_activity

  Arguments : 1 if star activity required, 0 else
            
  Returns   : 1 if the enzyme meets the star activity requirements,
              0 else.

=cut

sub filter_by_star_activity
{
  my ($self, $star) = @_;
  my $result = 1;
  $star = 0 unless ($star);
  $result = 0 if (($star && ! $self->{staract}) || (! $star && $self->{staract}));
  return $result;
}

=head2 filter_by_incubation_temperature

  Arguments : an arrayref of acceptable integer incubation temperatures
          
  Returns   : 1 if the enzyme meets the incubation temperature requirements,
              0 else.

=cut

sub filter_by_incubation_temperature
{
  my ($self, $arrref) = @_;
  my $result = 1;
  my %temps;
  foreach my $temp (@$arrref)
  {
    if ($temp !~ /\d/x || $temp <= 0)
    {
      print "\tWARNING: Can't parse incubation argument $temp - ignoring.\n";
    }
    $temps{$temp}++;
  }
  $result = 0 unless ( exists $temps{$self->{temp}});
  return $result;
}

=head2 filter_by_inactivation_temperature

  Arguments : an acceptable integer inactivation temperature maximum
          
  Returns   : 1 if the enzyme meets the inactivation temperature requirement,
              0 else.

=cut

sub filter_by_inactivation_temperature
{
  my ($self, $temp) = @_;
  my $result = 1;
  if ($temp !~ /\d/x || $temp <= 0)
  {
    print "\tWARNING: Can't parse inactivation argument $temp - ignoring.\n";
  }
  else
  {
    $result = 0 if ($self->{tempin} > $temp);
  }
  return $result;
}

=head2 filter_by_base_ambiguity

  Arguments : "nonNonly" if any non N bases are allowed; "ATCGonly" if only
                A, T, C, or G are allowed
        
  Returns   : 1 if the enzyme meets the ambiguous nucleotide requirement,
              0 else.

=cut

sub filter_by_base_ambiguity
{
  my ($self, $ambig) = @_;
  my $result = 1;
  if ($ambig ne "nonNonly" && $ambig ne "ATCGonly")
  {
    print "\tWARNING: Can't parse ambiguity argument $ambig - ignoring.\n";
  }
  else
  {
    my $ambregex;
    $ambregex  = qr/N/  if ($ambig eq "nonNonly");
    $ambregex  = $ambnt  if ($ambig eq "ATCGonly");
    $result = 0 unless ( $self->{recseq} =~ $ambregex );
  }
  return $result;
}

=head2 filter_by_length

  Arguments : an arrayref of acceptable recognition site lengths
        
  Returns   : 1 if the enzyme meets the recognition site length requirements,
              0 else.

=cut

sub filter_by_length
{
  my ($self, $arrref) = @_;
  my $result = 1;
  my %lens;
  foreach my $len (@$arrref)
  {
    if ($len =~ /\D/x || $len <= 0)
    {
      print "\tWARNING: Can't parse length argument $len - ignoring.\n";
      next;
    }
    $lens{$len}++;
  }
  $result = 0 unless ( exists $lens{length($self->{recseq})} );
  return $result;
}

=head2 filter_by_overhang_palindromy

  Arguments : an arrayref of acceptable overhang palindromys, from the list
                pal (palindromic),
                nonpal (nonpalindromic),
                pnon (potentially nonpalindromic)
      
  Returns   : 1 if the enzyme meets the palindromy requirements,
              0 else.

=cut

sub filter_by_overhang_palindromy
{
  my ($self, $arrref) = @_;
  my $result = 1;
  my %pals;
  foreach my $pal (@$arrref)
  {
    if ($pal ne "pal" && $pal ne "pnon" && $pal ne "nonpal")
    {
      print "\tWARNING: Can't parse palindromy argument $pal - ignoring.\n";
      next;
    }
    $pals{$pal}++;
  }
  $result = 0 unless (exists $pals{$self->{palindromy}});
  return $result;
}

=head2 filter_by_stickiness

  Arguments : an arrayref of acceptable overhang orientations, from the list
                1 (single basepair overhang),
                5 (five prime overhang),
                3 (three prime overhang),
                b (blunt ended)
    
  Returns   : 1 if the enzyme meets the overhang requirements,
              0 else.

=cut

sub filter_by_stickiness
{
  my ($self, $arrref) = @_;
  my $result = 1;
  my %sticks;
  foreach my $stick (@$arrref)
  {
    if ($stick ne "5" && $stick ne "3" && $stick ne "1" && $stick ne "b")
    {
      print "\tWARNING: Can't parse sticky argument $stick - ignoring.\n";
      next;
    }
    $sticks{$stick}++;
  }
  $result = 0 if ($self->{onebpoverhang} && ! exists $sticks{1});
  my $type = $self->{type};
  $type =~ s/\'//xg;
  $result = 0 unless (exists $sticks{$type});
  return $result;
}

=head1 ACCESSOR METHODS

Methods for setting and accessing enzyme attributes

=head2 id

The name of the enzyme.

=cut

sub id
{
  my ($self) = @_;
  return $self->{'id'};
}

=head2 display_name

The name of the enzyme.

=cut

sub display_name
{
  my ($self) = @_;
  return $self->{'id'};
}

=head2 score

This attribute initially holds the price in dollars per unit of the enzyme
(2009 US Dollars) but can be used to hold any score or cost value.

=cut

sub score
{
  my ($self, $value) = @_;
  if (defined $value)
  {
    $self->{'score'} = $value;
  }
  return $self->{'score'};
}

=head2 aggress

Aggressiveness is the number of recognition sites in a template piece of DNA
(usually lambda, but sometimes adeno2, pBR322, pUC19, pXba, etc) over the total
length of that template piece of DNA. This number tells the manufacturer how
much enzyme to sell as a "unit" - the amount of enzyme required to fully digest
one microgram of template DNA under reaction conditions in an hour.

=cut

sub aggress
{
  my ($self, $value) = @_;
  if (defined $value)
  {
    $self->{'aggress'} = $value;
  }
  return $self->{'aggress'};
}

=head2 len

The length in bases of the recognition sequence (recseq).

=cut

sub len
{
  my ($self) = @_;
  return $self->{'length'};
}

=head2 methcpg

The effect of CpG methylation on the enzyme's efficacy.

=cut

sub methcpg
{
  my ($self) = @_;
  return $self->{'methcpg'};
}

=head2 methdcm

The effect of Dcm methylation on the enzyme's efficacy.

=cut

sub methdcm
{
  my ($self) = @_;
  return $self->{'methdcm'};
}

=head2 methdam

The effect of Dam methylation on the enzyme's efficacy.

=cut

sub methdam
{
  my ($self) = @_;
  return $self->{'methdam'};
}

=head2 buffers

A hash reference where the keys are buffer names and the values are the activity
level of the enzyme in that Buffer. Since most of the enzymes in the default
GeneDesign list are NEB enzymes, this is usually full of NEB buffers.

=cut

sub buffers
{
  my ($self) = @_;
  return $self->{'buffers'};
}

=head2 vendors

A hash reference where the keys are abbreviations for and the values are names
of vendors that stock the enzyme. These are read in from the enzyme file.

                      B = Invitrogen
                      C = Minotech
                      E = Stratagene
                      F = Thermo Scientific Fermentas
                      I = SibEnzyme
                      J = Nippon Gene Co.
                      K = Takara
                      M = Roche Applied Science
                      N = New England Biolabs
                      O = Toyobo Technologies
                      Q = Molecular Biology Resources
                      R = Promega
                      S = Sigma Aldrich
                      U = Bangalore Genei
                      V = Vivantis
                      X = EURx
                      Y = CinnaGen
                      
=cut

sub vendors
{
  my ($self) = @_;
  return $self->{'vendors'};
}

=head2 tempin

The temperature in degrees Celsius that deactivates the enzyme.

=cut

sub tempin
{
  my ($self) = @_;
  return $self->{'tempin'};
}

=head2 timein

The time required at inactivation temperature to deactivate the enzyme.

=cut

sub timein
{
  my ($self) = @_;
  return $self->{'timein'};
}

=head2 temp

Incubation temperature for the best enzyme activity, in degrees Celsius.

=cut

sub temp
{
  my ($self) = @_;
  return $self->{'temp'};
}

=head2 recseq

This attribute is the "clean" description of the enzyme's recognition sequence -
that is, no information about cleavage site can be gained from this attribute.
This is determined automatically from the cleavage string (cutseq) at
instantiation.

=cut

sub recseq
{
  my ($self) = @_;
  return $self->{'recseq'};
}

=head2 seq

Synonym for recseq

=cut

sub seq
{
  my ($self) = @_;
  return $self->{'recseq'};
}

=head2 cutseq

This attribute is the string description of the enzyme's recognition sequence.
It includes information about both the recognition and cleavage sites.
See http://rebase.neb.com/rebase/rebrec.html for help interpreting this field.

=cut

sub cutseq
{
  my ($self) = @_;
  return $self->{'cutseq'};
}

=head2 regex

This attribute stores a set of regular expressions as an array reference to
speed the search for recognition sites in sequence. The first entry in the
arrayref is the regular expression representing the forward orientation of
the recognition sequence; the second entry represents the reverse orientation
and is only defined if the recognition site is nonpalindromic.

This attribute is defined at instantiation.

=cut

sub regex
{
  my ($self) = @_;
  return $self->{'regex'};
}

=head2 class

Class describes the cutting behavior of an enzyme. The classes used by
GeneDesign uses a generalized subset of the classes as described at Rebase - for
the purposes of enzyme editing, three classes have so far proven to be enough.
See http://rebase.neb.com/cgi-bin/sublist for the full description of enzyme
classes.

  IIP : This enzyme has a symmetric target and a symmetric cleavage site; this
        usually means that the enzyme cleaves inside its own recognition site.
        This is not the same as overhang palindromy!
        
  IIA : This enzyme has an asymmetric recognition site and usually cleaves
        outside of it.
        
  IIB : This enzyme has one recognition site and two cleavage sites, one on
        either side of the recognition site, and thus cuts itself out of
        sequence.

=cut

sub class
{
  my ($self) = @_;
  return $self->{'class'};
}

=head2 classex

=cut

sub classex
{
  my ($self) = @_;
  return $self->{'classex'};
}

=head2 class_regexes

Short cut to accessing class regular expressions

=cut

sub class_regexes
{
  return {"IIP" => $IIPreg, "IIA" => $IIAreg, "IIB" => $IIBreg};
}

=head2 type

Type describes the kind of overhang left by an enzyme. This is probably not a
good use of the word type.

Type may be 5', for a five prime overhang; 3', for a three prime overhang;
or b for blunt ends.

=cut

sub type
{
  my ($self) = @_;
  return $self->{'type'};
}


=head2 onebpoverhang

One basepair overhangs can be harder to ligate than blunt ends. This attribute
returns 1 if an enzyme leaves a 1bp overhang and 0 else.

=cut

sub onebpoverhang
{
  my ($self) = @_;
  return $self->{'onebpoverhang'};
}

=head2 exclude

Some enzymes share overlapping recognition sites. If you are trying to ensure
the absence or uniqueness of a recognition site, you will want to be sure to
exclude isoschizomers and neoschizomers from consideration elsewhere. The
exclude attribute stores an array reference that lists the ids of neo- and
isoschizomers - or any arbitrary enzyme that is incompatible with this enzyme -
for easy lookup.

=cut

sub exclude
{
  my ($self, $value) = @_;
  if (defined $value)
  {
    $self->throw("$value is not a reference to an array")
      unless (ref $value eq "ARRAY");
    $self->{'exclude'} = $value;
  }
  return $self->{'exclude'};
}

=head2 palindromy

Information about the overhang the enzyme leaves.

  pal     = palindromic
  nonpal  = nonpalindromic
  pnon    = potentially nonpalindromic, or sometimes palindromic and sometimes
            nonpalindromic
  unknown = unknown
  
=cut

sub palindromy
{
  my ($self) = @_;
  return $self->{'palindromy'};
}

=head2 staract

1 if the enzyme exhibits star activity, 0 else

=cut

sub staract
{
  my ($self) = @_;
  return $self->{'staract'};
}

=head2 start

The offset in nucleotides of the enzymes recognition site in an ORF

=cut

sub start
{
  my ($self, $value) = @_;
  if (defined $value)
  {
    $self->{'start'} = $value;
  }
    return $self->{'start'};
}

=head2 outside_cut

=cut

sub outside_cut
{
  my ($self) = @_;
  return $self->{'outside_cut'};
}

=head2 inside_cut

=cut

sub inside_cut
{
  my ($self) = @_;
  return $self->{'inside_cut'};
}

1;

__END__

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2012, GeneDesign developers
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

* The names of Johns Hopkins, the Joint Genome Institute, the Lawrence Berkeley
National Laboratory, the Department of Energy, and the GeneDesign developers may
not be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=cut