Have you ever felt the need to sit and flip a coin 100 times???

If you have, you are either in a Stats class or very bored.  Never mind the fact that it is evident that I have been thinking about flipping coins.  That’s just the result of working too hard yesterday and having nothing to do today.  Anyway, after much deliberation, I’ve come to the conclusion that it’s a lot of work flipping that coin 100 times…what if there was an easier way???  I decided to take my training in R (minimal though it may be) and use it to work out this simple problem for practice.  Much more fun than actually flipping the coin 100 times.  And I actually don’t have a coin anyway.

Here’s how you do it in R:

Coin Flip Simulation


Session 1: Getting Started

Please note that I work on a Mac, so all of the screenshots that are included in this blog will be of the Mac version of the R program.  Fortunately, the program runs very similarly on both Windows and Mac.  I will try to point out the differences where they occur.

To download R, go to http://www.r-project.org.

1.  To download R for your personal computer, you must choose a mirror through which to run the program.  As far as I am aware, it doesn’t matter which one you choose. One person recommended the mirror run through Iowa State University, as it seems to run faster.

2.  Install the program.  On a windows machine, a shortcut will appear on the desktop.  On a Mac, drag the R icon from the applications menu to the dock.

3.  Open the program.  The new version on a Mac appears as shown in Figure 1.

Figure 1.  Screenshot of R program on a Mac.

Figure 1. Screenshot of R program on a Mac.

4.  To begin programming, type at the > symbol.  At the end of the command, press enter or return to run the command.  On a Windows machine, commands can either be typed in the Console (pictured in Figure 1) on in the Editor screen.  To open the Editor, go to File, Open, New Document.  To run the commands from the Editor screen on Windows, click the button that looks like it has an arrow between two file cabinets…not the most intuitive button.

The logic behind programming in R rests on the construction of vectors.  A vector has one dimension and is composed of elements.  The elements may be numerical, logical (true vs false), or characters.

Example 1:

I want vector x to be composed of the numbers 5, 6, 7, 8, 9, 10.

The command to construct this vector in R is:


There are several elements to this command.

  1. x is the name of the vector.  If I want to, I could name the vector Victor.  Then Victor would contain the elements 5,6,7,8,9,10.  (But that would be ridiculous.)  For another example, the vector might contain height of 5 humans.  In this case I would name the vector height and set height to contain the elements 1.6, 1.8, 1.3, 1.7, 1.9.
  2. <- is the less than sign followed by the minus sign.  Think of it as an arrow pointing to the name of the vector and indicating what elements are assigned to that vector.
  3. c(…) is the concatenate function.  This is a very commonly used function that groups elements together.

This is what Example 1 looks like in R (Figure 2):

Figure 2.  The first line of code sets the assigns the vector x the numbers 5-10.  To verify the assignment, I typed x in the next line and pressed return.  This gives the third line  [5  6   7   8   9  10] to show the contents of x.

Figure 2. The first line of code sets the assigns the vector x the numbers 5-10. To verify the assignment, I typed x in the next line and pressed return. This gives the third line
[5 6 7 8 9 10]
to show the contents of x.

There are a lot of other ways to accomplish making a vector.  These additional methods follow:

Figure 3.  Additional ways to make vectors.

Figure 3. Additional ways to make vectors.




Welcome to the Jungle (of R)

I am currently taking a class in R programming and thought it might be useful to dedicate part of this blog to topics covered in class and homework.   Examples of R code can be found all over the internet.  Almost every question about code has been asked and answered, but sometimes it is hard to know where to start.  And sometimes it is difficult to keep track of information on writing code.  Putting everything covered in my class down on this blog might be helpful.  It might not be helpful.  But I’m going to give it a shot….just realize:  I am not an expert.  I am learning to program in R at the very basic level.  I just downloaded the program and opened it for the first time this past month.  One other advantage of posting this information online is that if questions come up, I can add solutions to this blog and make it more complete. (completely self-serving, I know).

Drumroll please!!!!!

I am inordinately self-satisfied and ridiculously excited to announce that coqui project that occupied my every waking moment as an undergraduate senior is published in the October issue of the Journal of Biogeography!!! Hooray! After cleaning up my lab space and taking a final count on all of the materials (not to mention time) spent on completing the lab work, my advisor and I sat down to write the manuscript all summer and into fall.  After being sent back to the drawing board for massive and then minor changes that included another analysis and complete concept restructuring, the paper was accepted.  The whole writing-get sent back for revisions-writing again-resubmitting process was very educational.  And kind of mind numbing at times. But we got it done!! A few people (not including my mom) have even requested copies of it!  Like I said; inordinately self-satisfied.

You can find the article here:


And, oh, by the way…that snazzy looking coqui frog on the COVER of the issue?  Yeah.  I took that. :D

E. coqui


Ok, I’m done bragging now.  Back to my current research project…

Fun with Numbers

The molecular work is finished!! It’s sort of strange, but now that I have to leave my lab space, I finally feel like I’ve graduated from Jewell.  The ceremonies were fun—it was nice to be one of the graduates for a change instead of just someone in the band beating out Pomp and Circumstance for half an hour.  I’ve been to no less than 8 graduation ceremonies after all.  However, cleaning out my lab bench was kind of a sad experience.  Now the only evidence of my extended presence in the lab is the collection of tiny scratches on the bench that mark the careful removal of toes, legs, and other appendages of 500+ frogs.  That and the 12 boxes of coquis in the refrigerator, 4-5 boxes of PCR reagents and primers in the -20 freezer, and the 15 or so boxes filled with DNA samples in the -80 freezer…I can certainly fill up space.  I’m sure that everyone is glad to have the bench back in lab.  With all of my notebooks and hoarded reagents gone, cabinet space is not an issue at all!

I thought it would be…entertaining (for lack of a better word) to go back and figure out exactly how many materials I went through in order to finish my thesis.  When we were drafting out our research proposals as juniors, I was presumptuous enough to think that I could figure out my supplies list down to the pipette tips.  Lots of people have asked me how many tips I think I’ve used, and I usually just shrug and say, “I dunno,” and dump a beaker full into the autoclave box.  But it’s easy enough to figure out, so here we go:

I anticipated needing a total of 5224 tips total, including all three sizes available.  Well I was off by a little:

PCR requires a pipette each for water, buffer, taq, primer 1 and primer 2, dNTPS, BSA, and magnesium.  That’s 8 yellow pipettes per master mix.  Pipetting the PCR master mix into the PCR tubes requires another yellow pipette that I reuse, so now we’re up to 9 tips.  I make 5 master mixes for each 96-sample PCR reaction and DNA goes into 91 of the PCR tubes.  It took 50 PCR reactions to amplify 9 microsatellites.  So for 250 master mixes, I used 2250 yellow tips. And with a clean pipette tip for each DNA sample, we’re at 6732 tips.  Already way over what I anticipated.  But lets keep going.

Now that PCR is done, each sample gets a little dye, distributed by (thank God) a multichannel pipette.  For roughly 4800 samples (including, of course negative controls), I used as many white tips…and that many again to load the gels.  That puts us at 9600 white tips for prepping and loading PCR to run.  One gel will hold 12 samples, so that puts us at 400 gels.  Something doesn’t add up…I have 524 gels on my flashdrive…oh yeah! I forgot!  I redid coq-211 and some of coq-20, and filled in a few holes…you know it’s really the nit-picky stuff that adds up.  Silly me.   So I actually ran 6288 samples and used 12,576 white tips for gels.  And with each gel getting three lanes of marker, we round out this leg of lab work with 14,148 white tips.  Whoa.  Well, why stop now???

Looking back a little farther to the days of DNA extraction, it’s a little harder to figure out the numbers.  But not impossible:  Each DNA sample gets poked, prodded, transferred, or aliquoted with approximately 7 yellow tips, 1 blue tip, and 1 white tip.  That adds up to around 3486 yellow tips, 498 blue tips, and 498 white tips.  Oh but then there was that one population of 21 coquis that I re-extracted, so now we’re at 3633 yellow tips, and 519 blue and white tips each.

Grand total for tips:  10,365 yellow tips. 14,667 white tips.  519 blue tips.  And these numbers don’t include any trouble-shooting, or tips filled up with the wrong reagent, or the tips that fell on the floor accidentally. Yikes!

But wait, there’s more!  Instead of needing 500 1.5 mL microcentrifuge tubes, it took 1038 for DNA extractions and 250 for PCR master mixes, plus around 6 per microsatellite primer set…1342 1.5 microcentrifuge tubes total.  Instead of needing a refill on RED TAQ, I needed 4.5 tubes.  Instead of planning to use the ladder we already had plenty of, I needed a little over 7 tubes.  Instead of just finishing up the bottle of acrylamide, I needed 2 liters.  I think the only place I managed to save was on the running buffer for the gels.  After I made about 10 liters of that, I just reused it.

And let’s not forget the collecting trip to Hawai’i…

Look out K-State!!!

Decisions, Decisions…

Well, I finally took a break from lab work shortly after obtaining a third gel apparatus.  It was a nice break–more than a month–but now I’m back in lab working on the same 13 microsatellites, the same 498 coquis, in the same lab, with the same equipment.  The only difference is now, I have a degree! Yay.

I started with optimization PCR for the 7 remaining microsatellites and ran the gels yesterday.  I rescued the gels after their 12 hour runs this morning and voila! The images are below.

Gel 413 shows PCR product from coq-27 and coq-208. Not surprisingly, coq-208 is STILL ambiguous. Coq-27 is annoyingly faint, but may be a good microsatellite for a rainy day.

In this gel you can see PCR product from the infamous coq-31. Lanes in which this microsatellite are mysteriously blank…Coq-28 appears to have been more successful. You can see more of this microsatellite in the following image.

Coq-28 has finally made an appearance, and it looks to be polymorphic and there are several heterozygotes in this gel, making coq-28 a good candidate for future PCR reactions. Also in this gel, you can see PCR product from coq-201. This microsat. worked so well at 50 degrees (lane 8), it’s probably next up for PCR. On the far right, lane 14 shows coq-203. This micro satellite also appears to have worked well.

Well, maybe I won’t get too excited about coq-203. Not very polymorphic–in fact, it looks an awful lot like coq-20 and coq-224…weird. The last microsat. in this gel is coq-10. Another primer set that has yet to work in any circumstance.

Tom, Dick, and Harry…

I am now four gels faster than I was last week.  Only two more PCR reactions for coq-19 before I have to stop adding new data and start filling in the infamous “holes in my data set” that I keep mentioning at every presentation I’ve given so far this semester.  I might be able to squeeze in coq-27 and coq-203 if they behave (amplify).

Other things of note:

Loading dye is easy to make:  3 grams glycerol in 10 mL water, shake vigorously, look at it, realize it’s not mixed yet and shake it again even more vigorously, and then add xylene cyanol.  Be careful not to add too much.  The first tube I made was way too dark, but the second one was much better.  Literally, all you need is a few crumbs of the dye powder.  Also, it’s quite messy, so mix carefully…