in reply to Re: deleting a particular character and its coresponding score in 2 different files!!!
in thread deleting a particular character and its coresponding score in 2 different files!!!

yeah, i tried with use warnings and use strict, here is the program which i tried.
#!/usr/bin/perl use strict; use warnings; open(FH1,"read.txt"); open(FH2,"qual.txt"); my @arr1=<FH1>; my @arr2=<FH2>; my $joi1=join(' ',@arr1); my $joi2=join(' ',@arr2); my @new=split('>',$joi1); my @numbers=split('>',$joi2); my @new; my @seqid; foreach(@new){ my($seq_id,$seq)=split(/\n/,$_); push(@alp,split(' ',$seq)); push(@seqid,$seq_id); } my @numbers; my @numid; foreach(@numbers){ my ($num_id,$numb)=split(/\n/,$_); push(@num,split(' ',$numb)) +; push(@numid,$num_id) } my @keep= grep {$_ < 1 || $num[$_]>=10 || $alp[$_-1] ne $alp[$_-0]} 0. +.$#num; print (join(' ',@alp[@keep]),"\n"); print (join(' ',@num[@keep]),"\n");
the result which i got is
Use of uninitialized value in split at sample.pl line 15,<FH2> line 6. Use of uninitialized value in split at sample.pl line 21,<FH2> line 6. Use of uninitialized value in string ne at sample.pl line 24, <FH2> li +ne 6. Use of uninitialized value in join or string at sample.pl line 25, <FH +2> line 6. TGACTTTTGCAAAGCTCGTA TGACTTTTGCAAAGCTCGTA TGACTTTTGCAAAGCTCGTA + 34 45 34 23 32 43 54 45 3 +4 12 23 45 54 65 34 23 54 42 34 45 34 23 32 43 54 45 34 12 23 45 54 6 +5 34 23 54 42 34 45 34 23 32 43 54 45 34 12 23 45 54 65 34 23 54 42
Is this problem because i am using more than one string from 2 different files? in the above program, why are we not comparing the character repetition at all? In some cases, if the number is less than 10, but doesnt come into repeted continous characters, it should be removed. Please suggest what can be done. I am not very good at perl :-( Thanks
  • Comment on Re^2: deleting a particular character and its coresponding score in 2 different files!!!
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: deleting a particular character and its coresponding score in 2 different files!!!
by GrandFather (Saint) on Oct 14, 2008 at 10:26 UTC

    No. It is because you are being silly. Some important lines of code are:

    my @new = split ('>', $joi1); ... my @new; .. foreach (@new) {

    Which of the two @new variables do you expect will be used by the for loop?

    Why didn't you show us the '"my" variable @new masks earlier declaration in same scope at ...' errors you received or the errors about @alp and @num? Have you actually run the code you've shown us?

    It helps us a lot to help you if you give use sample code we can actually run and if you show us the result you get and the result you would like from running the code. Oh, and the sample code and results should be short. For example cleaning up your code a little including fixing all stricture warnings and errors:

    use warnings; use strict; my $seq = <<DATA; >s1 AGCTTTTCGGGCAAT >s2 GCTGCCCCCCATCTT >s3 TCGTAGCTGAAAATC DATA my $num = <<DATA; >s1 23 43 45 65 76 54 3 34 54 65 7 45 56 87 56 >s2 23 43 23 45 65 45 76 78 34 8 12 32 65 23 25 >s3 12 23 34 45 56 54 43 32 65 43 12 34 75 76 45 DATA open FH1, '<', \$seq; open FH2, '<', \$num; my @arr1 = <FH1>; my @arr2 = <FH2>; my $joi1 = join (' ', @arr1); my $joi2 = join (' ', @arr2); my @new = grep length, split ('>', $joi1); my @numbers = grep length, split ('>', $joi2); my @seqid; my @alp; foreach (@new) { my ($seq_id, $seq) = split (/\n/, $_); push (@alp, grep /[ACGT]/, split ('', $seq)); push (@seqid, $seq_id); } my @num; my @numid; foreach (@numbers) { my ($num_id, $numb) = split (/\n/, $_); push (@num, split (' ', $numb)); push ( @numid, $num_id ); } my @keep = grep {$_ < 1 || $num[$_] >= 10 || $alp[$_ - 1] ne $alp[$_ - 0]} 0 +.. $#num; print (join (' ', @alp[@keep]), "\n"); print (join (' ', map {sprintf '%2d', $_} @num[@keep]), "\n");

    prints:

    A G C T T T C G G C A A T G C T G C C C C C A T + C T T T C G T A G C T G A A A A T C 23 43 45 65 76 54 34 54 65 45 56 87 56 23 43 23 45 65 45 76 78 34 12 3 +2 65 23 25 12 23 34 45 56 54 43 32 65 43 12 34 75 76 45

    Perl reduces RSI - it saves typing
Re^3: deleting a particular character and its coresponding score in 2 different files!!!
by apl (Monsignor) on Oct 14, 2008 at 10:00 UTC
    Use of uninitialized value in string ne at sample.pl line 24, <FH2> line 6.
    This refers to

    my @keep= grep {$_ < 1 || $num[$_]>=10 || $alp[$_-1] ne $alp[$_-0]} 0..$#num;

    This statement appears to be incorrectly constructed. I believe the first argument should be a regex, not a logical conditional.

    Revised: Please ignore. As this points out, I was wrong.