Sponsored Content
Top Forums Shell Programming and Scripting Need help comparing Base Pairs within PERL Post 302659765 by drossy on Thursday 21st of June 2012 11:22:30 AM
Old 06-21-2012
Okay I now have a new specification that I would like to add to my program.
Given this is the original file and corresponding program:
Code:
 
Non-ref      "A"     "A1"    "A2" ....... (column6)
A               AT      5       15            INTRONIC

Code:
 
#!/usr/bin/perl
use strict;
use warnings;
#initialize data
my(@data,$row,@dataline,$dnafile);
#open file to be read or quit
open(FILE1,"<",'file.txt')or die $!;
#initialize counts of variables
my $countExonic=0;
my $countIntergenic=0;
my $countIntronic=0;
my $countUpstream=0;
my $countDownstream=0;
my $countUTR5=0;
my $countUTR3=0;
my $countFrameshift=0;
my $countNonsynonymous=0;
my $countSyn=0;
my $countStopgain=0;
my $countStoploss=0;
my $countSplicing=0;
my $countErrors=0;
#set data equal to the previously opened file
@data=<FILE1>;close(FILE1);
#loop to grep rows of file that have genotype that matches non-ref allele
#$dataline[1] is genotype, $dataline[0] is non-ref allele, $dataline[7] is
#mutation type
#selects for ratio above .5
#the number for each type of mutation occurring in the grepped data is recorded
foreach $row(@data) {
        next unless $row=~/^\d/;
        @dataline=split(/\s+/,$row);
        next unless $dataline[1] ne "NA";
        next unless $dataline[1]=~/$dataline[0]/i;
        next unless $dataline[2]>=10;
        next unless $dataline[2]/$dataline[3]>=.5;
        if($dataline[7] =~ /exonic/){
                ++$countExonic;
        }elsif($dataline[7]=~/inter/){
                ++$countIntergenic;
        }elsif($dataline[7]=~/intron/){
  ++$countIntronic;
        }elsif($dataline[7]=~/upstream/){
                ++$countUpstream;
        }elsif($dataline[7]=~/downstream/){
                ++$countDownstream;
        }elsif($dataline[7]=~/UTR5/){
                ++$countUTR5;
        }elsif($dataline[7]=~/UTR3/){
                ++$countUTR3;
        }elsif($dataline[7]=~/frame/){
                ++$countFrameshift;
        }elsif($dataline[7]=~/nonsyn/){
                ++$countNonsynonymous;
        }elsif($dataline[7]=~/syn/){
                ++$countSyn;
        }elsif($dataline[7]=~/gain/){
                ++$countStopgain;
        }elsif($dataline[7]=~/loss/){
                ++$countStoploss;
        }elsif($dataline[7]=~/splic/){
                ++$countSplicing;
        }else{++$countErrors;
        }
}
#print out results of mutation counts
print "nc_RNA Exonic Mutations=$countExonic\n\n";
print "Intergenic Mutations=$countIntergenic\n\n";
print "Intronic Mutations=$countIntronic\n\n";
print "Upstream Mutations=$countUpstream\n\n";
print "Downstream Mutations=$countDownstream\n\n";
print "UTR5 Mutations=$countUTR5\n\n";
print "UTR3 Mutations=$countUTR3\n\n";
print "Frameshift Mutations=$countFrameshift\n\n";
print "Nonsynonymous Mutations=$countNonsynonymous\n\n";
print "Synonymous Mutations=$countSyn\n\n";
print "Stop Gain Mutations=$countStopgain\n\n";
print "Stop Loss Mutations=$countStoploss\n\n";
print "Splicing Mutations=$countSplicing\n\n";
print "Others=$countErrors\n\n";
exit;

And say the new file being read is as follows:

Code:
 
Non-ref           "A"      "A1"       "A2"          "B"          "B1"         "B2"      
A                   AT       5            15          AA           13           14

I want to be able to select either the column of "A" or "B" to be performed on depending on what i type in on the command line.
In other words the original code:
Code:
 
next unless $dataline[1] ne "NA";
next unless $dataline[1]=~/$dataline[0]/i;
next unless $dataline[2]>=10;
next unless $dataline[2]/$dataline[3]>=.5;

Should change so that [1] is instead the column of "A" or "B' depending on the input, and [2] is "A"+1 or "B"+1 and [3] is "A"+2 or "B"+2


Hope that is clear and thanks for the help!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl search and replace pairs

Hello all im facing some kind of problem i have this string : functionA() $" "$ functionB("arg1") $" = "$ i will like to replace all the pairs of opening and closing "$" to be something like that functionA() <#" "#> functionB("arg1") <#" = "#> i cant of course do is with simple ... (1 Reply)
Discussion started by: umen
1 Replies

2. Shell Programming and Scripting

Comparing Variables in Perl

Hi. I have three arrays. @a=('AB','CD','EF'); @b=('AB,'DG',HK'); @c=('DD','TT','MM'); I want to compare the elements of the first two array and if they match then so some substition. I tried using the if statement using the scalar value of the array but its not giving me any output. ... (7 Replies)
Discussion started by: kamitsin
7 Replies

3. Shell Programming and Scripting

Comparing arrays in perl

Hi all, I am trying to compare two arrays in perl using the following code. foreach $item (@arrayA){ push(@arrayC, $item) unless grep(/$item/, @arrayB); ... (1 Reply)
Discussion started by: chriss_58
1 Replies

4. Shell Programming and Scripting

PERL name value pairs substituions

I have a main file with variable tokens like this: name: File1 =========== Destination/Company=@deploy.company@ Destination/Environment=@deploy.env@ Destination/Location=@deploy.location@ Destination/Domain=@deploy.location@ MIG_GatewayAddresses=@deploy.gwaddress@ MIG_URL=@deploy.mig_url@... (1 Reply)
Discussion started by: uandme2k2
1 Replies

5. Shell Programming and Scripting

comparing list values in Perl

Hi, I have tab separated list: KB0005 1019 T IFVATVPVI 0.691 PKC YES KB0005 1036 T YFLQTSQQL 0.785 PKC YES KB0005 1037 S FLQTSQQLK 0.585 DNAPK YES KB0005 508 S ENIISGVSY 0.507 cdc2 YES KB0005 511 S ... (1 Reply)
Discussion started by: karla
1 Replies

6. Shell Programming and Scripting

PERL: simple comparing arrays question

Hi there, i have been trying different methods and i wonder if somebody could explain to me how i would perform a comparison on two arrays for example my @array1 = ("gary" ,"peter", "paul"); my @array2 = ("gary" ,"peter", "joe"); I have two arrays above, and i want to something like this... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

7. Shell Programming and Scripting

Perl: Comparing to two files and displaying the differences

Hi, I'm new to perl and i have to write a perl script that will compare to log/txt files and display the differences. Unfortunately I'm not allowed to use any complied binaries or applications like diff or comm. So far i've across a code like this: use strict; use warnings; my $list1;... (2 Replies)
Discussion started by: dont_be_hasty
2 Replies

8. Shell Programming and Scripting

Perl: Need help comparing huge files

What do i need to do have the below perl program load 205 million record files into the hash. It currently works on smaller files, but not working on huge files. Any idea what i need to do to modify to make it work with huge files: #!/usr/bin/perl $ot1=$ARGV; $ot2=$ARGV; open(mfileot1,... (12 Replies)
Discussion started by: mrn6430
12 Replies

9. Shell Programming and Scripting

Need help in comparing two files using shell or Perl

I have these two file that I am trying to compare using shell arrays. I need to find out the changed or the missing enteries from File2. For example. The line "f nsd1" in file2 is different from file1 and the line "g nsd6" is missing from file2. I dont want to use "for loop" because my files... (2 Replies)
Discussion started by: sags007_99
2 Replies

10. Shell Programming and Scripting

Perl for comparing numbers from previous lines in a file?

Hi everyone I have a question for you, as I am trying to learn more about Perl and work with some weather data. I have an ascii file (shown below) that has 10 lines with different columns. What I would like is have Perl find an "anomalous" value by comparing a field with the values from the last... (2 Replies)
Discussion started by: lucshi09
2 Replies
All times are GMT -4. The time now is 04:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy