InSilicoSpectro-Databanks

 view release on metacpan or  search on metacpan

lib/InSilicoSpectro/Databanks/DBEntryUniprot.pm  view on Meta::CPAN

    my $self=shift;
    my $shortName=shift;
    my @chains;
    my $i=0;
    foreach my $c (@{$self->chains()}) {
      my $cseq=$self->clone(1);
      $cseq->ACorig($self->AC());
      $cseq->AC($shortName ? $self->AC()."_C$i" : $self->AC()."_CHAIN_$i");
      $cseq->description($self->description()." [CHAIN $i]");
      $cseq->seqExtract(from=>$c->[0], to=>$c->[1]);
      $i++;
      push @chains, $cseq;
    }
    return @chains;
  }


  sub seqSubstr{
    my $self=shift;
    my %hprm=@_;
    my ($pos, $len, $substr);
    if ($hprm{from} && $hprm{to}) {
      $pos=$hprm{from}-1;
      $len=$hprm{to}-$hprm{from}+1;
    } elsif ((defined $hprm{pos}) && $hprm{len}) {
      ($pos, $len)=($hprm{pos}, $hprm{len});
    } else {
      croak "cannot DBEntryUniprot::seqSubstr with paramer [@_] (either (from=>x, to=>y) or (pos=>x, len=>y) for ".$self->AC;
    }
    $substr=$hprm{substr} || '';
    my $seq=$self->sequence;
    $pos|=0;
    $seq=~s/(.{$pos}).{$len}/$1$substr/;
    $self->sequence($seq);
    #CHANGE 2007/12/19
    $self->updateAnnotPos($pos, $len-length($substr));
  }


  sub seqExtract{
    my $self=shift;
    my %hprm=@_;
    my ($pos, $len, $substr);
    if ($hprm{from} && $hprm{to}) {
      $pos=$hprm{from}-1;
      $len=$hprm{to}-$hprm{from}+1;
    } elsif ((defined $hprm{pos}) && $hprm{len}) {
      ($pos, $len)=($hprm{pos}, $hprm{len});
    } else {
      croak "cannot DBEntryUniprot::seqSubstr with paramer [@_] (either (from=>x, to=>y) or (pos=>x, len=>y) for ".$self->AC;
    }
    my $lseq=length $self->sequence();
    if ($lseq>($pos+$len)) {
      $self->seqSubstr(from=>$pos+$len+1, to=>$lseq);
    }
    if ($pos>0) {
      $self->seqSubstr(from=>1, to =>$pos);
    }
  }

  sub updateAnnotPos{
    my ($self, $pos, $len)=@_;
    #shift or remove all annotated PTM
    my @amr=$self->annotatedModRes;
    if (@amr) {
      $self->clear_annotatedModRes;
      foreach (@amr) {
	my @tmp=@$_;
	my $p=$tmp[0];
	if ($p>=$pos) {
	  $tmp[0]-=$len;
	  $self->add_annotatedModRes(@tmp) if $tmp[0]>$pos;
	} else {
	  $self->add_annotatedModRes(@tmp);
	}
      }
    }
    @amr=$self->variants;
    if (@amr) {
      $self->clear_variants;
      foreach (@amr) {
	my @tmp=@$_;
	my $p=$tmp[0];
	if ($p>=$pos) {
	  $tmp[0]-=$len;
	  $self->add_variant(@tmp) if $tmp[0]>0;
	} else {
	  $self->add_variant(@tmp);
	}
      }
    }
  }

}
return 1;



( run in 0.325 second using v1.01-cache-2.11-cpan-bbe5e583499 )