How To Perform Basic Multiple Sequence Alignments In R?
4
5
Entering edit mode
13.9 years ago
Tal Galili ▴ 180

The task I'm trying to achieve is to align several sequences.

I don't have a basic pattern to match to. All that I know is that the "True" pattern should be of length "30" and that the sequences I have had missing values introduced to them at random points.

Here is an example of such sequences, were on the left we see what is the real location of the missing values, and on the right we see the sequence that we will be able to observe.

My goal is to reconstruct the left column using only the sequences I've got on the right column (based on the fact that many of the letters in each position are the same)

                     Real_sequence           The_sequence_we_see
1   CGCAATACTAAC-AGCTGACTTACGCACCG CGCAATACTAACAGCTGACTTACGCACCG
2   CGCAATACTAGC-AGGTGACTTCC-CT-CG   CGCAATACTAGCAGGTGACTTCCCTCG
3   CGCAATGATCAC--GGTGGCTCCCGGTGCG  CGCAATGATCACGGTGGCTCCCGGTGCG
4   CGCAATACTAACCA-CTAACT--CGCTGCG   CGCAATACTAACCACTAACTCGCTGCG
5   CGCACGGGTAAGAACGTGA-TTACGCTCAG CGCACGGGTAAGAACGTGATTACGCTCAG
6   CGCTATACTAACAA-GTG-CTTAGGC-CTG   CGCTATACTAACAAGTGCTTAGGCCTG
7   CCCA-C-CTAA-ACGGTGACTTACGCTCCG   CCCACCTAAACGGTGACTTACGCTCCG

Here is an example code to reproduce the above example:

ATCG <- c("A","T","C","G")
set.seed(40)
original.seq <- sample(ATCG, 30, T)
seqS <- matrix(original.seq,200,30, T)
change.letters <- function(x, number.of.changes = 15, letters.to.change.with = ATCG) 
{
    number.of.changes <- sample(seq_len(number.of.changes), 1)
    new.letters <- sample(letters.to.change.with , number.of.changes, T)
    where.to.change.the.letters <- sample(seq_along(x) , number.of.changes, F)
    x[where.to.change.the.letters] <- new.letters
    return(x)
}
change.letters(original.seq)
insert.missing.values <- function(x) change.letters(x, 3, "-") 
insert.missing.values(original.seq)

seqS2 <- t(apply(seqS, 1, change.letters))
seqS3 <- t(apply(seqS2, 1, insert.missing.values))

seqS4 <- apply(seqS3,1, function(x) {paste(x, collapse = "")})
require(stringr)
# library(help=stringr)
all.seqS <- str_replace(seqS4,"-" , "")

# how do we allign this?
data.frame(Real_sequence = seqS4, The_sequence_we_see = all.seqS)

I understand that if all I had was a string and a pattern I would be able to use

library(Biostrings)
pairwiseAlignment(...)

But in the case I present we are dealing with many sequences to align to one another (instead of aligning them to one pattern).

Is there a known method for doing this in R?

Thanks,

Tal

r sequence alignment multiple • 8.7k views
ADD COMMENT
4
Entering edit mode

I would not attempt to do this in R unless there is already a library for doing so. There are plenty of good stand-alone multiple sequence alignment programs out there - I would just use one of them.

ADD REPLY
0
Entering edit mode
ADD REPLY
2
Entering edit mode
13.9 years ago
Michael 55k

Afaik, there exists no such R package to do it directly from R. In particular the BioStrings package does not contain methods for multiple sequence alignments only for pairwise alignements.

You can read multiple alignments files in different formats using the seqinr package using the function read.alignment.

ADD COMMENT
2
Entering edit mode
13.8 years ago
Gregr ▴ 20

Try the Bio3d R package and install the MUSCLE program separately:

http://mccammon.ucsd.edu/~bgrant/bio3d/html/seqaln.html

ADD COMMENT
1
Entering edit mode
13.9 years ago
Bilouweb ★ 1.1k

I don't know if there is such function in R but multiple alignment is a hard computation task.

That's why all algorithms I know use a heuristic to find a near optimal multiple alignment of sequences.

ADD COMMENT
1
Entering edit mode
13.9 years ago
Thaman ★ 3.3k

It seems like you are using BioStrings package and PairwiseAlignment function which produces the set of objects. Maybe it's better to go through R package Biostrings->MatchAlign again if you want to compute alignment without other applications.

ADD COMMENT
0
Entering edit mode

Thanks Thaman, I imagine I'll use that function (actually pairwiseAlignment).

ADD REPLY
0
Entering edit mode

You are aware that pairwise alignments of many sequences and multiple sequence alignments are two different things?

ADD REPLY
0
Entering edit mode

Hi Michael.

Yes, I am aware of it.

It obviously won't work out of the box, but with some tweaking I might get it to solve my particular problem (which is a bit simpler then complete combination search for full sequence alignment). BTW, I also found the following answer to be useful: http://stackoverflow.com/questions/4497747/how-to-perform-basic-multiple-sequence-alignments-in-r/4498434#4498434

ADD REPLY

Login before adding your answer.

Traffic: 1778 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6