#! /usr/bin/perl -w use strict; #Script to return the percentage of each well's cell population BELOW the supplied threshold for P-S780RB1 per well as well as the mean value for nuclear antibody intensity per well. #Settings are intended for reading data from Nuclei.csv as generated using the 3_channels_pipeline.cppipe file in conjunction with Cell Profiler. sub get_line { print $_[0]; chomp (my $line = ); $line; } #Define 96 well plate addresses in @plate A1-H12 my (@column, @row, @plate, $addr, $row, $column); @column = qw (1 2 3 4 5 6 7 8 9 10 11 12); @row = qw (A B C D E F G H); foreach $column (@column) { foreach $row (@row) { $addr = ("$row"."$column"); push (@plate, $addr); } } #Get user input via questionnaire my ($source, $dest, $threshold); if ($#ARGV == 2) { $source = $ARGV[0]; open IN, $source or die "Can't open '$source' for input: $!"; $dest = $ARGV[1]; die "Won't overwrite existing file" if -e $dest; open OUT, ">>$dest" #append destination file or die "Can't open '$dest' for output: $!"; $threshold = $ARGV[2]; } else { $source = &get_line("Which source file? "); open IN, $source or die "Can't open '$source' for input: $!"; $dest = &get_line("Which destination file? "); die "Won't overwrite existing file" if -e $dest; open OUT, ">>$dest" #append destination file or die "Can't open '$dest' for output: $!"; $threshold = &get_line("What threshold for hypo-P-S780 RB?: "); } # Read each line corresponding to each well address in turn and output a single line of summarized data for each well in the output file. my ($well); print OUT "Threshold\: $threshold\n"; print OUT "Well,Total Count,Threshold Passed,Percent Hypo-P,Mean Ab Intensity\n"; foreach $well (@plate) { seek(IN, 0, 0); my ($tcount, $gated, $found, $accum); while () { if (/^\d{1,4},\d{1,4},Red,Blue,Green,\d{1,2},($well),[0-9]+,[A-H],\d{1,4},\d*.\d*,\d*.\d*,(\d*.\d*),\d*.\d*\r*\n/) { #refer to notes in 2gate_classifier.pl for modification guidelines for this regex line $tcount += 1; $accum += $2; if ($2 <= $threshold) { #NB MIN vs MAX gate adjusted here #gates applied here can use gt > lt < or equal to == symbols $gated += 1; } $found = 1; } } if (defined $found) { my $score = (($gated / $tcount) * 100); my $mean = ($accum / $tcount); print OUT "$well\,$tcount\,$gated\,$score\,$mean\n"; } } close IN; close OUT;