CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [GeneticsGirl] Help outputting first and last positions of blocks of the same type: Edit Log



wickedxter
User

Aug 24, 2012, 2:24 AM


Views: 3348
Re: [GeneticsGirl] Help outputting first and last positions of blocks of the same type

This might help get you closer its not where it should be but close.


Code
use strict; 
use warnings;

my $new_data;
my $counter = 1;
my $class_watch;
my $inbetween = 1;

my $line_before;

while (<DATA>){
chomp;
my ($chrom_pos, $all1, $all2, $class) = split /\s/;

#if the class changes save the $chrom_pos and the line before
if($class ne $class_watch ){

$new_data .= "$chrom_pos\n" if $inbetween <= 2;
$new_data .= "$line_before \n" if $inbetween > 1;

#reset counter data
$inbetween = 1;
$class_watch = $class;
$line_before = $chrom_pos;
}else {
#if the class is the same keep track
$inbetween++;
$line_before = $chrom_pos;
$class_watch = $class;
}
#line counter
$counter++;
}

print $new_data;

__DATA__
1457 G G SAME
1979 G G SAME
2056 T T SAME
3091 A A SAME
3562 A G DIFF
3778 A A SAME
4124 T T SAME
4229 C T DIFF
4571 A G DIFF
5019 A C DIFF
5114 C C SAME
6291 T T SAME
6414 C C SAME
6553 C C SAME
6941 G G SAME
EOF


This output's :
1457
3091
3778
4229
4124
5019
6941


(This post was edited by wickedxter on Aug 24, 2012, 2:26 AM)


Edit Log:
Post edited by wickedxter (User) on Aug 24, 2012, 2:26 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives