Hello all,

I have got a file that has the informations like this is in a tab delimited form.

Chromosom_id    fstart  fstop   Count
1 105     1  14.5
1  105     1  14.5
1  105     1  14.5
1  813     797     4

I would like to get the fstart and fstop and use them in the further processes.
I try to get those by two different types of scripts.
the first one is some thing like this::

while(<>){
chomp();
next if /^\s*$/;
next if /^(Chromosom_id.+)$/;
my ($cid, $fstart, $fstop, $count) = split/\t/;
print $fstart,"\n";
}
  1. I cant get individula columns. As in the code if I tried to print $cid it prints everything.
    like this

    1 105 1 14.5
    1 105 1 14.5
    1 105 1 14.5
    1 813 797 4
    1 813 797 22
    1 813 797 4

  2. where as if I tried to print $fstart I get

    Use of uninitialized value in print at gbrowse_cluster_col.pl line 12, <> line 2.

    Use of uninitialized value in print at gbrowse_cluster_col.pl line 12, <> line 3.

    Use of uninitialized value in print at gbrowse_cluster_col.pl line 12, <> line 4.

  3. Also I tried replacing the split with tab by split/\s+/
    it returns everthing as a single line like this:

    1105114.5
    1105114.5
    1105114.5
    18137974

Then in the case of the other code

open (FILE ,"$file") or die "Cannot open the file\n";
my @hit_clusters = <FILE>;
foreach my $file_line(@hit_clusters){


next if $file_line =~m/^\s*$/;
next if $file_line =~m/^(Chromosom_id.+)$/;
print $file_line, "\n";
if ($file_line =~m/^(.+?)\t(\d+?)\t(\d+?)\t(\d+?)\b/){
my ($id, $fstart, $fstop, $count)= ($1,$2,$3,$4);


}
}

I could not access the variables in the if loop.

Whats wrong in these? Any help?

Thanks.

Recommended Answers

All 4 Replies

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

while (<DATA>)
{
	my ($fstart, $fstop) = (split/\t/)[1,2];
	chomp;
	print "$fstart : $fstop\n";
}

print "\nAll done\n";


__DATA__
1	105	1	14.5
1	105	1	14.5
1	105	1	14.5
1	813	797	4

He has this posted on another forum where it has a number of replies and so far nothing has worked, his input file appears to not be tab delimited. He was told to use \s+ instead of \t , which did not work either.

:) It never ceases to amaze me how simple some problems are to solve when you at least have the right data to work with and the right question to ask.

:) It never ceases to amaze me how simple some problems are to solve when you at least have the right data to work with and the right question to ask.

Hey trudge,

Yeah That s true. I have been working with a wrong data set. ANd with the proper dataset it worked fine. Thanks for your comments and suggestions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.