#!/usr/bin/perl -w #1_copy_both_spp.pl use strict; use warnings; ##NB: To run this script on the file my_orthomcl_dir/groups.txt, specify it when runniong the script to add it to the @AGRV array die "usage: 1_copy_both_spp.pl \n" if (@ARGV!=1);##if a file is not specified in the beginning, it will die print "Processing file $ARGV[0]\n"; ##counting groups that have a single copy in both spp my $bothspp=0; my $outfile ="1_copy_both_spp_output.txt";##provides the groups with the protein accession number and counts my $outfile2 ="1_copy_both_spp_data.txt";##just numbers to make analysis easy open (my $out, ">$outfile") or die ("Problem with opening $outfile: $!");##open the file or the program dies open (my $out2, ">$outfile2") or die ("Problem with opening $outfile2: $!"); print $out2 "# of total proteins, cct proteins and ppb proteins in each group\n";##giving this a label while (my $line=<>){##takes a look at each line of the groups.txt next unless($line=~m/group\d{1,4}\:\scct\|\S{38}\d{4,7}\S{1}\d{4,7}\S{1}\d{1}\sppb\|/);##looks at lines that include only the one cct and the one ppb pattern $bothspp++;##add a count each time there is a line that matches above parameter my $count+= ()=($line =~ m/\|/g);#counts the number of proteins in each line my $cct+= ()=($line =~ m/cct/g);# counts the number of cct proteins in each line my $ppb+= ()=($line =~ m/ppb/g);# counts the number of ppb proteins in each line print $out "$line \($count proteins total, $cct cct protein, $ppb ppb protein\)\n";#prints to the outfile the entire line (includes group number and proteins involved) and the number of proteins print $out2 "$count $cct $ppb\n";##prints only the counts of the number of proteins in each group to a file } print "There are $bothspp groups of protein families that contain a single copy in both spp\n";#provides terminal output for the overall number of groups with 1 copy of both spp close($out); ##output "There are 1465 groups of protein families that contain a single copy in both spp.