Sponsored Content
Top Forums Shell Programming and Scripting Need help comparing Base Pairs within PERL Post 302652165 by ddreggors on Thursday 7th of June 2012 09:24:38 AM
Old 06-07-2012
I found the issue.
See my above comment... I updated it to show what I did.

---------- Post updated at 04:09 PM ---------- Previous update was at 03:31 PM ----------

Actually, now that we have solved the original code... there is a better way to do this.
Here is a way smaller piece code that removes the need for second array (@ref) and I nest the loops.

Code:
#!/usr/bin/perl


use strict;
use warnings;
my (@data, $tmpidx, $tmpref);
open(FILE1,"<","file1.txt") or die $!;
while (<FILE1>) {
        chomp;
        next unless $_ =~ /^\d/;
        @data =  split(/\s+/,$_);
        open(FILE2,"<","file2.txt") or die $!;
        while (<FILE2>) {
                /^(\d*)\s*([a-z]*)/i;
                $tmpidx = $1;
                $tmpref = $2;
                next unless $_ =~ /^\d/;
                next unless $data[0] == $tmpidx;
                next unless $data[87] =~ /$tmpref/i;
                print $data[0] . "\t" . $data[5] . "\t" . $data[87] . "\n";
        }
        close FILE2;
}
close FILE1;


Result:
Code:
[user@host ~]$ ./test3.pl    
4       Exonic  AA
5       Intronic        GC

---------- Post updated 06-07-12 at 09:24 AM ---------- Previous update was 06-06-12 at 04:09 PM ----------

OK, after a bit more tweaking, here is the smallest and cleanest I could get the code.


Code:
#!/usr/bin/perl

use strict;
use warnings;
my (@ref, @data, $refidx, $ref, $row, @dataline, $refline);
open(FILE1,"<","file1.txt") or die $!; @data = <FILE1>; close(FILE1);
open(FILE2,"<","file2.txt") or die $!; @ref = <FILE2>; close(FILE2);
foreach $row (@data) {
        next unless $row =~ /^\d/;
        foreach $refline (@ref) {
                next unless $refline =~ /^\d/;
                ($refidx, $ref) = split('\s*', $refline);
                @dataline = split('\s',$row);
                next unless $dataline[0] == $refidx;
                next unless $dataline[87] =~ /$ref/i;
                print $dataline[0] . "\t" . $dataline[5] . "\t" . $dataline[87] . "\n";
        }
}

It weighs in at 18 lines, the files are read into arrays and closed immediately.
This User Gave Thanks to ddreggors For This Post:
 

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
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 08:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy