Sponsored Content
Top Forums Shell Programming and Scripting Need help comparing Base Pairs within PERL Post 302654197 by drossy on Monday 11th of June 2012 11:05:20 AM
Old 06-11-2012
Hi I am now facing two current issues when trying to expand this program. Ddreggors you have been wonderful so far and I am hoping you can help me with these issues.

The first is that for some of the data, the genotype is not available and is given as "NA" in the file. Thus when the reference allele is "A", the program wrongly assumes that the criteria is met, and this row is given in the output. Is there anyway for me to specify that for genotype = "NA", skip on to the next row?

Secondly I would like to attach the following on to the end of the program so that the number of each mutation is recorded:

Code:
 
#!/usr/bin/perl
#Ask user for file that is to be read
print "please type name of file: ";
$dnafile = <>;
#Remove the newline from the dna file name
chomp $dnafile;
#Open the file or exit
unless (open(DNAFILE, $dnafile)){
         print  "can't open file \"$dnafile\"\n\n";
        exit;
}
#store dna information
@dna = <DNAFILE>;
#close now read file
close DNAFILE;
#turn array into single string
$dna = join('', @dna);
#get rid of blank spaces
$dna =~ s/\s//g;
#initialize mutation counts
$countExonic = 0;
$countIntergenic = 0;
$countIntronic = 0;
$countUpstream = 0;
$countDownstream = 0;
$countUTR5 = 0;
$countUTR3 = 0;
$countFrameshift = 0;
$countNonsynonomous = 0;
$countSyn = 0;
$countStopgain = 0;
$countStoploss = 0;
$countSplicing = 0;
$countErrors = 0;
#create loop to search for mutations
foreach (@dna) {
        if ( /exonic/ ) {
                ++$countExonic;
        } elsif ( /inter/ ){
                ++$countIntergenic;
        } elsif ( /intron/ ){
                ++$countIntronic;
        } elsif ( /upstream/ ){
                ++$countUpstream;
        } elsif ( /downstream/ ){
                ++$countDownstream;
        } elsif ( /UTR5/ ) {
                ++$countUTR5;
        } elsif ( /UTR3/ ){
                ++$countUTR3;
        } elsif ( /frame/ ){
                ++$countFrameshift;
        } elsif ( /nonsyn/ ){
                ++$countNonsynonomous;
        } elsif ( /syn/ ) {
                ++$countSyn;
        } elsif ( /gain/ ) {
                ++$countStopgain;
        } elsif ( /loss/ ) {
                ++$countStoploss;
        } elsif ( /splic/ ) {
                ++$countSplicing;
        } else  {++$countErrors;
        }
}
#print out results
print "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 "Nonsynonomous Mutations = $countNonsynonomous\n\n";
print "Sysnonomous 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 the program
exit;

However, this does not seem to be working simply by saving the output of the first part of the program into a file and opening that file again for the second part. Any help would be greatly appreciated.
Thanks a lot,
Drossy
 

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
Perl::Critic::Policy::ControlStructures::ProhibitCascadiUserEContributed PerlPerl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse(3pm)

NAME
Perl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse - Don't write long "if-elsif-elsif-elsif-elsif...else" chains. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Long "if-elsif" chains are hard to digest, especially if they are longer than a single page or screen. If testing for equality, use a hash lookup instead. If you're using perl 5.10 or later, use "given"/"when". if ($condition1) { #ok $foo = 1; } elsif ($condition2) { #ok $foo = 2; } elsif ($condition3) { #ok $foo = 3; } elsif ($condition4) { #too many! $foo = 4; } else { #ok $foo = $default; } CONFIGURATION
This policy can be configured with a maximum number of "elsif" alternatives to allow. The default is 2. This can be specified via a "max_elsif" item in the .perlcriticrc file: [ControlStructures::ProhibitCascadingIfElse] max_elsif = 3 AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.14.2 2012-06-0Perl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse(3pm)
All times are GMT -4. The time now is 07:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy