533
565
my $out_ID = ( split(' ',$type_out) )[1];
535
567
if ($in_ID ne 'consensus') {
536
$read_in = $self->get_seq_coord( $self->get_seq_by_name($in_ID) );
537
$self->throw("Can't change coordinates without sequence location for $in_ID")
538
unless (defined $read_in);
568
$read_in = $self->get_seq_coord( $self->get_seq_by_name($in_ID) );
569
$self->throw("Can't change coordinates without sequence location for $in_ID")
570
unless (defined $read_in);
540
572
if ($out_ID ne 'consensus') {
541
$read_out = $self->get_seq_coord( $self->get_seq_by_name($out_ID) );
542
$self->throw("Can't change coordinates without sequence location for $out_ID")
543
unless (defined $read_out);
573
$read_out = $self->get_seq_coord( $self->get_seq_by_name($out_ID) );
574
$self->throw("Can't change coordinates without sequence location for $out_ID")
575
unless (defined $read_out);
546
578
# Performing transformation between coordinates
549
# Transformations between contig padded and contig unpadded
550
(($type_in eq 'gapped consensus') && ($type_out eq 'ungapped consensus')) && do {
551
$self->throw("Can't use ungapped consensus coordinates without a consensus sequence")
552
unless (defined $self->{'_consensus_sequence'});
553
$query = &_padded_unpadded($self->{'_consensus_gaps'}, $query);
556
(($type_in eq 'ungapped consensus') && ($type_out eq 'gapped consensus')) && do {
557
$self->throw("Can't use ungapped consensus coordinates without a consensus sequence")
558
unless (defined $self->{'_consensus_sequence'});
559
$query = &_unpadded_padded($self->{'_consensus_gaps'},$query);
563
# Transformations between contig (padded) and read (padded)
564
(($type_in eq 'gapped consensus') &&
565
($type_out =~ /^aligned /) && defined($read_out)) && do {
566
$query = $query - $read_out->start() + 1;
569
(($type_in =~ /^aligned /) && defined($read_in) &&
570
($type_out eq 'gapped consensus')) && do {
571
$query = $query + $read_in->start() - 1;
575
# Transformations between contig (unpadded) and read (padded)
576
(($type_in eq 'ungapped consensus') &&
577
($type_out =~ /^aligned /) && defined($read_out)) && do {
578
$query = $self->change_coord('ungapped consensus','gapped consensus',$query);
579
$query = $self->change_coord('gapped consensus',"aligned $out_ID",$query);
582
(($type_in =~ /^aligned /) && defined($read_in) &&
583
($type_out eq 'ungapped consensus')) && do {
584
$query = $self->change_coord("aligned $in_ID",'gapped consensus',$query);
585
$query = $self->change_coord('gapped consensus','ungapped consensus',$query);
589
# Transformations between seq $read_in padded and seq $read_out padded
590
(defined($read_in) && ($type_in =~ /^aligned /) &&
591
defined($read_out) && ($type_out =~ /^aligned /)) && do {
592
$query = $self->change_coord("aligned $in_ID",'gapped consensus',$query);
593
$query = $self->change_coord('gapped consensus',"aligned $out_ID",$query);
597
# Transformations between seq $read_in padded and seq $read_out unpadded
598
(defined($read_in) && ($type_in =~ /^aligned /) &&
599
defined($read_out) && ($type_out =~ /^unaligned /)) && do {
600
if ($read_in ne $read_out) {
601
$query = $self->change_coord("aligned $in_ID",'gapped consensus',$query);
602
$query = $self->change_coord('gapped consensus',"aligned $out_ID",$query);
604
my $list_out = $self->{'_elem'}{$out_ID}{'_gaps'};
605
$query = &_padded_unpadded($list_out,$query);
606
# Changing read orientation if read was reverse complemented when aligned
607
if ($read_out->strand == -1) {
608
my ($length) = $read_out->length();
609
$length = $length - &_nof_gaps($list_out,$length);
610
$query = $length - $query + 1;
614
(defined($read_in) && ($type_in =~ /^unaligned /) &&
615
defined($read_out) && ($type_out =~ /^aligned /)) && do {
616
my $list_in = $self->{'_elem'}{$in_ID}{'_gaps'};
617
# Changing read orientation if read was reverse complemented when aligned
618
if ($read_in->strand == -1) {
619
my ($length) = $read_in->length();
620
$length = $length - &_nof_gaps($list_in,$length);
621
$query = $length - $query + 1;
623
$query = &_unpadded_padded($list_in,$query);
624
if ($read_in ne $read_out) {
625
$query = $self->change_coord("aligned $in_ID",'gapped consensus',$query);
626
$query = $self->change_coord('gapped consensus',"aligned $out_ID",$query);
631
# Transformations between seq $read_in unpadded and seq $read_out unpadded
632
(defined($read_in) && ($type_in =~ /^unaligned /) &&
633
defined($read_out) && ($type_out =~ /^unaligned /)) && do {
634
$query = $self->change_coord("unaligned $in_ID","aligned $out_ID",$query);
635
$query = $self->change_coord("aligned $out_ID","unaligned $out_ID",$query);
639
# Transformations between contig (padded) and read (unpadded)
640
(($type_in eq 'gapped consensus') &&
641
($type_out =~ /^unaligned /) && defined($read_out)) && do {
642
$query = $self->change_coord('gapped consensus',"aligned $out_ID",$query);
643
$query = $self->change_coord("aligned $out_ID","unaligned $out_ID",$query);
646
(($type_in =~ /^unaligned /) && defined($read_in) &&
647
($type_out eq 'gapped consensus')) && do {
648
$query = $self->change_coord("unaligned $in_ID","aligned $in_ID",$query);
649
$query = $self->change_coord("aligned $in_ID",'gapped consensus',$query);
653
# Transformations between contig (unpadded) and read (unpadded)
654
(($type_in eq 'ungapped consensus') &&
655
($type_out =~ /^unaligned /) && defined($read_out)) && do {
656
$query = $self->change_coord('ungapped consensus','gapped consensus',$query);
657
$query = $self->change_coord('gapped consensus',"unaligned $out_ID",$query);
660
(($type_in =~ /^unaligned /) && defined($read_in) &&
661
($type_out eq 'ungapped consensus')) && do {
662
$query = $self->change_coord("unaligned $in_ID",'gapped consensus',$query);
663
$query = $self->change_coord('gapped consensus','ungapped consensus',$query);
667
$self->throw("Unknow coordinate system. Args: $type_in, $type_out.");
668
$query = undef; # If a coordinate systems just requested is unknown
581
# Transformations between contig padded and contig unpadded
582
(($type_in eq 'gapped consensus') && ($type_out eq 'ungapped consensus')) && do {
583
$self->throw("Can't use ungapped consensus coordinates without a consensus sequence")
584
unless (defined $self->{'_consensus_sequence'});
585
$query = &_padded_unpadded($self->{'_consensus_gaps'}, $query);
588
(($type_in eq 'ungapped consensus') && ($type_out eq 'gapped consensus')) && do {
589
$self->throw("Can't use ungapped consensus coordinates without a consensus sequence")
590
unless (defined $self->{'_consensus_sequence'});
591
$query = &_unpadded_padded($self->{'_consensus_gaps'},$query);
595
# Transformations between contig (padded) and read (padded)
596
(($type_in eq 'gapped consensus') &&
597
($type_out =~ /^aligned /) && defined($read_out)) && do {
598
$query = $query - $read_out->start() + 1;
601
(($type_in =~ /^aligned /) && defined($read_in) &&
602
($type_out eq 'gapped consensus')) && do {
603
$query = $query + $read_in->start() - 1;
607
# Transformations between contig (unpadded) and read (padded)
608
(($type_in eq 'ungapped consensus') &&
609
($type_out =~ /^aligned /) && defined($read_out)) && do {
610
$query = $self->change_coord('ungapped consensus','gapped consensus',$query);
611
$query = $self->change_coord('gapped consensus',"aligned $out_ID",$query);
614
(($type_in =~ /^aligned /) && defined($read_in) &&
615
($type_out eq 'ungapped consensus')) && do {
616
$query = $self->change_coord("aligned $in_ID",'gapped consensus',$query);
617
$query = $self->change_coord('gapped consensus','ungapped consensus',$query);
621
# Transformations between seq $read_in padded and seq $read_out padded
622
(defined($read_in) && ($type_in =~ /^aligned /) &&
623
defined($read_out) && ($type_out =~ /^aligned /)) && do {
624
$query = $self->change_coord("aligned $in_ID",'gapped consensus',$query);
625
$query = $self->change_coord('gapped consensus',"aligned $out_ID",$query);
629
# Transformations between seq $read_in padded and seq $read_out unpadded
630
(defined($read_in) && ($type_in =~ /^aligned /) &&
631
defined($read_out) && ($type_out =~ /^unaligned /)) && do {
632
if ($read_in ne $read_out) {
633
$query = $self->change_coord("aligned $in_ID",'gapped consensus',$query);
634
$query = $self->change_coord('gapped consensus',"aligned $out_ID",$query);
636
my $list_out = $self->{'_elem'}{$out_ID}{'_gaps'};
637
$query = &_padded_unpadded($list_out,$query);
638
# Changing read orientation if read was reverse complemented when aligned
639
if ($read_out->strand == -1) {
640
my ($length) = $read_out->length();
641
$length = $length - &_nof_gaps($list_out,$length);
642
$query = $length - $query + 1;
646
(defined($read_in) && ($type_in =~ /^unaligned /) &&
647
defined($read_out) && ($type_out =~ /^aligned /)) && do {
648
my $list_in = $self->{'_elem'}{$in_ID}{'_gaps'};
649
# Changing read orientation if read was reverse complemented when aligned
650
if ($read_in->strand == -1) {
651
my ($length) = $read_in->length();
652
$length = $length - &_nof_gaps($list_in,$length);
653
$query = $length - $query + 1;
655
$query = &_unpadded_padded($list_in,$query);
656
if ($read_in ne $read_out) {
657
$query = $self->change_coord("aligned $in_ID",'gapped consensus',$query);
658
$query = $self->change_coord('gapped consensus',"aligned $out_ID",$query);
663
# Transformations between seq $read_in unpadded and seq $read_out unpadded
664
(defined($read_in) && ($type_in =~ /^unaligned /) &&
665
defined($read_out) && ($type_out =~ /^unaligned /)) && do {
666
$query = $self->change_coord("unaligned $in_ID","aligned $out_ID",$query);
667
$query = $self->change_coord("aligned $out_ID","unaligned $out_ID",$query);
671
# Transformations between contig (padded) and read (unpadded)
672
(($type_in eq 'gapped consensus') &&
673
($type_out =~ /^unaligned /) && defined($read_out)) && do {
674
$query = $self->change_coord('gapped consensus',"aligned $out_ID",$query);
675
$query = $self->change_coord("aligned $out_ID","unaligned $out_ID",$query);
678
(($type_in =~ /^unaligned /) && defined($read_in) &&
679
($type_out eq 'gapped consensus')) && do {
680
$query = $self->change_coord("unaligned $in_ID","aligned $in_ID",$query);
681
$query = $self->change_coord("aligned $in_ID",'gapped consensus',$query);
685
# Transformations between contig (unpadded) and read (unpadded)
686
(($type_in eq 'ungapped consensus') &&
687
($type_out =~ /^unaligned /) && defined($read_out)) && do {
688
$query = $self->change_coord('ungapped consensus','gapped consensus',$query);
689
$query = $self->change_coord('gapped consensus',"unaligned $out_ID",$query);
692
(($type_in =~ /^unaligned /) && defined($read_in) &&
693
($type_out eq 'ungapped consensus')) && do {
694
$query = $self->change_coord("unaligned $in_ID",'gapped consensus',$query);
695
$query = $self->change_coord('gapped consensus','ungapped consensus',$query);
699
$self->throw("Unknow coordinate system. Args: $type_in, $type_out.");
700
$query = undef; # If a coordinate systems just requested is unknown
1079
1112
my $seq = shift;
1081
1114
if( !ref $seq || ! $seq->isa('Bio::LocatableSeq') ) {
1082
$self->throw("Unable to process non locatable sequences [", ref($seq), "]");
1115
$self->throw("Unable to process non locatable sequences [".ref($seq)."]");
1085
1118
my $seqID = $seq->id() || $seq->display_id || $seq->primary_id;
1086
$self->{'_elem'}{$seqID} = {} unless (exists $self->{'elem'}{$seqID});
1119
$self->{'_elem'}{$seqID} = {} unless (exists $self->{'_elem'}{$seqID});
1088
1121
if (exists( $self->{'_elem'}{$seqID}{'_seq'} ) &&
1089
($seq eq $self->{'_elem'}{$seqID}{'_seq'}) ) {
1090
$self->warn("Adding sequence $seqID, which has already been added");
1122
($seq eq $self->{'_elem'}{$seqID}{'_seq'}) ) {
1123
$self->warn("Adding sequence $seqID, which has already been added");
1093
1126
# Our locatable sequences are always considered to be complete sequences
1094
$seq->start(1); $seq->end($seq->length());
1128
$seq->end($seq->_ungapped_len);
1096
1130
$self->warn("Adding non-nucleotidic sequence ".$seqID)
1097
if (lc($seq->alphabet) ne 'dna' && lc($seq->alphabet) ne 'rna');
1131
if (lc($seq->alphabet) ne 'dna' && lc($seq->alphabet) ne 'rna');
1099
1133
# build the symbol list for this sequence,
1100
1134
# will prune out the gap and missing/match chars
1101
1135
# when actually asked for the symbol list in the
1103
1137
if (defined $seq->seq) {
1104
map { $self->{'_symbols'}->{$_} = 1; } split(//,$seq->seq);
1138
map { $self->{'_symbols'}->{$_} = 1; } split(//,$seq->seq);
1106
$self->{'_symbols'} = {};
1140
$self->{'_symbols'} = {};
1109
1143
my $seq_no = ++$self->{'_nof_seqs'};
1111
1145
if (ref( $self->{'_elem'}{$seqID}{'_seq'} )) {
1112
$self->warn("Replacing one sequence [$seqID]\n");
1146
$self->warn("Replacing one sequence [$seqID]\n");
1114
#print STDERR "Assigning $seqID to $order\n";
1115
$self->{'_order'}->{$seq_no} = $seqID;
1116
# $self->{'_start_end_lists'}->{$id} = []
1117
# unless(exists $self->{'_start_end_lists'}->{$id});
1118
# push @{$self->{'_start_end_lists'}->{$id}}, $seq;
1148
#print STDERR "Assigning $seqID to $order\n";
1149
$self->{'_order'}->{$seq_no} = $seqID;
1150
# $self->{'_start_end_lists'}->{$id} = []
1151
# unless(exists $self->{'_start_end_lists'}->{$id});
1152
# push @{$self->{'_start_end_lists'}->{$id}}, $seq;
1121
1155
$self->{'_elem'}{$seqID}{'_seq'} = $seq;