[BioC] replace nucleotide at fixed position in a DNAStringSet object

Valerie Obenchain vobencha at fhcrc.org
Mon Sep 16 18:46:14 CEST 2013


Hi,

On 09/13/2013 07:13 AM, Robert Castelo wrote:
> hi!!
>
> i'd like to know if there is some efficient way to replace a nucleotide
> at a fixed position in a DNAStringSet object.
>
> let's say we have the following toy DNAStringSet object with 3 DNA
> sequences:
>
> x <- DNAStringSet(c("ATGACCACG", "ACTGGGGAA", "GCCGATGCG"))
> x
>    A DNAStringSet instance of length 3
>      width seq
> [1]     9 ATGACCACG
> [2]     9 ACTGGGGAA
> [3]     9 GCCGATGCG
>
> and a DNAStringSetList object with the following 3 nucleotides
>
> y <- DNAStringSetList(DNAStringSet("G"), DNAStringSet("C"),
> DNAStringSet("C"))
> y
> DNAStringSetList of length 3
> [[1]] G
> [[2]] C
> [[3]] C
>
> i'd like to replace the, let's say, fourth nucleotide along the DNA
> sequences in 'x' by those in 'y'. i can imagine how to do it coercing
> back and forth to character and so on but i guess there must be some
> more efficient way to do it.

I don't think so. XString objects are immutable. The data are accessed 
through an external pointer to an environment where they are 
written/stored as raw. To subset/replace positions in 'x' with values 
from 'y' you would need to go through the 'as.character' conversion and 
create a new DNAStringSet.

I've cc Herve in case I've gotten this wrong or he has a different 
solution to the problem.

Valerie




my interest come from the fact that the
> DNAStringSet object i have to work with can have many DNA sequences.
>
> thanks!!
> robert.
>



More information about the Bioconductor mailing list