Advertisement
dsuveges

FPLC_parser.pl

Aug 10th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.07 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # This program was written to parse FPLC files.
  4. # One FPLC run can contain multiple runs, where the first injection starts the timer
  5. # Then the timer goes on util hitting END.
  6. # Upon exporting the trace, the time of all injections are saved in the third column.
  7. # This program creates a list, where the first column is the elution volume
  8. # Subsequent columns are the traces of different injections.
  9.  
  10. # usage:
  11.     # >FPLC_Parser_v1.1.pl <INFILE> > <OUTFILE>
  12.     # Infile is the exported ASCII format generatd by Unicorn software.
  13.     # Output is a list where the first column is the time (in minutes), the outher columns are the absorbance values of
  14.     # Each injections (in mAU units).
  15.  
  16. # v 1.1 2013.07.05
  17.     # Code optimization
  18.     # Commenting
  19.  
  20. # v. 1.0 2012.11.17
  21.     # All functionality is implemented - At first all datapoints are collected,
  22.     # then the serie is brokend down to pieses corresponding each injections.
  23.     # the input and output secification is quite low-end, but works just fine.
  24.  
  25. ##### Comment about the algorytm ##############################################
  26. ## It might sounds reasonable to do the splitting on the flight, but that may cause dataloss:
  27. ## You can start the next run before finishing the datacollection of the previous run
  28. ## This is possible, as you can count on the void volume of the colunms
  29. ###############################################################################
  30.  
  31.  
  32.  
  33. use warnings;
  34. use strict;
  35.    
  36. my @injections  = (); # An array with injection times.
  37. my %trace       = (); # This variable will filled by all values!
  38.  
  39. foreach (<>){
  40.  
  41.     # discard header lines
  42.     if ($_ =~ /^\S/){ next }
  43.    
  44.     # collect injection times. (Carefully, as those lines have absorbance values as well!)
  45.     if ($_ =~ /\s+(\d+\.\d+)\s+([-]*\d+\.\d+)\s+(\d+\.\d+)/){
  46.        
  47.         # $1 - Time
  48.         # $2 - Absorbance
  49.         # $3 - Time of injections.
  50.         push (@injections, $3);
  51.         $trace{$1} = $2;    
  52.     }
  53.  
  54.     # Collect data points.
  55.     if ($_ =~ /\s+(\d+\.\d+)\s+([-]*\d+\.\d+)/){
  56.        
  57.         # $1 - Time
  58.         # $2 - Absorbance
  59.         $trace{$1} = $2;    
  60.     }
  61.    
  62. }
  63.  
  64. # Calculate run length - As injections are started manually, the length can vary.
  65. # To make it sure that all split will contain the sufficient amount of data,
  66. # At first the length of the longest run is collected.
  67. my $runlength = &RunLength(@injections);
  68.  
  69. # Submit collected data to parser (trace, injections, run length)
  70. &Parse(\@injections,\%trace,$runlength);
  71.  
  72. # Spliting
  73. sub Parse {
  74.  
  75.     # Loading variables.
  76.     my @injection   = @{$_[0]};
  77.     my %trace       = %{$_[1]};
  78.     my $runlength   = $_[2];
  79.     my @table       = ();
  80.    
  81.     # Walking through the trace.
  82.     foreach my $timepoints (sort {$a <=> $b} keys %trace){
  83.         # print "$timepoints\t$trace{$timepoints}\n"
  84.         for ( my $i = "0"; $i < scalar(@injection); $i ++){
  85.             if (($timepoints >= $injections[$i]) and ($timepoints < $injections[$i] + $runlength)){
  86.                 push (@{$table[$i]}, $trace{$timepoints});
  87.             }
  88.         }
  89.     }
  90.    
  91.     my @TimeSteps   = sort {$a <=> $b} keys(%trace);
  92.    
  93.     for (my $timestep = 0;  $TimeSteps[$timestep] < $runlength; $timestep ++){
  94.         print "$TimeSteps[$timestep]\t";
  95.        
  96.         for (my $injection = "0"; $injection < scalar(@table); $injection ++){
  97.             if (${$table[$injection]}[$timestep]){
  98.                 print "${$table[$injection]}[$timestep]\t";
  99.             }
  100.             else {
  101.                 print "\t";
  102.             }
  103.         }
  104.        
  105.         print "\n";
  106.     }
  107. }
  108.  
  109. # Calculate the legth of a run
  110. sub RunLength {
  111.     # get list of injections
  112.     my @injections = @_;
  113.    
  114.     # Calculate time difference between each injection
  115.     my $maxtime = "0";
  116.    
  117.     for (my $i = "0"; $i < scalar (@injections) - 1; $i++){
  118.         if ($injections[$i+1] - $injections[$i] > $maxtime){
  119.             $maxtime = $injections[$i+1] - $injections[$i];
  120.         }
  121.     }
  122.    
  123.     # Return with the longest distance.
  124.     return $maxtime;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement