Entering edit mode
2.3 years ago
margo
▴
40
I have a DNA sequence in SeqFastadna format as a result of seqnir
package in R. I am using the getFrag()
function to extract sequence fragments. For example my SeqFastadna object (f) looks like this:
$genome
[1] "t" "t" "a" "a" "a" "a" "a" "a" "g" "a" "g" "a" "t" "c"
[1] "genome"
attr(,"Annot")
[1] ">genome, complete genome"
attr(,"class")
[1] "SeqFastadna"
When using the getFrag function getFrag(f, 1, 5)
, it prints out unnecessary information. I am only wanting the 5 bases, however this function is printing out other attributes too:
[1] "t" "t" "a" "a" "a"
attr(,"seqMother")
[1] "genome"
attr(,"begin")
[1] 1
attr(,"end")
[1] 5
attr(,"class")
[1] "SeqFrag"
Is there any way where I can just return the bases and have the following output?:
[1] "t" "t" "a" "a" "a"
This won't remove attributes. You can use the
as.character
generic or remove them directlyattributes(frag) <- NULL
.My code produces the desired output, which is of class character and without attributes.
as.character
will not produce the desired output andattributes(getFrag(f,1,5))
is already NULL.From what information they provided the output is a vector, which would be equivalent to the below code that uses a vector of characters as input.
In this case
unlist
won't work since it's not a list.But
as.character
would work (same with setting attributes to NULL).Your code would work if the input was an unaltered
SeqFastadna
object, but that wouldn't match with the OP's output.It is possible that OP didn't provide the full output though, in which case your code would work incidentally.
Indeed, thank you for the clarifications.
The unlist option gave me the desired output. Thank you!