Showing posts with label regular expressions. Show all posts
Showing posts with label regular expressions. Show all posts

Sunday, November 13, 2011

grep()-ing for decimal points with regular expressions

Decimal points/periods are metacharacters that have special meaning in regular expression.

You normally have to "escape" metacharacters in R regular expressions if you want to search for the literal character. Escaping is done with a double slash "\\" before the metacharacter.

At least for decimal points (perhaps all metacharacters) you don't have to escape them if they are contained within brackets. All of the following grep() statements will find decimal points.

grep("[\\.]", test$orig_tag)
grep("[.]", test$orig_tag)
grep("\\.", test$orig_tag)

Thursday, November 3, 2011

regex practice from the biobucket

Using the stringr package
http://thebiobucket.blogspot.com/2011/11/simple-but-propable-useful-regex.html#more

Wednesday, November 2, 2011

Beautiful Code from O'Reilly

Beautiful Code: Leading Programmers Explain How They Think (2007) has several chapters that relate to the deeper logic behind scientific programming. While not related to the everyday chores of applied programing and statistics, these look like they would be useful for appreciating what goes on under the hood of well-designed programming languages, packages, and functions.

Chapter 1: "A regular expression matcher" by Brian Kerigham (one of the luminaries of computer science), dissects a simple regular expression editor written in C and extends a discussion on regular expressions started started in his book The Practice of Programming.
Chapter 4: "Finding things," by Tim Bray, also deals with regular expressions.
Chapter 14: "How elegant code evolves with hardware: the case of Gaussian Elimination" discuss some of the mechanics behind computation of systems of linear equations.

Two chapters focus on aspects of how Python works:
Chapter 18: Python's dictionary implementation: being all things to all people
Chapter 19: Multidimensional iterators in Numpy

And two chapters relate specifically to the design of bioinformatics tools.
Chapter 12: Growing beautiful code in BioPerl
Chapter 13: The deign of the Gene Sorter


Also in this series of books is Beautiful Data.

Thursday, October 27, 2011

awk and sed

Two programs that are suppossed to be great for processing text are awk and sed. According to Haddock and Dunn's Practical Computing For Biologists (2010), the are similar to other general expression environments like the shell function grep, but they "are like programming languages" and provide "even more opportunities to perform complex tasks" (page 78).

Wild-card searches in MS Word

Word support advanced searching using "wildcards." Details can be found on the Microsoft website.

Sunday, October 23, 2011

Cleaning bibliographies with regular expressions

http://www.r-bloggers.com/using-regular-expressions-in-r-case-study-in-cleaning-a-bibtex-database/

Sunday, October 9, 2011

Find questions marks (?) and asterisks (*) in Excel




Excel treats some characters differently than others when you do a search (cntrl+F). If you try to search for a ? or a *, it won't take you to their location.

According to this site if you precede your search with a tilda (~) the search function will locate the question marks.

So, to find a ?, enter ~? into the search field.
To find a *, enter ~*
and to find a tilda itself, enter ~~.

This odd complication is probably due to the fact that ?, * and ~ are "metacharacters" used for special functions in other programming contexts (specifically "regular expressions"). Why these three cause problems, and other metacharacters such as {, [, . , $, ^ and < don't, however, is a mystery to me.