perlhappy has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I have a quick question about the behavior of Perl when reading from the STDIN. Specifically about a particular piece of code.
Here is the code:
cat input_file.fq | perl -ne '$s=<>;<>;<>;chomp($s);print length($s)."\n";' > output.txt
The format for the input_file.fq is a FASTQ format file. This is standard for storing biological data.
e.g.
@HWI-EAS283_0004_FC:1:1:1321:1118#0/1TTGCTCAGCAGGTTCAACTGCAGGTTGCCCAGGACTTTAC
+HWI-EAS283_0004_FC:1:1:1321:1118#0/1
gg/fgag_ffgcfgeffafSKd\\adfRffff]fa[fffaf
@HWI-EAS283_0004_FC:1:1:1399:1117#0/1
CTTGACGATTCCCCGCAGGCTGTTCCCGCGGGCCGCAATG
+HWI-EAS283_0004_FC:1:1:1399:1117#0/1
Every line beginning with '@' is the ID for the next 3 lines. The second line is a collection of letters, typically either ATCG. The line beginning with + is just a repeat for the ID and then the fourth line is the last relevant line for a segment. Then this repeats for a new 4 line segment.
Basically, the above code gets the length of the sequence (ATCG) line for every segment, which is great but I dont understand the behaviour of the $s=<>;<>;<>; part of the code.
Could anyone explain what its doing, and how it knows only to look at the correct line (which will be line number 2, 6, 10, 14, 18 etc)? I've played around with this on different file formats and cant figure it out.
Any advice would be greatly appreciated
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: command line perl reading from STDIN
by choroba (Cardinal) on Jan 22, 2013 at 17:32 UTC | |
by perlhappy (Novice) on Jan 22, 2013 at 17:54 UTC | |
by choroba (Cardinal) on Jan 22, 2013 at 18:02 UTC | |
by perlhappy (Novice) on Jan 22, 2013 at 18:14 UTC | |
by perlhappy (Novice) on Jan 22, 2013 at 18:12 UTC | |
by Anonymous Monk on Jan 23, 2013 at 23:32 UTC | |
Re: command line perl reading from STDIN
by talexb (Chancellor) on Jan 22, 2013 at 17:56 UTC | |
by perlhappy (Novice) on Jan 31, 2013 at 16:43 UTC | |
by choroba (Cardinal) on Jan 31, 2013 at 17:25 UTC | |
by perlhappy (Novice) on Jan 31, 2013 at 18:06 UTC | |
by BrowserUk (Patriarch) on Jan 31, 2013 at 18:24 UTC | |
| |
by tye (Sage) on Jan 31, 2013 at 19:11 UTC | |
| |
Re: command line perl reading from STDIN
by AnomalousMonk (Archbishop) on Jan 23, 2013 at 00:48 UTC | |
by perlhappy (Novice) on Jan 31, 2013 at 16:25 UTC |