Advertisement
dsuveges

Kinetic parser.pl

Jul 1st, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.67 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # Program to parse kinetic data produced by the plate reader at Couchin lab.
  4. # The data structure is not complicated, but almost impossible to extract data manually:
  5. # one line contains all data for the 96 wells in each time step.
  6. # What the program does is to collect the absorbance value correspondig to each well for each timestep and makes a table
  7.  
  8.  
  9. # Usage:
  10. # $./Kinetic_parser.pl <Infile> >Outfile
  11.  
  12. # (c) Daniel Suveges
  13.  
  14. # v 1.0 2011.09.30
  15.     # Very primitive form, but works anyway
  16.  
  17. # v 2.0 2011.10.04
  18.     # Trained to get all possible 96 well data, but returns only those that actually filled
  19.     # Cleaning input data is not required
  20.  
  21. # v 2.5 2013.06.28
  22.     # An error is fixed: real labeling of the wells.
  23.     # Deals with multiple experiments!!!
  24.     # Time format is in minutes with decimal values instead of the min:sec format
  25.  
  26. our $version    = "2.5";
  27.    
  28. use strict;
  29. use warnings;
  30.  
  31.  
  32. my @lines       = ();
  33. our %AllData    = ();
  34. my @time        = ();
  35.  
  36. # REadin the files line by line
  37. foreach (<>){
  38.     # A line can be separeted by \r or \n
  39.     push(@lines,split(/[\r\n+]/,$_));
  40. }
  41.  
  42. my $lineNo  = "";
  43. my $time    = "";
  44.  
  45. foreach my $line (@lines){
  46.     # print "$line!!\n";
  47.     # my $time    = "";
  48.     if ($line =~ /(\d+\:\d+)\t([\d\.]+)([\d\.\t]+)/){
  49.         $lineNo = "0";
  50.         &row($lineNo,$3);
  51.  
  52.         my ($min, $sec) = split(/:/,$1);
  53.         $time    = $min + (int($sec / 0.6)/100);
  54.         push (@time, $time);
  55.     }
  56.     elsif ($line =~ /^\t([\d\t\.]+\d)/){
  57.         $lineNo ++;
  58.         &row($lineNo,$1);
  59.     }
  60.     else {
  61.         next;
  62.     }
  63.  
  64. }
  65.  
  66. print "Time\t";
  67. my @keys    = keys %AllData;
  68. foreach my $keys (@keys){
  69.     print "$keys\t"
  70. }
  71. print "\n";
  72.  
  73. for ( my $i = 0; $i < scalar @{$AllData{$keys[0]}}; $i++){
  74.     print "$time[$i]\t";
  75.     foreach my $keys (keys %AllData){
  76.         print "${$AllData{$keys}}[$i]\t";
  77.    
  78.     }
  79.     print "\n";
  80.  
  81. }
  82.  
  83. # parsing a row of the outputfile
  84. sub row {
  85.     my $LineNo  = $_[0];
  86.     my $line    = $_[1];
  87.    
  88.     my @stuff   = split(/\t/, $line);
  89.     my @letters = qw(A B C D E F G H);
  90.  
  91.     # Reading all lines. Every line is a timestep with data correspondig to all 96 well
  92.     for( my $index = "0"; $index <= scalar (@stuff); $index++){
  93.  
  94.         # If the element is exists, let's see which well is it?.
  95.         if($stuff[$index]){
  96.            
  97.             #Find the position in the plate
  98.               # Find the row (A-H)
  99.               my $row = $letters[int($index/12)];
  100.               # Find the column (1-12)
  101.               my $column = $index % 12;
  102.            
  103.             push(@{$AllData{$row.$column}},$stuff[$index]);
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement