| |||||||||||
| |||||||||||
whats wrong?? Posted by revtopo (revtopo), 8 January 2008 Hi all,Below is the code for parsing through the files. #!/usr/bin/perl -w use strict; my $maximum_gap =150; my %pro_locus; while(<>){ chomp(); next if /^\s*$/; next if /^(Chromosom_id.+)$/; my ($cid, $fstart, $fstop, $count) = split/\t/; print "$cid\n"; } I have a bit of problem though it may be silly, I couldn't understand whats wrong with this. the file content is some thing like this: Chromosom_id fstart fstop Count 1 105 1 14.5 1 105 1 14.5 1 105 1 14.5 1 813 797 4 1 813 797 22 I thought the cid will have the chromosom_id, fstart=fstart, fstop =fstop , count = count. but when i print all these I get Use of uninitialized value in concatenation (.) or string at gbrowse_cluster_col.pl line 12, <> line 2. 1 105 1 14.5 Use of uninitialized value in concatenation (.) or string at gbrowse_cluster_col.pl line 12, <> line 3. Use of uninitialized value in concatenation (.) or string at gbrowse_cluster_col.pl line 12, <> line 3. Use of uninitialized value in concatenation (.) or string at gbrowse_cluster_col.pl line 12, <> line 3. 1 105 1 14.5 this 'line 3' keeps increasing until the last line of the file id printed. but if I print as in the code just the $cid then I am not getting any problem and I get all the columns in the file like 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 and goes on.. but instead if i try to print any thign other than cid I get uninitalised values as before. whats wrong on thes?? thanks. Posted by admin (Graham Ellis), 8 January 2008 It looks like your split is returning everything as one field so you're getting warnings that you don't have enough data to set all the varaibles; you have chosen to use the "-w" flag to ask for such warnings!Posted by revtopo (revtopo), 8 January 2008 I tried this way as well , but the problem with this is I cannot print nay thing to the standard out. and could not access any of the variables in the if loop.#! usr/bin/perl -w use strict; use Getopt::Long; my $file; my $maximum_gap =150; my %pro_locus; GetOptions('f=s'=>\$file, 'g=i' => \$maximum_gap) or exit; warn "\n Can't proceed!!!No file name given\n" if !$file; open (FILE ,"$file") or die "Cannot open the file\n"; my @hit_clusters = <FILE>; my $line_count = `wc -l < $file`; print "the number of line:$line_count\n"; close FILE; my %loci; foreach my $file_line(@hit_clusters){ next if $file_line =~m/^\s*$/; next if $file_line =~m/^(Chromosom_id.+)$/; if ($file_line =~m/^(.+?)\t(\d+?)\t(\d+?)\t(\d+?)\b/){ my ($id, $fstart, $fstop, $count)= ($1,$2,$3,$4); } } Is there any other way for this to go with? Thanks Posted by xadio (xadio), 8 January 2008 Take a look at the line in your original postCode:
I would suggest replacing it with Code:
I believe I have encountered this before when I was trying to split on a tab, but my data was in the form of spaces. Note 1: this also correlates with Graham's statement that "split is returning everything as one field so you're getting warnings". Note 2: this will only work if you don't have or need any other whitespace in your data. Posted by KevinAD (KevinAD), 9 January 2008 Instead of this:$_ =~ s/\s+/:/; my ($cid, $fstart, $fstop, $count) = split/:/; just do this: my ($cid, $fstart, $fstop, $count) = split/\s+/; the substitution is redundant. The problem is that the file is not tab delimited, or the tabs are not recognized as tabs by the system the script runs on. Tabs generated on one OS may not be the same as tabs on another OS. It's like line endings, they are not the same for all operating systems, and the system the script runs on defines what perl will think they are. In any event, unless there are embedded spaces in the fields, using \s+ is safer than \t as the search pattern for the split function. Posted by revtopo (revtopo), 9 January 2008 Hi, Though thatss work fine that returns everything as a single line something like this:1105114.5 1105114.5 1105114.5 18137974 Since i need the second and third columns for all my processing I would like the parsed file 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 with cid representing the first coulmn(1) fstart representing the second column(105) fstop representing the third column(1) and count representing the fourth column (14.5) so i need them all seperately Thanks Posted by KevinAD (KevinAD), 9 January 2008 If it returns all the fields as one line it is not working fine. We know what you want, repeating the same question again is not helpful. Post the most current code you are using and show how you are printing the lines after splitting them from the file.Posted by KevinAD (KevinAD), 10 January 2008 I guess he gave up here, he posted the original question on another forum today.Posted by admin (Graham Ellis), 11 January 2008 on 01/10/08 at 21:57:51, KevinAD wrote:
Kevin, I always bear in mind that some people don't have natural analytic minds and find it quite hard to read my analysis (or yours) so may do better having someone else explain the same thing in different ways. I'm also aware that English probably isn't the first language of the poster which doesn't help him/her, and that his/her culture may not be one where it's natural to get back and say "sorry - this didn't work for me". Come to think of it, there are a lot of people in my culture who take a lot of help with little or no thanks given! Posted by KevinAD (KevinAD), 12 January 2008 Graham,Thats all fine and probably true. You accept (or at least understand) the way he is and you try your best to help him. This is the way I am. Maybe this is the way I am because of my culture. You are probably the way you are for the same reasons, or maybe in spite of them. I trust you see where I'm going with this. We all have our reasons and our excuses. If I/we try and understand his culture (used in the broadest sense of the word), he has to try and understand "ours" too. No? Ipso-facto, if I can take his culture into account, he can take mine/ours into account too. Cogito ergo sum ![]() Posted by KevinAD (KevinAD), 12 January 2008 Graham,Thats all fine and probably true. You accept (or at least understand) the way he is and you try your best to help him. This is the way I am. Maybe this is the way I am because of my culture. You are probably the way you are for the same reasons, or maybe in spite of them. I trust you see where I'm going with this. We all have our reasons and our excuses. If I/we try and understand his culture (used in the broadest sense of the word), he has to try and understand "ours" too. No? Ipso-facto, if I can take his culture into account, he can take mine/ours into account too. Cogito ergo sum ![]() Posted by KevinAD (KevinAD), 12 January 2008 I guess it was worth repeating... sorry, no idea how the double-post got there, feel free to delete one and this one if you think best.Posted by revtopo (revtopo), 14 January 2008 thanks for those good commentsThis page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |