SEQanswers

Go Back   SEQanswers > Sequencing Technologies/Companies > 454 Pyrosequencing



Similar Threads
Thread Thread Starter Forum Replies Last Post
seq.txt, qseq.txt and fastq NicoBxl Bioinformatics 5 01-03-2014 09:35 AM
s_*_export.txt VS s_*_sequence.txt zhuj Illumina/Solexa 5 06-08-2010 02:35 PM
solexa output files | s_*_seq.txt vs. s_*_sequencece.txt lajoieb Illumina/Solexa 3 04-08-2009 06:52 PM
Difference between eland_multi.txt and eland_extended.txt seq_GA Illumina/Solexa 1 02-13-2009 04:50 AM
problems concerning seq.txt and prb.txt hannat Bioinformatics 4 01-27-2009 11:35 PM

Reply
 
Thread Tools
Old 01-19-2011, 06:26 AM   #1
pmiguel
Senior Member
 
Location: Purdue University, West Lafayette, Indiana

Join Date: Aug 2008
Posts: 2,317
Default One-liner to parse 454BaseCallerMetrics.txt

After processing usually follows the maddeningly slow crawl through 454BaseCallerMetrics.txt to find out whether it is a good day or not. Typically I egrep for a few keywords (eg "totalBases") to get an idea. But, even then I am squinting at the screen, counting digits to see if all went well. How about a nice perl one-liner that will pull the lines of interest and add commas in the right places in long numbers?

Code:
perl -ne 's/(\d)(?=(\d{3})+(\D|$))/$1\,/g; print if /region|numberReads|totalBases|average|key/;' 454BaseCallerMetrics.txt

That sweet "insert commas into numbers" regex courtesy of Randall Schwartz:

http://www.perlmonks.org/?node_id=28331

--
Phillip

Last edited by pmiguel; 07-26-2011 at 07:25 AM. Reason: Changed "averageLength" to "average"
pmiguel is offline   Reply With Quote
Old 01-19-2011, 06:54 AM   #2
pmiguel
Senior Member
 
Location: Purdue University, West Lafayette, Indiana

Join Date: Aug 2008
Posts: 2,317
Default

By the way, my take on how the regex functions is:

Code:
s{
    (\d)            #capture a single digit
    (?=            #so-called look ahead assertion
       (\d{3})+ #3 digits -- remember greediness, though!
       (\D|$)     #a single "not a digit" or end of string (line)
    )
}
{$1\,}gx
#replace the first captured digit with itself plus a comma -- repeat until the end of the string is reached
The goofy "(?=)" syntax requires the regex inside be true, but does not actually "consume" the characters it matches.

One other factor in play: most repeat regex operators are naturally "greedy". That is, they try to match as much as possible. So \d{3}+ will match as many instances as possible of groups of three digits. The result is that the first comma to be replaced is the leftward-most one.

The "g", of course, calls for the matching to be repeated until the end of the string is reached. This is where the (?=) becomes important. Even though it matched all the way to the end of the number, it is a "zero width assertion", meaning string matching picks up again right where the (?=) had started. Hence the next comma can be insert, and so on.

--
Phillip
pmiguel is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 02:10 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO