write.fasta() fails when writing sequence with only one amino acid

Issue #83 resolved
Former user created an issue

The Rscript:

write.fasta(ids = fasta1$id,seqs=fasta1_alcol1,file=opt$out_fasta1)

works fine with multiple amino acid per sequence, but when there is only one amino acid per sequence, it gives an error:

Error in seqs[i, ] : incorrect number of dimensions Calls: write.fasta -> cat Execution halted

Is this a bug.

Comments (7)

  1. Xinqiu Yao

    Hi,

    Make sure your alignment is still a "matrix" even if there is only one residue in each sequence. Try

    write.fasta(ids = fasta1$id,seqs=matrix(fasta1_alcol1, ncol=1),file=opt$out_fasta1)
    

    Let us know if it is still problem.

  2. Lars Skjærven

    Should work if you keep seqs as a matrix as Xinqiu suggests. drop=FALSE might be of help:

    aln <- read.fasta(system.file("examples/hivp_xray.fa",package="bio3d"))
    write.fasta(ids=aln$id, seqs=aln$ali[,1, drop=FALSE], file="test.fasta")
    

    I've noticed earlier that reading the same one-column fasta file causes an error though:

    read.fasta("test.fasta")
    Error in `rownames<-`(`*tmp*`, value = c("d1hhp__", "d1nh0a_", "d1nh0b_",  : 
      length of 'dimnames' [1] not equal to array extent
    
  3. Xinqiu Yao

    The drop option is cool! Thanks Lars. read.fasta() really doesn't work with one-column fasta file. So let me fix it.

  4. Migun Shakya

    I have setup an Rscript so i dont always know if the fasta1_alcol1 will always have 1 column. So, i cant specify ncol=1. However, i did try with just

    seqs=matrix(fasta1_alcol1)
    

    but now its only writing one column even when there are multiples.

    Thanks

  5. Log in to comment