Thanks for your generous help!
• 0 views
•
link
I've got a GRanges object , but I don't know how to transfer it into fasta with tx_name. I tried to extract sequence using writeXStringSet(), but the result didn't have the tx_name. Can anybody tell me how to solve this?
seq <- getSeq(Hsapiens,gr)
writeXStringSet(seq,file="result")
but the result didn't have the tx_name, like follows > ATCGATCG
I want to have the tx_name as follows
ENST00000252835.5 ATCGATCG
You just need to make sure the names are append to the seq object. This can be done easily using: names(seq) <- gr$tx_name
library(GenomicFeatures)
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
library(BSgenome.Hsapiens.UCSC.hg38)
Hsapiens <- BSgenome.Hsapiens.UCSC.hg38
## random tx subset
tx <- transcripts(TxDb.Hsapiens.UCSC.hg38.knownGene)
gr <- tx[sample(seq(length(tx)),5)]
## extract sequence
seq <- getSeq(Hsapiens,gr)
## add names
names(seq) <- gr$tx_name
writeXStringSet(seq,file="result")
Thanks for your generous help!
Log in to answer this question.
Can you show some content of that GR?
I wanna to get a fasta file as follows
Please use the formatting bar (especially the

codeoption) to present your post better. I've done it for you this time.Thank you!