[BioC] no method for coercing this S4 class to a vector

Martin Morgan mtmorgan at fhcrc.org
Mon Mar 11 15:50:21 CET 2013


Hello Martin

      Thanks a lot for your help. For me, if I try without as.character it  
doesnt work.
      But how you show, for you it works
      I realize that you are using format="fastq" and I'm using  
format="fasta"
      I attached the file. But I dont want to use your time any more, you  
already help me a lot.
      I'm going to try to convert to fastq to see if I can get the same  
result as you.

thank you very much

Thiago Maia

On 03/11/2013 07:06 AM, Thiago Maia wrote:
> function () {
>     print(nchar(as.character(seq2[1])))
> }
>
> to execute
> fn1()
>
>
> actually the function became like this
> function (N) {
>      for(i in as.numeric(1:N)) {
>
> print(substr(seq2[i],nchar(as.character(seq2[i]))-2,nchar(as.character(seq2[i]))))
>      }
> }

Hi Thiago -- but the as.character() are not necessary

function (N) {
       for(i in as.numeric(1:N)) {
           print(substr(seq2[i], nchar(seq2[i])-2, nchar(seq2[i])))
       }
}


and remember that R is 'vectorized', so

fn1 <- function(N) {  ## better: function(N, seq2)
       i <- 1:N          ## better: i <- seq_len(N)
       substr(seq2[i], nchar(seq2[i]) - 2, nchar(seq2[i]))
}

so after

     library(Biostrings)
     example(readDNAStringSet)

we have

   > seq2 <- readDNAStringSet(filepath, format="fastq")
   > fn1(10)
HWI-EAS88_1_1_1_1001_499  HWI-EAS88_1_1_1_898_392  HWI-EAS88_1_1_1_922_465
                      "TGT"                    "GAC"                     
"GGT"
    HWI-EAS88_1_1_1_895_493  HWI-EAS88_1_1_1_953_493   
HWI-EAS88_1_1_1_868_763
                      "AAA"                    "CTT"                     
"GCG"
    HWI-EAS88_1_1_1_819_788  HWI-EAS88_1_1_1_801_123   
HWI-EAS88_1_1_1_885_419
                      "CTT"                    "CTT"                     
"GTT"
    HWI-EAS88_1_1_1_941_477
                      "AAT"



-- 
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: rosalind_grph.txt
URL: <https://stat.ethz.ch/pipermail/bioconductor/attachments/20130311/f13ae85f/attachment.txt>


More information about the Bioconductor mailing list