0

I have an RNA string on text format file. I want to import/read it from the txt file for translate function of Biostrings package in R.

I tried readRNAStringSet before but this function reads FASTA and FASTQ formats, however, my file is not FASTA or FASTQ but it's txt and I wanna read from that one.

In my file, there's no quotation mark but after the last code, there's space. Eventually, When I read this RNA string, I want to translate it to its protein amino acids using "translate" function in Biostrings package.

As an example, I have the RNA string bellow in "txt" file, there's no quotations and no other sign in the file and there's only one string:

AUGCCGGUAAAGCGUGUCACAGAACUCCAUUUACUAUUAUGCCUUUGUGCGGGAGGAAGUUUCAGAAAGUACAUUCAUCC‌​UGGA

Tensibai
  • 15,557
  • 1
  • 37
  • 57
arado1
  • 51
  • 7
  • 6
    Please provide a reproducible example and describe better what you want to achieve. – nicola Sep 02 '15 at 13:05
  • possible duplicate of http://stackoverflow.com/questions/9068397/import-text-file-as-single-character-string – pcantalupo Sep 02 '15 at 13:21
  • I just looked into Biostrings package...you need to use the readRNAStringSet function. Make sure your input file is FASTA or FASTQ formatted – pcantalupo Sep 02 '15 at 13:28
  • Thank you guys for your consideration. here is one example: – arado1 Sep 02 '15 at 14:04
  • AUGCCGGUAAAGCGUGUCACAGAACUCCAUUUACUAUUAUGCCUUUGUGCGGGAGGAAGUUUCAGAAAGUACAUUCAUCCUGGACGCAUCU – arado1 Sep 02 '15 at 14:06
  • Just in a text file. – arado1 Sep 02 '15 at 14:07
  • I tried readRNAStringSet before and exactly my problem is that my file is not FASTA or FASTQ but it's txt and I wanna read from that one. – arado1 Sep 02 '15 at 14:08
  • 2
    @arado1 perhaps you should put these notes as an edit to the original question. That way people do not have to read the comments to see what you want – C8H10N4O2 Sep 02 '15 at 14:22
  • Sorry, I thought that my question is clear. I'd edit it if I could! – arado1 Sep 02 '15 at 15:11
  • @arado1 There's an edit button just under the question... – Tensibai Sep 02 '15 at 15:44
  • Thanks Tensibai. I'll add more explanation. – arado1 Sep 02 '15 at 16:00
  • @arado1 1) prefix people with @ (so we get a notification when you answer) 2) Please use the enter Key and try to write it in paragraphs, as is it's an unreadable blob of text. – Tensibai Sep 02 '15 at 16:42
  • @Tensibai Is it better now? – arado1 Sep 02 '15 at 17:13
  • Much better yes ;) you have my upvote for listening to advices and putting the effort (I just quoted the file content as a last modification, the functions and class type could have been embedded with quotes too, but it's really much easy to read now) – Tensibai Sep 02 '15 at 18:57
  • (last note on So notifications, post author is always notified ;)) – Tensibai Sep 02 '15 at 18:58

1 Answers1

3

You can simply readLines and convert to RNAStringSet afterwards:

> writeLines(c("AUGC", "AGCU", "UUGA", "CGAU"), "foo") # Dummy input
> RNAStringSet(readLines("foo"))
  A RNAStringSet instance of length 4
    width seq
[1]     4 AUGC
[2]     4 AGCU
[3]     4 UUGA
[4]     4 CGAU
zero323
  • 322,348
  • 103
  • 959
  • 935