Converting Between Gapped and NonGapped DNA Coordinates in R

I've been needing to convert coordinates in gapped DNA alignments back and forth to coordinates in the nongapped sequence a lot recently. For example, the T in AC--TGA--A is in the 5th position but in the gapless sequence ACTGAA it is 3rd. My first few tries (counting chars in regex'd substrings) at programming up a decent converters ended up not working very well with large datasets. Since I had to do it with 50,000 positions in a sequence with 2 million letters, I was running into a little trouble. But it ended up actually being a pretty easy problem in R so I thought I'd post it up in case anybody else is running into something similar. Also it's a pretty good example why programming in R can be fun.

R:
  1. gap2NoGap<-function(gapSeq,coords){
  2.    gapSeqSplit<-strsplit(gapSeq,'')[[1]]
  3.    nonDash<-gapSeqSplit!='-'
  4.    newCoords<-cumsum(nonDash)
  5.    return(newCoords[coords])
  6. }

So the function takes a gapped sequence and the gapped coordinates. It splits the gapped sequence into an array of single characters and finds which ones are not -'s. It then takes the cumulative sum at each element in the array (TRUE evaluates as 1 and FALSE as 0). This gives an array where each element gives the new gap-free coordinates. So the function just returns the appropriate new coordinate for each old coordinate.

R:
  1. noGap2Gap<-function(gapSeq,coords){
  2.    gapSeqSplit<-strsplit(gapSeq,'')[[1]]
  3.    newCoords<-which(gapSeqSplit!='-')
  4.    return(newCoords[coords])
  5. }

This opposite conversion function again takes the gapped sequence and appropriately the nongapped coordinates. It splits the gapped sequence into an array of single characters and finds the indices of the characters which are not -'s. Since we only stored the indices of nongap characters, this array gives the gapped coordinates for each nongap letter. So again the function can just returns the appropriate new coordinate for each old coordinate.

These ended up being pretty elegant in R (once I finally figured them out).

Bioinformatics
Biologist
Programmer
R

Comments (3)

Permalink

Functional Metagenomics: Sequence Everything and Let DNA Sort The Functions Out

ResearchBlogging.org

One of the cool things you can do with the high throughput DNA analysis of pyrosequencing, is to collect a sample from the environment, isolate the DNA from everything in it and sequence it. Then you can match the DNA up with known sequences and see what sort of microbes you had. Dinsdale and a bunch of coauthors collected the data from a bunch of such studies. They managed to find 45 bacterial samples and 42 viral samples from 9 broad environmental classifications. You can see all the different samples the authors pooled together (circles microbial and squares viral).

Locations of metagenomic samples from Dinsdale et al.

The interesting thing about this study was that instead of looking at the taxonomy of the critters as usual, they looked at the function of the genes. By simply looking at what the genes do, the researchers hoped to get a feel for what activities were going on in that environment without necessarily having to identify the species of the bacteria and viruses. To do this, they fed their 14.5 million sequences (pyrosequencing sure can generate data) into the SEED database, a big collection of genes which have been assigned to functions (for example membrane transport or sulphur metabolism) by experts. They were able to match 1 million of the bacterial and 500,000 of the viral sequences to previously identified gene functions.

It might seem odd that they would look at viral DNA since viruses are rather simple and have only a few basic genes. But the researchers were actually looking at bacterial genetic sequences being carried inside viruses. This of course brings up the question of what bacterial DNA is doing inside viruses. It turns out there are a lot of bacteriophage viruses that like to infect bacteria and sometimes these viruses capture some of the DNA of their bacterial hosts and carry it to their next host. Looking at the bacterial DNA present in a viral population gives an interesting look at what types of genes are being passed around between individual bacteria (and even between bacterial species).

So here are the high level classifications of the function of the genes they found for each environment.

Percentages of gene function of bacterial and viral gene function from Dinsdale et al.

It's pretty cool that the viruses were carrying around so much of a variety of bacterial DNA. The authors suggest that motility genes coding for things like flagella and cilia (which could help the bacterial host spread the virus further) were enriched in the viral samples but it seems a bit hard to say that for certain without a bit more analysis.

A useful way to look at huge masses of data, like their 1.5 million matches, is to try and reduce all the different counts in the functional categories into a couple of condensed variables. This can be seen in the next couple plots. They could use a little explaining. Bacterial sequences are on top and viral sequences on the bottom. Lines show how the various functional categories have been condensed into the x and y variables. For example, samples that contained lots of genes for making cell walls will tend to be at the top of the plot in the bacterial samples and tend not to have many genes for respiration.

Canonical discriminant function analysis of bacterial and viral gene function from Dinsdale et al.

It's pretty cool to see how the various environments clustered with other samples from the same environment. For example, all the yellow diamond fish farm samples ended up on the right side of the bacteria graphs even though they were sampled independently. It appears that functions seem to correlate with environmental conditions. For example, the fish food at the fish farms contained a lot of sulfur supplements and the bacteria from those samples were rich in sulfur metabolism genes and the bacteria from corals contained many different respiration genes to deal with the highly variable oxygen concentrations found there. Dinsdale and her coauthors go so far as to suggest that gene function may provide a better indicator of environment than the taxonomy of the bacteria present.

The paper did have a little trouble in the math in one part but the authors already have a correction in for it so it's really not worth worrying about. Overall, it was a pretty interesting story and a good example of stuff to do with a sequencing machine (also it must have taken a good bit of work to collect all that data together from all those authors).

References

Elizabeth A. Dinsdale, Robert A. Edwards, Dana Hall, Florent Angly, Mya Breitbart, Jennifer M. Brulc, Mike Furlan, Christelle Desnues, Matthew Haynes, Linlin Li, Lauren McDaniel, Mary Ann Moran, Karen E. Nelson, Christina Nilsson, Robert Olson, John Paul, Beltran Rodriguez Brito, Yijun Ruan, Brandon K. Swan, Rick Stevens, David L. Valentine, Rebecca Vega Thurber, Linda Wegley, Bryan A. White, Forest Rohwer (2008). Functional metagenomic profiling of nine biomes Nature, 452 (7187), 629-632 DOI: 10.1038/nature06810

Biologist
Statistician

Comments (1)

Permalink

Can You Sequence a Bacteria’s Entire Genome Overnight?

ResearchBlogging.org

Science postings here have been a bit light recently. I got a new job a bit back and it's been keeping me pretty busy catching up on DNA stuff I haven't really used since undergrad. Things are finally starting to settle down so I figure I'll write a few posts about stuff I've been learning. So a lot of my job is helping to analyze the data from a shiny new DNA sequencer. Before I started, I didn't know how far sequencing had improved in the last several years.

Until recently, most sequencing was done with Sanger sequencing. This type of sequencing produces about 100,000 bases per run and requires the DNA to be first grown in bacteria before sequencing. Then Margulies and a bunch of coauthors from a company called 454 published a paper in Nature and produced a commercial sequencer capable of sequencing 250 times as many bases per run. To do this, they used a technique called pyrosequencing. The process is pretty cool as shown in this figure from the paper.

Pyrosequencing bead preparation from Margulies et al 2005

The figure goes in a clockwise direction. On the top left, DNA is fragmented into many pieces. Next in the upper right, the DNA is bound to tiny beads, one piece to a bead and the beads are isolated in little bubbles where the attached DNA is copied millions of times. This leaves each bead with millions of copies of a single piece of DNA. Importantly all these DNA are single stranded and looking for a matching strand. In the bottom right, the beads are deposited one to a well in a fiber optic slide. Then helper immobilization and enzyme beads fill in the wells in the bottom left. You can see some real images of this process in their next figure.

Beads droplets and wells for pyrosequencing from Margulies et al 2005

The left photo shows one of the beads (thin arrow) in a droplet (thick arrow). The bead is about 1/30 mm in diameter and the droplet about 1/10 of a mm. On the right is a electron micrograph of the wells on the fiber optic slide where beads are trapped. Each well is about 1/20 mm wide.

Once all this has been setup, they get to the real pyrosequencing part. With all the beads firmly nested in their separate wells, the sequencing machine takes turns flowing the A, T, C and G nucleotide building blocks of DNA over the wells. Because the DNA bound to the bead is single stranded, these new nucleotides begin building the second strand nucleotide by nucleotide. The trick to this technique (and where its name comes from) is that when a nucleotide is incorporated pyrophospate is released. This pyrophosphate is converted to ATP (a very common energy storage molecule) by enzymes on the helper beads. The ATP then fuels a bioluminescent luciferase enzyme (like in fireflies) to produce light. A 16 megapixel camera captures this light and the number of nucleotides incorporated can be estimated from the brightness. By cycling through T, A, C, and G around 40 times, the machine can count the number of bases incorporated in each step and get an average read length of about 110 bases. You can see that process in the following figure with (a) the nucleotides ready to flow over (b) the wells with their beads and produce light which is captured by (c) the camera and analyzed.

Pyrosequencing machine from Margulies et al 2005

The authors were a little worried whether the shorter 110 base sequences would be useful. So they tried to sequence a bacteria, Mycoplasma genitalium. Although it's sort of an easy target since this bacteria has a tiny 580,000 base genome, they did get an extremely thorough 40x coverage from a single run and were able to successfully assemble an accurate sequence of the genome.

The Rest of the Story

What they don't mention in the paper is that one sequencer costs $500,000. Each run costs about $10,000 in chemicals and reagents (still cheaper than Sanger sequencing). Perhaps unsurprisingly at those prices, the 454 company responsible for this paper was later bought (for $150 million) by Roche, one of the largest pharmaceutical companies in the world.

Reminiscent of many gadgets, early adopters buying the sequencer from this paper got kind of screwed because 454 soon came out with a new improved model able to generate sequences twice as long. It looks like they'll soon releasing an upgrade for the second model that should allow 2-4 times as many reads and again double the length (resulting in 8-16 times as many bases as this Nature paper).

The paper is a little short of pictures direct from the sequencing process so here's a couple from a recent run. First, here's an example of a single flow (a T nucleotide [no visible difference from other nucleotides]) showing 13 lanes of a 16 lane slide (you can divide the slide into portions to share the run [and the cost]). You might notice a pattern in some of the lanes. That's because lanes 1-4 and 9-12 were tests to see how much DNA per bead produced the best results with the lowest concentration on the left.

Example of sequencing lanes from 454 pyrosequencer

And here's a close up of a single lane during a flow (a C this time). Each bright dot signals incorporation of a C nucleotides. Brighter dots mean there were several C's in a row.

Closeup of sequencing lane from 454 pyrosequencer

So a very cool technology. It's pretty amazing that an entire bacterial genome (up to about 1.5 million bases [soon to be 6 million]) can be sequenced in one shot. Unfortunately, animals including humans have genomes of 2 billion or more bases so no one will be sequencing any individuals or endangered species without a few hundred thousand dollars to burn. But a little over ten years ago, you could get published in Science for sequencing the M. genitalium and here it was used as a simple test. It'll be interesting to see where sequencing technology stands ten years from now.

References

Margulies, M., Egholm, M., Altman, W.E., Attiya, S., Bader, J.S., Bemben, L.A., Berka, J., Braverman, M.S., Chen, Y., Chen, Z., Dewell, S.B., Du, L., Fierro, J.M., Gomes, X.V., Godwin, B.C., He, W., Helgesen, S., Ho, C.H., Irzyk, G.P., Jando, S.C., Alenquer, M.L., Jarvie, T.P., Jirage, K.B., Kim, J., Knight, J.R., Lanza, J.R., Leamon, J.H., Lefkowitz, S.M., Lei, M., Li, J., Lohman, K.L., Lu, H., Makhijani, V.B., McDade, K.E., McKenna, M.P., Myers, E.W., Nickerson, E., Nobile, J.R., Plant, R., Puc, B.P., Ronan, M.T., Roth, G.T., Sarkis, G.J., Simons, J.F., Simpson, J.W., Srinivasan, M., Tartaro, K.R., Tomasz, A., Vogt, K.A., Volkmer, G.A., Wang, S.H., Wang, Y., Weiner, M.P., Yu, P., Begley, R.F., Rothberg, J.M. (2005). Genome sequencing in microfabricated high-density picolitre reactors. Nature DOI: 10.1038/nature03959

Biologist

Comments (6)

Permalink

Cancer Fighting Bacteria

ResearchBlogging.org

I was doing a bit of background reading and came across an interesting paper about mutating normal bacteria into cancer-fighting bacteria. The paper centers around a single gene called inv (short for invasin) that can give an otherwise mild-mannered noninfectious bacteria the ability to invade cells.

Now this might seem like a pretty bad idea since there are probably enough infectious bacteria in the world already but this was only the first step of the research. Anderson and colleagues attached inv to a genetic switch (normally used for bacterial metabolism control) that turns on when arabinose (a type of sugar) is present. Unfortunately this switch was a little leaky. So even bacteria without arabinose were still infectious. Not ones to let that stop them, the researchers took out the ribosome (protein-making organelle) binding region of the gene, randomly mutated it and tested to find bacteria that were off by default but still able to turn on.

Once they got that working, they decided to attach a sensor to the infective gene. Bacteria often do things like switch metabolisms when they run out of oxygen. The researchers picked one of the bacteria genes that turns on when oxygen is low and replaced the arabinose switch from the previous bit with the oxygen sensing switch from this gene. Again the switch was leaky and they had to mutate it so it stayed off by default. Once that was done they had a bacteria that was only invasive in anaerobic environments. That's pretty cool because tumors are often anaerobic (since they're big lumps of fast growing dense tissue).

Plasmid for density dependent infectious bacteria

To go even further, the researchers tried to create bacteria that only turn on when there are many bacteria in one location. This will be useful because tumors often have higher concentrations of bacteria due to leaking nutrients and poor immune response. By creating a switch that only turns on when a bunch of bacteria are present, the bacteria can be further targeted to cancerous cells. To do this they used a gene from an ocean-dwelling bacteria that only turns on when many bacteria are present (the ocean bacteria uses the gene to detect when it has reached the light organ of squid). It seems odd that bacteria can communicate but it comes down to a simple mechanism made up of two genes. One gene encodes an enzyme that makes a chemical, called AI-1, that easily disperses in and out of the cell membrane. The second encodes a gene activator that is turned on by high concentrations of AI-1. When there are many bacteria, the environment becomes rich in AI-1 and the gene activator turns on even more production of AI-1 and gene activators. This positive feedback causes creates a sensitive switch that switches quickly from all off to all on when bacterial concentration crosses a certain level. By linking these genes to the infectious inv gene, the researchers created a bacteria that was only infectious when in high concentrations.

So now we have bacteria that might be able to selectively infect tumor cells. By combining this selective invasiveness with cell killing or immune response activating mechanisms, bacteria could become helpful tools for treating cancer (although there is still a pretty long way to go). The paper makes it look easy but that must have taken a good bit of work to get it all working so nicely. They ended up using DNA from three different bacteria species and many different bacterial systems. It's always really cool to see how scientists can take DNA "parts" and combine them together to create new and useful functions and even edit the DNA directly when the parts don't fit correctly.

I guess the next step in the research is to figure out how to get a bacteria to sense both an anaerobic and a high density environment. This might be a bit tricky since the two sensors would have to interact but I see some of the same researchers also have a paper on creating bacterial AND gates so I'll have to give that one a read too.

Reference

Anderson, J., Clarke, E., Arkin, A., Voigt, C. (2006). Environmentally Controlled Invasion of Cancer Cells by Engineered Bacteria. Journal of Molecular Biology, 355(4), 619-627. DOI: 10.1016/j.jmb.2005.10.076

Biologist

Comments (3)

Permalink

WP_Texticon

Matrix-like Texticon example Letters Texticon example DNA-like Texticon example

I realize I'm getting in the dead horse beating side of automatic avatar creation plugins but brainsolid asked for a plugin to generate binary avatars that looked like the text from the matrix and I figured it wouldn't take too long to change WP_Identicon over to it. Of course, then other things came up and I managed to take quite a while to get around to it but it's done now so here is WP_Texticon. It generates avatars with an array of colored characters. It's sort of hard to describe so it's probably easier to just show a few examples.

So I guess it's mostly for anyone that likes that text in the Matrix, writing about code (with 0 and 1's or 0-9 and A-E if you want to get fancy) or biologists (give every commenter their own DNA sequence with ATCG) or maybe general literature (with some random letters and a white background).

Features

  • Dynamically generated avatars for each commenter
  • Matrix/DNA/Binary-like text array icons
  • Customizable character selection
  • Gravatar support
  • No theme edits necessary

Current Version:

WP_Texticon

Installation instructions:

Unzip wp_texticon.zip. Upload wp_texticon.php and the texticon folder. Make sure the texticon folder is writable. If your unzipping program creates a wp_texticon folder please only upload the contents (wp_texticon.php and the texticon folder). That should be it. Texticons should now appear next to your commenter's names.

You can adjust the background colors, the type and number of characters making up the Texticons and CSS in the Texticon Control Panel. If you'd like to change the fonts used for the characters, add or remove any Truetype Fonts (files that end in .ttf) you'd like to the texticon/fonts folder. You can also clear the Texticon image cache in the control panel.

For Advanced Users:

For even more control, you can disable the automatic placement in the Texticon Control Panel and add an Texticon to any comment with texticon_build($comment->comment_author_email, $comment->comment_author);. For example, find the comments.php of your current theme (it should be in the folder wp-content/themes/[currentThemeName]/). Open it up and look for something similar to foreach ($comments as $comment). Inside this loop there should be code that displays the comment author's name or metadata like <p class="comment-author"> or <p class="comment-metadata">. Just before all this enter:
<?php if (function_exists(texticon_build)) echo texticon_build($comment->comment_author_email, $comment->comment_author); ?>
If you would prefer to base the Texticons on the commentor's IP address instead of the commentor's email just replace $comment->comment_author_email in the above with $comment->comment_author_IP.

Change Log:

  • v0.52 3-27-2007:
    • Fixed missing gravatar bug
  • v0.51 3-27-2007:
    • First Public Version

Blogger
Programmer
Web

Comments (8)

Permalink