Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: find reverse complement of every 2nd line

by bingalee (Acolyte)
on Jul 09, 2013 at 23:12 UTC ( #1043392=note: print w/replies, xml ) Need Help??


in reply to Re: find reverse complement of every 2nd line
in thread find reverse complement of every 2nd line

Hey Dave. For the reverse complement the code will be something like this

my $raw=<IN>; $rev= reverse $raw; $rev=~tr/ATGCatgc/TACGtacg/;

my problem actually is doing this only to every other line and not the entire file

this is what i came up with, but it doesnt work

while(@inf=<IN>) { if(i%2==1) { $inf[i]=reverse $inf[i]; } }

In this i was just trying to find the reverse to see if this code performs the action on the lines I want it to.. but no luck. Im still thinking of any other way. Any suggestions?

Replies are listed 'Best First'.
Re^3: find reverse complement of every 2nd line
by LanX (Chancellor) on Jul 09, 2013 at 23:27 UTC
    variables in Perl need sigils, so it must be $i not just i

    (using strict and warnings should have prevented you)

    and you need to increment it with ++$i within the loop.

    As an alternative you could just test $. % 2 since $. automatically holds the line-number.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re^3: find reverse complement of every 2nd line
by syphilis (Chancellor) on Jul 09, 2013 at 23:40 UTC
    my problem actually is doing this only to every other line and not the entire file

    The special variable $. (documented in perldoc perlvar) keeps count of the line numbers, so you can do something like:
    while(<IN>) { next if $. % 2; # skip odd lines # do the processing }
    Cheers,
    Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043392]
help
Chatterbox?
[Discipulus]: 'give man a fish erix it sonds like a push towards omosexuality.. ;=)
[Discipulus]: see Re: from txt file to array erix
[erix]: yeah, I ask for the text (I don't see signatures)
[Discipulus]: dear brother karl has "Furthermore I consider that Donald Trump must be impeached as soon as possible" in his sig
[erix]: ah, thanks Discipulus
[1nickt]: erix perhaps you could kindly point out your technique to roho and everyone will be happy.
[Discipulus]: but i'm also animalist, so i' hirted by 1nickt's sig: The way forward always starts with a mammal test... grin..
[erix]: I might if I did remember. It's probably somewhere in the site docs
[uhClem]: I don't favor that sort of thing around here but the place for our politics is wherever we live.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-06-22 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.