Thursday, March 26, 2020

Deciphering Caesar's Cipher

Right now I'm taking Harvard's CS50x online computer science course: https://cs50.harvard.edu/x/2020/

Since I have no "formal" computer science training, I wanted to go back and take a course that would give me some of the fundamentals my colleagues have.  You'd be surprised how much coding you can do without that degree, for certain.  But being able to do a thing is not the same as knowing why you do it the way you do.

This week my problem set included implementing a version of Caesar's Cipher--a way to encrypt messages by shifting the letter by a pre-arranged value.  For example, if you and I both agreed we'd shift every letter by 1, then 'HELLO' would become 'IFMMP.'  Which takes some thought but you can do it in your head, right?  But what if I told you we'd be shifting them by 20?  A+20 doesn't immediately make sense.  But fortunately computers already store letters as numbers. 

BEHOLD THE ASCII TABLE

So now it should be as simple as adding the starting letter's value to the key, then finding the new key in that ASCII table, right?  Oh yeah that's what I thought, until I remembered that the alphabet is 26 characters long. 

If your starting letter is A and your key is 20, you'll still land somewhere in the same alphabet.
If your starting letter is A and your key is 26, you'll land beyond Z . . . and then what do you do? 

Side note: "The Land Beyond Z" sounds like a pretty atmospheric novel title, doesn't it?  

As a human, you probably already know what to do: figure out how far past Z you've gone, and drag your finger back to A on that ASCII and keep counting.  You've got to "wrap around" to the beginning of the alphabet again.  But how do we tell a computer to do that?  I'll give you a short version, and a longer version:


TL;DR

Use of modulo in this case is like this game Cliffhangers on Price is Right!  When you know what's beyond your range, what remains, you can pick up this poor yodeler and set him back at square one and let him climb whatever steps he had left.  I'm going to pretend this mountain is 0-indexed because then it's perfect for the alphabetic range:



Longer Version / Deeper Dive / Down the Rabbit Hole We Go

encrpyted letter = ((starting letter) - 'A' + key) % 26 + 'A'

It works, and late at night I got here by googling around.  It worked but I didn't understand why.  Now I think I do.  Let's start here:

(starting letter) - 'A

A through Z is our valid range of characters.  If we take that Cliffhanger game analogy, past Z is a cliff!  So this part of the equation tells us how far away from our start, from A, we are right now.  

((starting letter) - 'A' + key)

Adding the key tells us how far we'd go from where we are, with no limits in place.  How far past the cliff's edge would the yodeler go, if he couldn't fall?

((starting letter) - 'A' + key) % 26
Here's where it gets fun!  Or at least, fun to me.  % in code can mean 'modulo' or 'remainder', where you are dividing a number by another number, and handing back what's left.  Here we are dividing the distance we could travel by 26, because that's how far the valid range goes.  How far past the cliff does our yodeler go?  If the number is smaller than 26, then the remainder is 0.  If the number is greater than 26, we get back what's left over--how far he's gone past the cliff.  

((starting letter) - 'A' + key) % 26 + 'A'
Now we know how far he's gone past the cliff, so we add that number to our starting point, 'A.'  In other words, instead of falling off the cliff, we picked up the yodeler and dropped him back at square one, at 'A', and then allowed him to climb the remaining steps to our new letter.


Let's practice this some more!

So if we take that complicated example, starting with A and having to change it by 26:

Given 
A = 65
Z = 90
Key = 26

((65)-65) = 0
Relative to our starting point, A, we're at 0

0 + 26 = 26
We want to move by 26 letters

26 % 26 = 0
There's nothing left over.

0 + 65 = 65
Fun!  By hurrying up we've stayed exactly in the same place.  Or more precisely, our yodeler moved the full length of our range and ended up back at the beginning of his climb.  

If we used 27 as our key instead . . .

((65)-65) = 0
Relative to our starting point, A, we're at 0

0 + 27 = 27
We want to move by 27 letters

27 % 26 = 1
We've got 1 left over.  We've exceed our range by one.

1 + 65 = 66
66 is B.  So the yodeler traveled the range, had one step left over, and instead of stepping into thin air, we picked him up and plopped him back at A and took one more step.  

To me, what's neat about all of this is that it doesn't matter how many times bigger than 26 the key is: with modulo we don't care how many times one number goes into another, only what's left over.  We know our starting point, so we apply the steps left to that.  

What if that poor yodeler never had to fall off a cliff!?  A thought for another time, perhaps.  Thanks for joining me on this mental journey! 



From DNA code to computer code

Hey all, it's been awhile right?  A lot has happened since I last posted here.  Significant milestones have included:

  • Completing my PhD thesis in Medical Microbiology and Immunology
  • Joining the private sector to work on bioinformatic software . . . 
  • Then pivoting to software for medical diagnostics
  • THEN pivoting both learning and location to work on software in the Financial Technology space in a whole new state!  
With that big set of shifts, the topics I'm going to cover will also shift.  I'm learning lots of good things and I want to share them!  

The fun part for me is that code is code is code.  And by that, I mean I've spent years with DNA code and lately I've spent my time instead studying computer code.  They are different.  They are the same.  Stay tuned!

Monday, June 16, 2014

Waiting for the moonflower

I grew up on a ridge in rural West Virginia.  Before the scurry of summer camps, internships, and eventually grad school and Adult Life, I spent many summer days just hanging around the house, helping out around the garden, flipping over rocks, catching crawdads.  For our family, one of our favorite evening activities was to sit out on the front lawn, our chairs faced in towards the house.  We were waiting for the moonflowers to open. 

Our moonflowers, more specifically Datura inoxia in this case, opened in the evening, around 8PMish ET if I recall.  Usually there would only be 1 or 2 blossoms opening each night.  We'd sit and watch the white umbrella-like bloom puff, slowly unfurl, eventually pop open.  And the fragrance was pure magic: like the cleanest soap you've ever smelled. 

I still marvel at the regularity of this event: it would always be around the same time each night, within 20 minutes or so.   While some folks were waiting for their regularly scheduled TV program, we were happy waiting for the moonflower's show. 

Some day, I'd like to have my own moonflowers to watch in the evening.  Unfortunately, they are not good for households with small children: they are part of the Solanaceae family, related to nightshade.  The entire plant contains dangerous alkaloids, such as atropine, and even touching their leaves is not a good idea.  Beautiful but dangerous, as many plants are. 

These days, my schedule revolves more around daycare dropoffs/pickups, heading to and from the office, and naptimes and bedtimes.  Hard to imagine a time when all we did in the evening was sit, chat, and wait for a flower to open!

Wednesday, August 29, 2012

Join in the chorus!

The other day I was learning a dance choreography from a good friend of mine.  She was having trouble remembering which combination went where, because the song repeats itself many times, and it's hard to know "where" in the song you are just by hearing a clip.

It struck me that this challenge was not unlike the challenge that scientists face trying to assemble genomes.  Genomes often contain repeat regions: stretches of sequence that are repeated in other parts of the genome.  In a way, repeat regions are like the chorus of a song.  When you hear a clip of only the chorus, you might not know if it's at the beginning of the song, somewhere in the middle, or near the end.

The trick with dancing a choreography that has lots of repeats is to memorize the bit that comes right before and right after each repeat.  Those bits help knit the repeat to its correct position in the song.  Genome assemblers can do the same thing if they receive sequences containing a bit of flanking DNA along with the repeat region.  Then each genetic chorus has its proper context.  

Saturday, April 14, 2012

Short Stories and Novels

When you get right down to it, your genome--the sum total of your DNA--is a story.  Sure, it's not written in English: DNA has its own code, with far fewer letters than we humans use to describe our world.  Yet this one code describes organisms as complex as ourselves and as elegantly simple as a virus.  As someone working in the field of DNA sequence analysis, I am thrilled to live in an age when whole genome sequencing is not only possible, it's becoming faster and cheaper by the year.  Still, the process of determining an entire genome is quite the puzzle. 

I want you to imagine your genome is right in front of you.  Maybe it's a big, leatherbound tome or a crisp, new paperback.  In a perfect world, you would just open the book and read it, cover to cover.  But the challenge of DNA sequencing is that the current technology can't do that, yet.  Instead of reading your genome cover to cover, you can only see, for example, 10 words at a time.    Somehow, you have to put the story back together. 


If someone gave you an envelope with the fragments of a haiku in it, you could probably paste the whole thing together all on your own.  But if someone hands you a shoebox with "The Cat in the Hat" fragments instead, it might take you a bit longer to put together.  And what if someone delivers you an office space filled with boxes of a hefty Stephen King novel, eh?  You'd probably need alot of time and alot of help. 

Bigger stories mean bigger problems.  That is the challenge of sequencing a genome, in a nutshell.  There are plenty of things that make the problem more difficult.  For example:
  • What if your "story" is a poem with repeated phrases?  How do you know where to put the fragment that matches 6 different places?  
  • What if, instead of seeing 10 words at a time, you could see 20 but there would be lots of typos?
  • What if the story is so huge it would take you several lifetimes to put together on your own? 
On the other hand, what can make solving the problem easier?
  • What if I gave you a draft copy of your story, and had you match the fragments to the draft?
  • What if I gave you a roomful of interns to help?
  • Or better yet, what if I gave you a roomful of computers to help?
Where is the technology right now?  Well, the stretches of DNA we can read at one time become longer and longer.  Imagine how much easier it is to piece together a story if you have whole chapters instead of sentences!  But you still might get the wrong answer, if the story long or very complex.  So these days scientists use computers to help solve the problems as fast as possible.  Over time, reading the sequence becomes cheaper, and piecing the story together becomes faster.  Truly, it is an exciting time to be a life scientist!  The ethical implications of all the information we glean from genomes, of course, is a discussion for another day . . . 

Tuesday, January 26, 2010

Quorum call, without voices

Is there anybody out there?
When it comes to political intrigue, it’s important to know whether you stand united or alone. Are you surrounded by friends or enemies? Is it time to lead the charge or wait for reinforcements? Tallying how many supporters you have—or how many enemies are waiting in your midst—can be critical to your success.

For bacteria, things aren’t much different. Bacteria survey their surroundings for others of their kind, and others NOT of their kind. They may wait until they have sufficient numbers to launch an attack on your body, or to coordinate effective mining of a nutrient source. But bacteria don’t have eyes, ears, or a mouth; they cannot see, hear, or speak. So how do they tell who is out there?

The peril of the tennis ball
Time to use your imagination, folks. Imagine you are in a windowless room. The door is closed. You are wearing a blindfold and earplugs. You cannot speak. In your hand is a fuzzy tennis ball. When you throw the tennis ball, it bounces off the walls until, eventually, it stops. Think about the chances of the ball ricocheting off a wall and hitting you in the head.

Now remember: you cannot speak, you cannot hear, you cannot see. But, if I put another person in the room with a tennis ball to throw, do you think you’d be able to tell you were not alone in the room? Maybe. How about if I dropped in TEN people, each with one tennis ball? How often do you think you’d be smacked square in head?

It probably seems strange to imagine all this blindfolded tennis ball throwing, and I’m pretty sure it won’t give you a better understanding of human politics. But if you understand how you’d be able to sense the presence of more people in the room based on how often you got a tennis ball concussion, you understand the microbial behavior called quorum sensing.

Bacteria don’t throw tennis balls, they “throw” chemical signals
The tennis ball in our thought-experiment represents a quorum-sensing signal. These are chemical compounds that bacteria can “throw” out into the environment, and “catch” if they hit the cell. In this way, bacteria can sense if they are relatively alone, or if they are surrounded by thousands of others.

If you play around with the tennis ball room scenario, you can start to envision more complex issues with quorum sensing. Can you imagine ways to trick the bacteria into thinking they were not alone? Or trick a crowd of bacteria into thinking they were all alone?

Monday, January 25, 2010

Microbial Grappling Hooks

It's a common theme for my view of microbes: for many real-world problems, microbes have already developed a solution.

Want to turn biomass into fuel? Microbes can do it!
Want to seed clouds for rain? Microbes can do it!
Want to move around using a grappling hook? Microbes can do it!

I've had the honor of contributing a blog entry to the delightful blog "Small Things Considered" on the topic of microbial grappling hooks, known more technically as "Type IV pili." It's basically a rope or filament that is sticky at the end. The bacteria can extend this filament out of the cell, and if the sticky end catches on something the microbe can pull itself along by reeling the filament back in. This is just one of many fascinating structures bacteria can use to interact with the world around them.

If you want a little more technical detail on how Type IV pili work, check out my "Small Things Considered" blog entry on the subject!

Thursday, December 31, 2009

Nature wins by a hair

When I first started doing lab work, I found all the specialized equipment quite glamorous. Especially the cold room—basically a walk-in fridge—which always billowed out fog when you opened the door and reminded me very much of the embryo storage room in Jurassic Park. In my lab, we’ve got centrifuges large and small, precision pipettors for measuring out droplets of chemicals, and lots of vials and beakers. In fact, there are whole companies focused on providing labs like ours with expensive, specialized equipment.

But if you look closely in every lab, you’ll find very normal items pressed into scientific service. After all, we scientists are in the business of innovation. In fact, some tools are actually the result of Mother Nature’s innovation, not ours. My favorite examples of nature-made scientific tools are cat whiskers and human eyelashes.

Some scientists study proteins by crystallizing them. One of the challenges of this approach can be getting BIG crystals to form. So sometimes big crystals are formed by micro-seeding a solution with smaller crystals. This requires a very small implement to pick up that small crystal (seed crystal). To this day, scientists sometimes use cat whiskers for the task. They are fine enough to grab a small crystal as you drag the whisker through the solution.

Another set of researchers works on the tiny nematode (worm-like creature) Caenorhabditis elegans. When your research subject is the about the size and length of an eyelash, how do you poke, prod, and transfer such a creature? With a human eyelash, that’s how.

It is a bit humbling that, despite all the sophisticated lab equipment available, sometimes the best tool for the job is something nature created!

Thursday, December 17, 2009

Our bodies, ourselves, our microbial ecosystems

Winter has finally and unquestionably hit Madison, hard. Staring out at the wintry landscapes I’ve been reminded of how harsh and ever-changing a smaller set of landscapes—our bodies—can be.

Just as we live on a planet with different terrains and environments, microbes live on, and in, the human body. As you can imagine, some areas of your body are more forgiving than others. Your mouth is a great place to get food, but with all that saliva it can be hard for a microbe to STAY there. Your skin can be welcoming where it is moist (like your armpits or between your toes) but challenging where it becomes a dry, cragged desert around your elbows. And of course, there is your digestive tract, a warm, nutrient-rich home for millions of microbes.

Though all this probably sounds a bit creepy and makes you want to take a shower, please remember that living with microbes is the healthy norm. They were here long before we arrived on the scene: my friend Dr. Mark O. Martin has a saying about this: “First to evolve, last extinct” I believe. But I digress!

When it comes down to sheer numbers, scientists have estimated that in your body there are ten times as many bacterial cells as human cells. Another motto comes to mind: “You are born 100% human and will die 90% bacteria.”

So, who are all these microbes are and what are they doing with our bodies?

A new National Institute of Health (NIH) “roadmap initiative” aims to answer this question, or at least BEGIN to answer this question, with The Human Microbiome Project. Scientists across the country will be sampling various sites on the bodies of healthy and diseased individuals to ask “who’s there?” and “what are they doing?” Along the way, we may get some interesting insight into how much our microbes very from body site to body site, person to person, week to week, state to state . . . you get the picture!

Thursday, November 19, 2009

It always comes back to Jurassic Park, doesn't it?

I just got back from a seminar by George Weinstock of Washington University, St. Louis about the human microbiome project. I was planning on doing a blog entry on the human microbiome project--and still will write one--but during the talk I was struck by the amount of data the Wash. U. genome sequencing center was producing, and how a huge percentage of the talk centered on the challenges of storing and processing all that data.

For example, the center needs an additional 4 terabytes of storage each day. They've built an entire storage facility which is in great part air conditioners and electrical equipment to maintain the data storage. It uses the same amount of electrical power it takes to light a New York Skyscraper.

It made me think back to all those Cray supercomputers used to process the ancient dinosaur DNA sequences in that most-influential novel "Jurassic Park" by the late Michael Crichton. The speed of current DNA sequencing technology is blinding in comparison to what those ol' Cray computers would have been capable of. But though the speed of the sequencing has gotten faster, all that data requires a huge space to house the technology to store it.

Wednesday, November 11, 2009

In a world overrun by antibiotics, what are we selecting for?

As a graduate student, I read a lot of self-help books. One of my favorite concepts is from Marcus Buckingham’s “Find Your Strongest Life”:

What does working look like?

It’s a very goal-oriented approach to life. Envision what you want your life to look like, and work backwards from there.

The concept of selection is very similar to the “what does working look like” approach. In my college microbiology class, I was tasked with isolating a microbe—from the environment—that could eat milk (casein proteolysis). So I left an open container of milk out in my dorm room for a week and waited to see what grew. To select for a milk-eating microbe, provide an environment where a milk-eating microbe would do well.

But what does this have to do with the zombie apocalypse that I was rambling on about in an earlier blog entry?

Well, if you want to get humans who are good at surviving zombie attacks, one way to do it would be to flood the world with zombies and see who’s left. If you did that, you’d be selecting for zombie survivors.

But while you would nearly guarantee the remaining humans were zombie-resistant, you would have little control over HOW they were zombie-resistant, or any number of other traits they would possess. You might end up with an excellent marksman, a swift runner, or a violent sociopath. You might find the survivor was just very good at hiding.

So what do antibiotics select for?
When you take antibiotics, you’re basically flooding your microbial world with something deadly. Unless you kill every single microbe, you will select for microbes that survived the antibiotics onslaught. They will survive and multiply in a land empty of competing microbes that used to keep them in check.

I could go on for several more paragraphs about antibiotics, but I’ll try to wrap this up: when you use antibiotics, anything that survives is antibiotic-resistant, but both “good” and “bad” microbes can have that ability. High dosages of antibiotics will kill off more microbes, leaving less to prosper. Using a combination of antibiotics would be like unleashing zombies on the world and then following it up with vampires: while there are citizens uniquely skilled at surviving either monster, there are far fewer individuals who can survive both.

So what happens if the world is full of violent criminals and suddenly zombies kill off a huge portion of civilized society, including law enforcement? Do you think a bad guy or two would survive? Would anyone left standing be able to keep them in check?

Friday, November 6, 2009

Tales from Home Economics UPDATE

After I posted my "Tales from Home Economics" entry, I received an e-mail from my mother-in-law Ellen (her description of yeast producing gas was the feature of that post). Thankfully she was happy about me putting her words on my blog (I have to admit I didn't check beforehand. I am a poor journalist!).

Now, I've never been in her class when she gives the description, so I was excited to get more specific information on what she tells her students about yeast:

When I tell the kids about the yeast they are about to use, I tell them they will first give the yeast a bath and then give the yeast a snack and then the burps come . . . Then I tell them to look very closely after they pour the yeast into the water and maybe they can see the yeasts smiling back at them!!! These poor kids will have a twisted science education by the time they leave my class!

Actually, I think a twisted science education may be just what students need to get excited about science. I think sometimes we get the impression that science only happens in laboratories, and that we need advanced degrees to understand it. But science happens everywhere, and with a little imagination we can understand even the things we can't see with the naked eye.

Although hopefully I won't see the yeast smile before I put them in the oven!

Thursday, October 29, 2009

Tales from Home Economics

I come from a family of teachers. The newest addition to my teaching family is my mother-in-law Ellen, who teaches Home Economics to middle school students. As you can imagine, she sometimes has to get REALLY creative to hold the attention of that age group!

Now, cooking often involves a bit of microbiology, like using yeast to make bread dough rise. Many of Ellen's students are indeed surprised to learn that they are adding LIVE MICROBES to the dough. Some even feel bad about killing so many microbes to make a loaf of bread. But how do yeast make the dough rise? The explanation Ellen gives is this:

The yeast eat sugars in the dough and 'burp' or 'fart' out gas.

Can you imagine the expressions on her students' faces? Her statement is accurate, in the same way good soil is really made up of worm poop. For better or for worse, when microbes are used in food products you will end up eating something that has been excreted from a microbe. Thank goodness it is all so delicious!

Sunday, October 25, 2009

What can the zombie apocolypse teach us about microbiology? Part 1

You may not have known it, but Madison is both an epicenter of top-notch microbiology research AND zombie rights. The latest zombie lurch organized by COLD (Coalition of the Living Dead) inspired me to talk a little about what zombies can teach us about microbiology. What's on my BRAAAAIIIIN today are the concepts of fitness and selection.

In the latest zombie flick "Zombieland" the protagonist is a neurotic introvert, and he credits his success in a world overrun by zombies to his obsessive adherence to a set of survival rules and a lack of friends who could turn into zombies and devour him. His traits did not make him very popular or successful in the pre-zombie world.

A simple way to think of fitness is the capability to persist and continue your species. Based on this definition, our nerdy protagonist was not very fit, was he? He didn't have many resources and he certainly wasn't a hit with the ladies.

But then the world changes, and zombies kill off a huge portion of what was once considered a normal, healthy population. Under this different set of demands--under different selection--he is left to prosper.

In summary, different environments can select for different traits. As long the selection doesn't kill off ALL individuals, then those that possess the traits endure the selection and subsequently reproduce would be considered the most fit.

I think you'll find cinematic history is full heroes and heroines that had traits that helped them survive very unusual situations!

COMING SOON IN PART 2: In a world overrun by antibiotics, what are we selecting for?

Friday, October 23, 2009

The Sweet Sound of Microbiology

As a fiddle enthusiast, I felt compelled to link you to an inspiring story: fungi are being used to age modern wood into Stradavarius-quality wood, and create an award-winning bioviolin:

Fiddling with Fungi

Not only can microbes perform simple chemical reactions efficiently, they can also perform complex, almost mysterious aging processes to give soy sauce its flavor and violins their timbre. How sweet the sound of microbiology can be!

Tuesday, October 20, 2009

Why use microbes to make biofuels?

Some fuels are easier to access than others. Biomass, for instance, represents a great deal of potential energy that’s tied up in very strong chains of molecules, such as cellulose. To get access to that energy, what you need is a molecular wood chipper: something that can break down tough chains into molecules we CAN use, like ethanol.

The problem: breaking down tough, energy-containing compounds into useable fuel sources.

The solution: microbes (bacteria, yeast, algae, etc.)


You may be asking yourself: why use microbes to break these things down? Don’t we have chemicals that can do the same thing?

I’d answer your question with another question:

Why do we use microbes for making beer, or cheese? Why didn’t your grandma wheel in a tank of gas to bubble into the bread dough and make it rise? You’d probably say “because it’s easier” and you’d be right. She’d sprinkle in some yeast (microbes) to get the dough to rise. Humans and microbes have a rich, delicious history together when it comes to food, but the idea of using microbes to process biomass into biofuels is, by comparison, quite new.

Microbes are tiny toolkits that can break down molecules or build new ones—often more efficiently than a chemist in a lab can. A microbe’s toolkit has developed over endless generations to be as cheap and effective as it can be. So why reinvent the wheel? Just as silk worms were harnessed by humans to create raw silk for fabrics, we can use microbes to perform complicated processes under simple conditions.

Wednesday, October 14, 2009

Just getting started!

It's a brave new adventure for a rogue graduate student: a science blog!

I came up with all sorts of clever names for the blog, like "The Sound of Science" and "Simply Science" but amazingly, the internet is chock-full of cleverly-named science blogs and podcasts. In the end, I found that "Tiny Topics" was not YET taken.

Undoubtedly, "Tiny Topics" will not be the most creative, most in-depth, or most up-to-speed science blog/podcast. My goal is to craft small morsels of science that don't take up much of your day to absorb, but might change the way you view the world around you (especially the parts you can't see).

"Tiny Topics" is all about small science for a great big world. Enjoy!