* Making an alignment:
my $db_obj = TFBS::DB::JASPAR2->new
(-connect => ["dbi:mysql:JASPAR2:myhost",
"myusername", "mypassword"]);
my $pfm1 = $db_obj->get_Matrix_by_ID("M0001", "PFM");
my $pfm2 = $db_obj->get_Matrix_by_ID("M0002", "PFM");
my $alignment= new TFBS::Matrix::Alignment(
-pfm1=>$pfm1,
-pfm2=>$pfm2,
-binary=>"/TFBS/Ext/matrix_aligner",
);
sub new
{ my ($class, %args) = @_;
my $self={
_pfm1=> $args{'-pfm1'},
_pfm2=> $args{'-pfm2'},
_ext_penalty=>$args{'-ext_penalty'}|| 0.01,
_open_penalty=> $args{'-open_penalty'}|| 3.00,
_strand=>'',
_align_string=>'',
_gaps=>'',
_aligned_positions =>'',
_score=>'',
};
bless $self, "TFBS::Matrix::Alignment";
my($fh1, $file1) = tmpnam();
print $fh1 $args{'-pfm1'}->rawprint()|| die " Cannot save temporary files for alignment";
my($fh2, $file2) = tmpnam();
print $fh2 $args{'-pfm2'}->rawprint()|| die " Cannot save temporary files for alignment";
my @pfm1_string;
my @pfm2_string;
foreach (`$args{'-binary'} $file1 $file2 $self->{'_open_penalty'} $self->{'_ext_penalty'}`){
my $max_length=$self->{'_pfm1'}->length();
$max_length=$self->{'_pfm2'}->length() if ( $self->{'_pfm2'}->length() > $self->{'_pfm1'}->length());
if (/^PFM1/){
s/PFM1//;
s/\t0/\t-/g;
@pfm1_string= split();
next;
}
if (/^PFM2/){
s/PFM2//;
s/\t0/\t-/g;
@pfm2_string= split();
next;
}
if (/^INFO/){
my @temp=split;
($self->{'_score'}, $self->{'_strand'}, $self->{'_aligned_positions'}, $self->{'_gaps'})= ($temp[3], $temp[6], $temp[7],$temp[8]);
next;
}
}
my $string= ($self->{'_pfm1'}->name()||$self->{'_pfm1'}->ID()||'PFM1')."\t\t";
my $string2=($self->{'_pfm2'}->name()||$self->{'_pfm2'}->ID()||'PFM2')."\t\t";;
if ($pfm1_string[0]==1){
$string.="-\t" x ($pfm2_string[0]-1);
foreach (my $j=1; $j< $pfm2_string[0]; $j++){
$string2.="$j\t";
}
}
if ($pfm2_string[0]==1){
$string2.="-\t" x ($pfm1_string[0]-1);
for (my $j=1; $j< $pfm1_string[0]; $j++){
$string.="$j\t";
}
}
$string.= join("\t", @pfm1_string);
$string2.= join("\t", @pfm2_string);
if ($pfm1_string[-1]==$self->{'_pfm1'}->length()){
$string.="\t-" x ($self->{'_pfm2'}->length()-$pfm2_string[-1]);
for (my $j=$pfm2_string[-1]+1; $j<= $self->{'_pfm2'}->length(); $j++){
$string2.="\t$j";
}
}
if ($pfm2_string[-1]==$self->{'_pfm2'}->length()){
$string2.="\t-" x ($self->{'_pfm1'}->length()-$pfm1_string[-1]);
for (my $j=$pfm1_string[-1]+1; $j<= $self->{'_pfm1'}->length(); $j++){
$string.="\t$j";
}
}
$self->{'_align_string'}= $string ."\n". $string2;
return $self;
}
} |
Please send bug reports and other comments to the author.