Question: length of a DNAString
0
gravatar for c.chakraborty
4 months ago by
c.chakraborty110
c.chakraborty110 wrote:

I am doing something extremely basic and stupid. I can call a fasta seq using this

x <- readDNAStringSet(file.choose())

file gets opened, and then I type this

length(x)

[1] 1 But when I use view, I can see nicely that it has 11405 bp. I can use seqinr to get the length, like

length(x[[1]])

But, I can't do anything more, how do I extract the sequence only? And how do I convert it to a DNAString?

ADD COMMENTlink modified 4 months ago by h.mon21k • written 4 months ago by c.chakraborty110
1

type width(x). This would print the lengths of all sequences in DNAstringset object.

ADD REPLYlink modified 4 months ago • written 4 months ago by cpad011210k
1
gravatar for h.mon
4 months ago by
h.mon21k
Brazil
h.mon21k wrote:

The readDNAStringSet() reads a set of sequences from a file into an XStringSet object. To see the help page of the XStringSet-class, use:

?XStringSet

There you will find why length(x) returned 1:

length(x): The number of sequences in x.

For an DNAStringSet object, the function you want is width(). If you want a DNAString, you may extract just one element of the DNAStringSet and assign it to a new variable:

xString <- x[[1]]

Now, length(xString) will show the sequence length.

ADD COMMENTlink written 4 months ago by h.mon21k

This is great, thanks a bunch! I also found a crude solution. If I load the files by ape and then unlist it, and then ask for length, it works!

ADD REPLYlink written 4 months ago by c.chakraborty110
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1711 users visited in the last hour