Off topic:Find The Match Entries In The Columns And Print Them Out By Perl
1
0
Entering edit mode
12.1 years ago
Ar Es ▴ 20

Hi, I have asked this question before , but as Admin said If i want to change my question , I have to ask new question instead of asking by answering the previous one, Anyhow, my question is :

I want to read through 2 different tab-delimited files of sequence coordinates and find the same columns entries in both files and print it out , one file is ref and the other one contains the the columns that I want to find in the ref file : I want to keep col1 - col2 and col3 of file one (ref file) and col1 - col2 - col 3 of file2

file one (ref file) :

Col1      Col2       Col3     Col4  Col5 ColX
chr        start       end    (rest columns)


file2 :

Col1      Col2       Col3     Col4  Col5 ColX
chr        start       end    (rest columns)

I have written script but I got error when i print it out :

Use of uninitialized value $line2 in split at ./match3.pl line 19, <$fh2> line 2458. Use of uninitialized value in string eq at ./match3.pl line 22, <$fh2> line 2458. Use of uninitialized value in string eq at ./match3.pl line 22, <$fh2> line 2458. Use of uninitialized value in string eq at ./match3.pl line 22, <$fh2> line 2458. Use of uninitialized value in string eq at ./match3.pl line 22, <$fh2> line 2458. Use of uninitialized value in string eq at ./match3.pl line 22, <$fh2> line 2458. Use of uninitialized value in string eq at ./match3.pl line 22, <$fh2> line 2458. Use of uninitialized value $values2[0] in concatenation (.) or string at ./match3.pl line 22, <$fh2> line 2458. Use of uninitialized value in concatenation (.) or string at ./match3.pl line 22, <$fh2> line 2458. Use of uninitialized value in concatenation (.) or string at ./match3.pl line 22, <$fh2> line 2458.

my script is :

#!/usr/bin/perl
use strict;
use warnings;

open my $fh1, '<', 'file1';
open my $fh2, '<', 'file2';

my$line1 ;
my$line2 ;

while (<$fh1>) {
  chomp;
  my @values1 = split( "\t", $line1 );
  close $fh1;
  while (<$fh2>) {
  chomp;
    my @values2 = split( "\t", $line2 );
close $fh2; 

if ( $values1[0] eq $values2[0] and $values1[1] eq $values2[1] and $values1[2] eq $values2[2])

{
  print "$values2[0] \t $values2[1] \t $values2[2] \t \n" ;}}}

Thanks In Advance,

comparison perl • 7.0k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 2441 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6