Combining pdf files

Recently, I needed to combine several pdf files into one. The The Tao of Mac has a discussion of how to do this and I’m posting the code I used here so that I can find it again later.

gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf -c save pop -f *.pdf

Running this from a directory containing only the pdfs to be combined produces out.pdf.

Evolutionary ecology diagram

I have used this diagram of evolutionary ecology in a wide variety of contexts. In the hope that it may be useful to others, I have made it available to anyone interested. The OmniGraffle source file is available as EvolEcol.graffle.

EvolEcol

Plantae

In collaboration with Jana and Steve Vamosi, I have started a new project called Plantae. The goal of this project is to create a community website for the collection of evolutionary and ecological data for plant species. An early prototype of the project is available and we welcome feedback on all aspects of the project.

Although the current implementation is rather rough. I hope to make some rapid progress on the design and function of the site in the new year.

Update: plantae has a new home at plantae.info.

Intelligent design in the classroom

Now that intelligent design is back in the Canadian news, we should consider (again!) the consequences of teaching intelligent design in the classroom.

Intelligent design makes two postulates:

  1. Complexity cannot be explained by science.

  2. Given 1, complexity comes from an intelligent designer.

Now, consider a science exam in any subject and the danger of intelligent design being taught in school becomes apparent.

Don’t be fooled that the creationist agenda ends with biology. They intend to reduce science education to: That’s really complicated; God did it.

The Onion on Intelligent Falling theory

The Onion on Intelligent Falling theory: “David Pescovitz: The Onion brilliantly parodies Intelligent Design believers:

KANSAS CITY, KSβ€”As the debate over the teaching of evolution in public schools continues, a new controversy over the science curriculum arose Monday in this embattled Midwestern state. Scientists from the Evangelical Center For Faith-Based Reasoning are now asserting that the long-held ‘theory of gravity’ is flawed, and they have responded to it with a new theory of Intelligent Falling.

‘Things fall not because they are acted upon by some gravitational force, but because a higher intelligence, ‘God’ if you will, is pushing them down,’ said Gabriel Burdett, who holds degrees in education, applied Scripture, and physics from Oral Roberts University…

Some evangelical physicists propose that Intelligent Falling provides an elegant solution to the central problem of modern physics.

‘Anti-falling physicists have been theorizing for decades about the ‘electromagnetic force,’ the ‘weak nuclear force,’ the ‘strong nuclear force,’ and so-called ‘force of gravity,” Burdett said. ‘And they tilt their findings toward trying to unite them into one force. But readers of the Bible have already known for millennia what this one, unified force is: His name is Jesus.’

Link _(Thanks, Scott Compton!) _

UPDATE: David Lynch (not that David Lynch) points to a comic with a similar gag from May. Link

(Via Boing Boing.)

Inflorescence architecture

Mating by outcrossing plants depends on the frequency and quality of interaction between pollen vectors and individual flowers. However, the historical focus of pollination biology on individual flowers (floricentrism) cannot produce a complete understanding of the role of pollination in plant mating, because mating is an aggregate process, which depends on the reproductive outcomes of all of a plant’s flowers. Simultaneous display of multiple flowers in an inflorescence increases a plant’s attractiveness to pollinators, which should generally enhance mating opportunities. However, whenever pollinators visit multiple flowers on an inflorescence, self-pollination among flowers can reduce the pollen available for export to other plants (pollen discounting) and increase the incidence of inbreeding depression for embryos and offspring. Therefore, the size of floral displays that maximizes mating frequency and quality generally balances the benefits of attractiveness against the costs of self-pollination. This balance can shift considerably if different flowers serve female and male functions at one time (sexual segregation) and flowers are arranged in inflorescences so that pollinators visit female flowers before male flowers. However, the effectiveness of sexual segregation depends on the extent to which a particular inflorescence architecture induces consistent movement patterns by pollinators. In general, the consistency of pollinator movement patterns varies with inflorescence architecture and differs between pollinator types. Such variation creates many options for the evolution of the diverse inflorescence characteristics within angiosperms, which can be appreciated only by moving beyond a floricentric perspective of the role of pollination in plant mating.

displaySize

Collaborator(s):

Lawrence Harder

Publication(s):

Trade-offs between clonal & sexual reproduction

Clonality is very common in flowering plants, but its consequences for sexual reproduction have rarely been explored. While clonal growth can increase the number of flowers a plant produces it may also limit reproductive success through pollen discounting (reduction in pollen exported to adjacent clones) and pollen limitation (failure of outside pollen to reach the centre of a clone). Using clones of domestic apple (Malus x domestica) that ranged from 1 to 5 orchard rows wide, we found that the patterns of siring success were consistent with the presence of pollen discounting, but we failed to detect evidence for pollen limitation. The results suggest that paternal function may be more sensitive to the effects of clonality than female function.

appleCloneSize

Collaborator(s):

Publication(s):

Temporal separation of gender

Dichogamy, the temporal separation of gender within a flower, is widespread throughout the angiosperms, occurring in over 250 families. There are two forms of dichogamy: protandry, in which male function precedes female function, and protogyny, the converse. Dichogamy has traditionally been interpreted as a mechanism to avoid inbreeding. However, recent evidence indicates that this inbreeding-avoidance hypothesis cannot completely explain the evolution of dichogamy. An alternate hypothesis is that dichogamy acts to reduce interference between gender functions. Interference can occur within a flower or between flowers on an inflorescence and result in substantial reductions in male and female reproductive success. To date there are very few tests of this interference-avoidance hypothesis or, in fact, investigations of the evolution of dichogamy in general. My Ph.D. thesis was a comprehensive evaluation of the evolutionary significance of dichogamy, including functional, genetic, comparative, and theoretical analyses of this important floral character.

clint

This Claytonia species is protandrous. The flower on the left is in male phase with its anthers shedding pollen and the stigma closed and unreceptive. The flower on the right is approximately one day older and is in female phase. The stigma is open and receptive and the anthers have moved away to the side and are empty of pollen.

Functional analyses

As an evaluation of the fitness consequences of protandry, we tested the interference-avoidance hypothesis with enclosed, artificial populations of Chamerion angustifolium (Onagraceae) by experimentally manipulating protandry and inflorescence size and measuring pollinator visitation, seed set, female outcrossing-rate, and outcross siring-success. Protandrous plants had a marginally higher female outcrossing rate than adichogamous plants, but similar seed set and visitation rates. More importantly, protandrous plants (blue points) had, on average, a twofold siring advantage relative to adichogamous plants (red points). However, this siring advantage did not increase linearly with inflorescence size, suggesting that protandry acts to enhance siring success, but not exclusively by reducing between-flower interference.

siring

To better understand the function of protandry, we analyzed single bee visits to pairs of C. angustifolium flowers in the field and the lab. The patterns of pollen removal and deposition revealed two major consequences of simultaneous hermaphroditism. First, the presence of anthers impeded pollinator’s access to the stigma. Second, pollinators spent more time foraging on hermaphroditic flowers, relative to female flowers. Protandry allows pollen to be exported in the absence of this within-flower interference and can enhance both male and female reproductive success through reductions in pollen discounting and facilitated selfing, respectively.

beevisit

Genetic analysis

The genetic basis of dichogamy may have important implications for its evolution. Consequently, we conducted genetic analyses of protandry in C. angustifolium using a paternal half-sib design and an artificial selection experiment. We found moderate heritability (h^2^=0.27) for the duration of male phase. An analysis of plants from the artificial selection experiment showed no genetic correlation between male-phase duration and aspects of floral size. However, we estimated a positive genetic correlation between male-phase duration and floral display size. In addition, we detected a negative correlation between male- and female-phase durations which creates the opportunity for fitness trade-offs between male and female function.

sel

Phylogenetic analysis

To gain a broader perspective on the evolution of dichogamy, we used a current, well resolved phylogeny of the angiosperms to conduct a comparative analysis of dichogamy and self-incompatibility. Using paired-comparisons and maximum-likelihood correlation analyses, we found that protandry is positively correlated with self-incompatibility and protogyny with self-compatibility. These results support a role for interference avoidance in the evolution of protandry and inbreeding avoidance in the evolution of protogyny, suggesting that the two forms of dichogamy provide different functions. In addition, dichogamy changes character states throughout the phylogeny, allowing rapid responses to changing ecological circumstance.

phylo

Theoretical analysis

We developed a conceptual model to synthesize the effects of male-phase duration, inflorescence size, and inbreeding depression on pollen import and export. The relative fitness of protandry is strongly affected by the combination of floral display size and inbreeding depression. Furthermore, the trade-off between male- and female-phase durations produced a fitness landscape much more favourable to the evolution of protandry.

relfitness

Conclusions

Collectively, this research suggest that protandry enhances male fitness through reductions in both within- and between-flower interference, while protogyny reduces inbreeding. This work has revealed unexpected fitness benefits to protandry and helps to explain the wide taxonomic and ecological distribution of this trait in flowering plants.

Collaborator(s):

Publication(s):

Population size

The outcrossing rate is a fundamental attribute of plant populations that determines population genetic structure, individual plant fitness, and ultimately speciation rates. The outcrossing rate can be influenced by population size through reductions in both mate availability and pollinator service. We investigated the effect of population size on the outcrossing rate in 10 populations of Aquilegia canadensis in Southern Ontario, Canada.

Across a range of sizes from 32 to 750 reproductive individuals, we found that small populations (n < 35, red line) had a significantly lower outcrossing rate than large populations (n > 90, blue line).

nXt

Given the high estimate for inbreeding depression in this species (0.88 Β± 0.14), small populations may experience a rapid decline in population-level fitness that can lead to local extirpation. The consequences of human-induced habitat fragmentation suggest that such local extinctions are common due to this demographic effect.

Collaborator(s):

Publication(s):

Vector assignment in R

As I use R for data analysis and simulations, I become more comfortable and proficient with the R/S syntax and style of programming. One important insight is the use of vector assignments in simulations. I have often read that using such assignments is the preferred method, but until recently I had not realised the importance of this statement. To illustrate the use of vector assignments and their advantages, consider two models of the style illustrated below:

Model 1:

 value1List <- seq(1:10)
 value2Function <- function (value1) {
     ifelse(value1 < constant1, constant2, constant1)
 }
 tableDimension <- length(value1List)
 outputTable <- NULL
 outputTable <- data.frame(value1=numeric(tableDimension), 
 value2=numeric(tableDimension))
 n <- 1
 for (value1 in value1List) {
     outputTable[n, ] <- c(value1, value2Function(value1))
     n <- n + 1
 }

Model 2:

 value1List <- seq(1:10)
 tableDimension <- length(value1List)
 outputTable <- NULL
 outputTable$value1 <- rep(value1List, each=
     tableDimension / (length(value1List)))
 outputTable <- as.data.frame(outputTable)
 outputTable$value2 <- ifelse(value1 < constant1, constant2, constant1)

Model 1 is how I originally approached R programming. It begins with declaration of a sequence for value1 and a function declaration to calculate value2 from each value1. I then declare a table to capture the output and fill it with zero values. The main loop of the program consists of replacing the rows of the output table with each value of value1 and the calculated value2. I use the variable n to keep track of the next row in the table. The function rbind() could also be used to generate the table, but it’s use for large datasets is quite inefficient.

Model 2 takes the approach of constructing each column of the output table in sequence. It begins by repeating the values of the value1List and then creates the value2 column through a vector assignment. No control structures or function calls are required in Model 2.

How is this important? Model 1 seems intuitive (at least to me) while the syntax of Model 2 is opaque at first glance. However, consider this figure: vectorR

On the x-axis is the number of data points in the output table on a log scale. The y-axis shows how long the model takes to calculate these values. Model 1 is the blue line. Model 2 is the red line. This illustrates two important points: * Model 1 is always slower than Model 2. * As the size of the dataset increases, Model 2 remains fast while Model 1 rapidly consumes all of the computer resources.

This is why vector assignments should be used when programming with R. Just to be clear, the models described here are simple abstractions of the types of models used to generate this figure.

Image uploads

A particular challenge with maintaining a weblog is the uploading and resizing of images. The process involves choosing the correct images, creating large & thumbnail sized versions, uploading these images to the webserver, and posting the appropriate code into the weblog post. In the spirit of my last few posts, image2web is an applescript I use to automate this process:


  --user-specific variables
  property theAlbum : "Marked"
      --contains the images to be uploaded
  property theBasePath : "the:path:to:the:local:images:" as alias
      --the local path to the weblog
  property tagBaseUrl : "[www.your.website.org/path/to//...](http://www.your.website.org/path/to//blog/images/)"
      --the url to the weblog images
  ---declare globals
  property htmlText : ""
      --stores the image tags & is copied to the clipboard
  
  tell application "Finder"
      set theList to name of every folder of theBasePath
  end tell
  
  --choose which weblog category the images belong to
  set theCategoryList to choose from list theList
      with prompt "Choose the post's category:"
  set theCategory to first item of theCategoryList
  
  tell application "Finder"
      set theCategoryFolder to folder theCategory of theBasePath
  end tell
  
  --I use a smart album that collects photos with the checkmark tag
  tell application "iPhoto"
      activate
      select album theAlbum --so we can see which images are involved
      set theImages to every photo of album theAlbum --collect the images
      repeat with thisImage in theImages
          set thisImage to get image path of thisImage
          my processImage(thisImage, theCategoryFolder)
      --resize & generate the thumbnail
      set theResult to the result --avoid declaring more globals
      set thePhotoName to item 1 of theResult
      set theMainImagePath to item 2 of theResult
      set theThumbnailImagePath to item 3 of theResult
      my uploadImage(theMainImagePath, theThumbnailImagePath) --upload the image
      my makeTag(theCategory, thePhotoName) --create the appropriate html
      end repeat
      set the clipboard to htmlText --pass the html code to the clipboard
  end tell
  
  on processImage(thisImage, theCategoryFolder)
  
      set theResult to display dialog "Enter the name for " & thisImage & ":" default answer ""
      set thePhotoName to text returned of theResult
  
      tell application "Finder"
          set theDestinationPath to POSIX path of (theCategoryFolder as string)
          set theMainImagePath to (theDestinationPath & thePhotoName & ".jpg")
          set theThumbnailImagePath to (theDestinationPath & thePhotoName & "-thumb.jpg")
          do shell script "/usr/local/bin/convert -resize 640x480 +profile \" * \" " & "\""
      & thisImage & "\"" & " " & theMainImagePath
      ---use extra quotes to protect against spaces in path names
          do shell script "/usr/local/bin/convert -resize 240x240 +profile \" * \" " & "\""
      & thisImage & "\"" & " " & theThumbnailImagePath
      end tell
      return {thePhotoName, theMainImagePath, theThumbnailImagePath}
  
  end processImage
  
  on uploadImage(theMainImagePath, theThumbnailImagePath)
  
      set theMainImage to POSIX file theMainImagePath
      set theThumbnailImage to POSIX file theThumbnailImagePath
  
      tell application "Transmit"
          open theMainImage
          open theThumbnailImage
      end tell
  
  end uploadImage
  
  on makeTag(theCategory, thePhotoName)
	set htmlText to htmlText & ""
      --show the thumbnail & link to the full-size image
  end makeTag

The workflow is as follows:

  1. Mark photos with the check-mark tag
  2. Run the image2web script
  3. Past the clipboard to Blapp
  4. Publish the weblog

This script requires both ImageMagick and Transmit and is inspired by a script from waferbaby.

Podcasting & the CBC

The CBC has begun an experiment with podcasting. I’m impressed with the progressive approach to technology that the CBC has adopted and hope they expand the experiment to more of their programs.

This has the added effect of making my Quirks & Quarks download script obsolete.

Quirks & Quarks

Quirks & Quarks is the CBC’s excellent science program. I usually download the mp3 archives of the show on the weekends and listen while I walk Ceiligh.

Of course, loading up the Quirks & Quarks webpage, finding the archives, downloading the mp3s, and adding them to iTunes takes at least a few minutes. Computers are much better and handling such tedium.

Inspired by the success (for me) of the apod script, quirks.pl is a perl script that downloads the current Quirks & Quarks episode to the Desktop. runQuirks.scpt is an applescript that further simplifies the process by adding the downloads to iTunes and trashing the redundant downloads. I’ve set iCal to invoke runQuirks.scpt in the middle of the night, so now Quirks & Quarks is on my iPod and ready to go Sunday morning.

Note that runQuirks.scpt expects quirks.pl to be in β€œ~/Library/Scripts/quirks/”.

Astronomy pictures on the Desktop

The β€œAstronomy Picture of the Day” is a source of fantastic images. To take advantage of this resource, I went looking for a way to automatically set the current image as my Desktop background. A quick Google search turned up a perl script at www.haroldbakker.com. Although this was a great start, I wasn’t completely happy with the implementation of this script and decided to write my own.

The apod.pl script is written in perl and both sets the Desktop background and copies a description of the image to the Desktop as an html file. You can add the script to your Script menu and run it as appropriate. Even better, download the runApod.scpt applescript and have iCal set the Desktop at a convenient time. I’ve set up my computer to run the perl script early each morning so that I have a new Desktop background each day. Note that runApod.scpt expects apod.pl to be in β€œ~/Library/Scripts/apod/”.

Heritability of male-phase duration

Format:

Citation:

Climate change and public relations

A recent column in the Globe & Mail reminded me of our Federal Government’s plan for reducing greenhouse gas emissions: the One Tonne Challenge.

This campaign challenges each Canadian to reduce their contribution to greenhouse gas emissions by one tonne. The first step is to calculate your emissions and then implement recommendations for reductions. According to the online calculator, Kelly & I combined emit 4.23 tonnes annually. Fortunately, this is below the national average of 5.5 tonnes per person and significantly better than Alberta’s average of 8 tonnes per person. Still, we could do better. However, the suggestions provided aren’t much help. They largely concern implementing energy savings to our home β€” which we rent and have little control over. Here are the suggestions I could implement:

The website has a variety of good suggestions. The trick is convincing Canadian’s to assume some responsibility for climate change. Monetary incentives seem like the best strategy, but those are not currently under consideration.

Google Scholar

Yet another useful site from Google: Google Scholar. The site provides an interface for searching the scientific literature with typical Google ease. Some preliminary tests suggest that it is quite effective at finding relevant literature.

JSTOR import script

I’ve written a script that imports a JSTOR citation page into BibDesk. To use the script, I suggest adding it to your script menu. Then, with the JSTOR citation page as the active web page in Safari, run the script and the citation will be added to the active BibDesk file. I use the first author’s last name and last two digits of the year as a cite key (e.g. Darwin59), you may want to change this to suit your style.

The script is written in perl and bracketed by two Applescript commands: one to extract the html source from the JSTOR page and the other to add the citation to BibDesk. Unfortunately, JSTOR citation pages contain almost no semantic markup, so I am not convinced that the approach is entirely robust. However, so far it has worked well for me and might be useful to you. Any feedback is welcome.

Download the script. JSTORImport.pl.txt

Ecology Retreat, University of Calgary

Routley, M.B. Measuring the male gain curve. Ecology Retreat, University of Calgary

Download

The Crusade Against Evolution

An interesting read from Wired News – The Crusade Against Evolution. In addition, the Panda’s thumb has been following and carefully dissecting the recent controversy over an intelligent design paper being published in a peer-reviewed journal. The evolution-creation debate seems to be resurfacing after a short time off. The debate is important and the intelligent design supporters have to be countered, but their arguments have become hackneyed.