title: How to perform basic Multiple Sequence Alignments in R?
body: <p>(I've tried asking this on <a href="https://www.biostars.org/p/4491/" rel="nofollow noreferrer">BioStars</a>, but for the slight chance that someone from text mining would think there is a better solution, I am also reposting this here)</p>
  
  <p>The task I'm trying to achieve is to align several sequences.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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)</p>
  
  <pre><code>                     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
  </code></pre>
  
  <p>Here is an example code to reproduce the above example:</p>
  
  <pre><code>ATCG &lt;- c("A","T","C","G")
  set.seed(40)
  original.seq &lt;- sample(ATCG, 30, T)
  seqS &lt;- matrix(original.seq,200,30, T)
  change.letters &lt;- function(x, number.of.changes = 15, letters.to.change.with = ATCG) 
  {
      number.of.changes &lt;- sample(seq_len(number.of.changes), 1)
      new.letters &lt;- sample(letters.to.change.with , number.of.changes, T)
      where.to.change.the.letters &lt;- sample(seq_along(x) , number.of.changes, F)
      x[where.to.change.the.letters] &lt;- new.letters
      return(x)
  }
  change.letters(original.seq)
  insert.missing.values &lt;- function(x) change.letters(x, 3, "-") 
  insert.missing.values(original.seq)
  
  seqS2 &lt;- t(apply(seqS, 1, change.letters))
  seqS3 &lt;- t(apply(seqS2, 1, insert.missing.values))
  
  seqS4 &lt;- apply(seqS3,1, function(x) {paste(x, collapse = "")})
  require(stringr)
  # library(help=stringr)
  all.seqS &lt;- str_replace(seqS4,"-" , "")
  
  # how do we allign this?
  data.frame(Real_sequence = seqS4, The_sequence_we_see = all.seqS)
  </code></pre>
  
  <p>I understand that if all I had was a string and a pattern I would be able to use </p>
  
  <pre><code>library(Biostrings)
  pairwiseAlignment(...)
  </code></pre>
  
  <p>But in the case I present we are dealing with many sequences to align to one another (instead of aligning them to one pattern).</p>
  
  <p>Is there a known method for doing this in R?</p>