Nathalie Conte wrote:

Hi,

Hello,

I am lost in my script, and would need to basic help please.
I have got a file , separated by tabs, and the first column contain a
chromosome number, then several other column with different infos.
Basically I am trying to created a script that would take a file(see
example), parse line by line, and when the first column start by any of
the chromosomes I don't want (6,8,14,16,18,Y), go the next line, and if
it doesn't start by the bad chromosomes , print all the line to a new
output file.
the script below, just reprint the same original file :(
thanks for any clues
Nat



#!/software/bin/perl
use warnings;
use strict;
open(IN, "<example.txt") or die( $! );
open(OUT, ">>removed.txt") or die( $! );
my @bad_chromosome=(6,8,14,16,18,Y);
while(<IN>){
chomp;
my @column=split /\t/;
foreach my $chr_no(@bad_chromosome){
if ($column[0]==$chr_no){
next;
}
}
print OUT
$column[0],"\t",$column[1],"\t",$column[2],"/",$column[3],"\t",$column[4],"\t",$column[5],"\t",$column[6],"\t",$column[7],"\t",$column[8],"\t",$column[9],"\t",$column[10],"\t",$column[11],"\t",$column[12],"\t",$column[13],"\t",$column[14],"\n";

}

close IN; close OUT;


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

open my $IN, '<', 'example.txt' or die "Cannot open 'example.txt' because: $!"; open my $OUT, '>>', 'removed.txt' or die "Cannot open 'removed.txt' because: $!";

my $bad_chromosomes = qr/^(?:6|8|14|16|18|Y)\t/;

while ( <$IN> ) {
    print $OUT $_ if !/$bad_chromosomes/;
    }

close $IN;
close $OUT;



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to