InSilicoSpectro::InSilico::RetentionTimer - A base class for implementing a peptide retention time predictor


InSilicoSpectro documentation Contained in the InSilicoSpectro distribution.

Index


Code Index:

NAME

Top

InSilicoSpectro::InSilico::RetentionTimer - A base class for implementing a peptide retention time predictor

SYNOPSIS

Top

  use InSilicoSpectro::InSilico::RetentionTimer;

  # create a retention time predictor
  my $rt = InSilicoSpectro::InSilico::RetentionTimer->new;

  # predict retention time for a peptide
  $rt->predict( peptide=>'ACFGDMKWVTFISLLRPLLFSSAYSRGVFRRDTHKSEIAHRFKDLGE' );

  # calibrate the predictor
  $rt->calibrate( data=>{calseqs=>\@calseqs,caltimes=>\@caltimes,calmodifs=>\@calmodifs},calibrator=>$ec );

DESCRIPTION

Top

InSilicoSpectro::InSilico::RetentionTimer is a base class for predictors of peptides retention time in HPLC. It gives also a method for calibration of the predictor.

FUNCTIONS

Top

count_aa()

This function counts the number of ocurrences of each amino acid in a given sequence and returns a reference to an array with the count sorted by the one-letter symbol: ACDEFGHIKLMNPQRSTVWY.

  my $count = count_aa( 'AAK' );
  print "Found $count[0] Alanines and $count[1] Cysteines\n";

METHODS

Top

my $rt=InSilicoSpectro::InSilico::RetentionTimer->new($h)

$h contains a hash with parameters.

$rt->predict($point)

Predict the retention time.

$rt->calibrate(%h)

Calibrate the predictor.

$rt->write_cal( calfile=>$file );

Save current calibrator.

$rt->read_cal ( calfile=>$file );

Retrieve a previously saved calibrator.

$rt->set($name, $val)

Set an instance parameter.

$rt->get($name)

Get an instance parameter.

EXAMPLES

Top

SEE ALSO

Top

InSilicoSpectro::InSilico::RetentionTime::Hodges

InSilicoSpectro::InSilico::RetentionTime::Petritis

InSilicoSpectro::InSilico::ExpCalibrator

InSilicoSpectro::InSilico::IsoelPoint

COPYRIGHT

Top

AUTHORS

Top

Pablo Carbonell, Alexandre Masselot, www.genebio.com


InSilicoSpectro documentation Contained in the InSilicoSpectro distribution.

use strict;

package InSilicoSpectro::InSilico::RetentionTimer;
require Exporter;
use Carp;
use File::Basename;

use InSilicoSpectro::InSilico::ExpCalibrator;


our (@ISA, @EXPORT, @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT = qw(&count_aa);
@EXPORT_OK = ();

sub new{
  my ($pkg,%h)=@_;# pkg: name of the module; h: hash with the rest of parameters
  my $rt={};# Create an empty reference
  bless $rt, $pkg;# Assign it to the object

# Setting of properties
  $rt->set('peptide','');# Peptide
  $rt->set('data',{expseqs=>[],exptimes=>[]});# Experimental data

  $rt->set('calfile','-');# default file

  $rt->set('filter',10); # Threshold (in %) for method filter()
  $rt->set('error','relative');

  $rt->set('calibrator',InSilicoSpectro::InSilico::ExpCalibrator->new(fitting=>'bypass',
							 expseqs=>[],expdata=>[],prdata=>[]));# new calibrator

  foreach (keys %h){ $rt->set($_, $h{$_}) }

  return $rt;
}

#-------------------------------- getters/setters

sub set{
  my ($this, $name, $val)=@_;
  if ((ref($val) eq 'HASH') and defined($this->{$name})) {# Add more fields to the hash
    $this->{$name}={%{$this->{$name}},%$val};
  } else {
    $this->{$name}=$val;
    }
}

sub get{
  my ($this, $n)=@_;
  return $this->{$n};
}

# -------------------------------   predict

sub predict {

  my ($this,$point)=@_;

  return $this->{calibrator}->fit($point);
}


sub count_aa {

  my ($seq)=@_;
  my %counter;
  my @aas=split '','ACDEFGHIKLMNPQRSTVWY';
  my @point;

  foreach (@aas) {
    $counter{$_}=0;
  }
  foreach (split '',$seq) {
    if (exists($counter{$_})) {
      $counter{$_}++;
    } else {
      carp "Coefficient for symbol $_ not defined. Discarding\n";
      }
  }

  foreach (@aas) {
    push(@point,$counter{$_});
  }
  return @point;
}

# -------------------------------   Filter data

sub filter {

 my ($this,$error)=@_;

 my @norder=(0..$#{$this->{data}{exptimes}});

 for(my $m=0;$m<=$#{$this->{data}{exptimes}};$m++) {
   if ($$error[$m]>(($this->{filter})*(($this->{error} eq 'relative') ? ($this->{data}{exptimes}[$m]/100) : 1))) {
     foreach (keys %{$this->{data}})
       {
	 splice(@{$this->{data}{$_}},$m,1);
       }
     splice(@$error,$m,1);
     splice(@norder,$m--,1);
   }
 }

 return \@norder;
}

# -------------------------------   calibrate

sub calibrate {

  my ($this,%h)=@_;
  foreach (keys %h) { $this->set($_, $h{$_}) }

  my (@prdata,@expdata,@expseqs,@sortaa,%indh,$k);

  $k=0;
  foreach (@{$this->{data}{prdata}}) { # Predicted cal. data with the predictor (before calibration)
     $indh{$k++}=$_;# Assign an index to each prediction
  }

  @sortaa= sort {$indh{$a} <=> $indh{$b}} keys %indh;# sort the indexes by predicted values

  foreach (@sortaa) {
    push(@prdata,$indh{$_});
    push(@expdata,${$this->{data}{caltimes}}[$_]);# populate arrays ordered by predicted values
   }

  $this->{calibrator}->train(expdata=>\@expdata,prdata=>\@prdata);
}

# -------------------------------   write / read xml file with the calibrated values

sub write_cal {

  my ($this,%h)=@_;
  foreach (keys %h) { $this->set($_, $h{$_}) }

  my $str='';
  my $k;

  $str.=$this->{calibrator}->write_xml(file=>$this->{calfile});


}

sub read_cal {

  my ($this,%h)=@_;
  foreach (keys %h) { $this->set($_, $h{$_}) }

  $this->{calibrator}->read_xml(file=>$this->{calfile});
  $this->{calibrator}->train;
}


# -------------------------------   misc
return 1;