title: R - Create biosequence from a list of sequences with sample()
body: <p>I have a list of biosequences that are very similar. Firstly I want to create a distance matrix NxN and then I want to generate another sequence with sample() that will be also quite similar to the others but not identical. I try to create the sequence by using the sample fucntion but it returns a copy of my initial list. Lastly, I want to update the matrix to contain the distances of the generated sequence. Is there a way to simply bind the new distances or I need to create a new one?</p>
  <pre><code>sequences &lt;- read.fasta('/media/losve/Νέος τόμος/Scripts/bnp54/ergasia 2/histone4.fa')
  seqnames &lt;- c(&quot;human&quot;, &quot;mouse&quot;, &quot;fly&quot;, &quot;plant&quot;, &quot;cow&quot;, &quot;worm&quot;, &quot;chick&quot;, &quot;rat&quot;,&quot;yeast&quot;, &quot;frog&quot;)
  myseqs &lt;- list() 
  for(i in 1:length(sequences))
  {
    myseqs[i] = toupper(paste(sequences[[i]], collapse=''))
  }
  
  names(myseqs) &lt;- seqnames
  dist_matrix &lt;- matrix(, nrow = length(sequences), ncol = length(sequences))
  
  for(i in 1:length(sequences))
  {
    for(j in 1:length(sequences))
    {
    dist_matrix[i][j] &lt;- pairwiseAlignment(myseqs[i], myseqs[j], substitutionMatrix = &quot;BLOSUM50&quot;)
    }
  }
  
  new_sequence &lt;- sample(myseqs, replace = TRUE )
  </code></pre>