text: user123: I'm having some problems in exporting the annotations of some variants from a VCF file, after using the "VariantAnnotation" package from bioconductor. Below the script I've used:
  #!/usr/bin/env Rscript
  
  library(VariantAnnotation)
  library(BSgenome.Scerevisiae.UCSC.sacCer3)
  library(TxDb.Scerevisiae.UCSC.sacCer3.sgdGene)
  
  args = commandArgs(trailingOnly=TRUE)
  
  vcf <- readVcf(args[1], "sacCer3")
  
  sc <- BSgenome.Scerevisiae.UCSC.sacCer3
  txdb <- TxDb.Scerevisiae.UCSC.sacCer3.sgdGene
  
  coding <- data.frame(predictCoding(vcf, txdb, seqSource=sc))
  
  The coding dataframe looks like this:
    seqnames start end width strand paramRangeID REF     ALT QUAL FILTER
  1     chrI   455 455     1      +         <NA>   C       T   40   PASS
  2     chrI   455 455     1      +         <NA>   C           40   PASS
  3     chrI   455 455     1      +         <NA>   C       G   40   PASS
  4     chrI   455 455     1      +         <NA>   C       A   40   PASS
  5     chrI   456 456     1      +         <NA>   T       A   40   PASS
  6     chrI   456 456     1      +         <NA>   C CCTGCTC   40   PASS
    varAllele CDSLOC.start CDSLOC.end CDSLOC.width PROTEINLOC QUERYID TXID CDSID
  1         T          121        121            1         41       1    1     1
  2                    121        121            1         41       2    1     1
  3         G          121        121            1         41       3    1     1
  4         A          121        121            1         41       4    1     1
  5         A          122        122            1         41       5    1     1
  6   CCTGCTC          122        122            1         41       6    1     1
     GENEID    CONSEQUENCE REFCODON  VARCODON REFAA VARAA
  1 YAL069W  nonsynonymous      CTC       TTC     L     F
  2 YAL069W not translated      CTC        TC            
  3 YAL069W  nonsynonymous      CTC       GTC     L     V
  4 YAL069W  nonsynonymous      CTC       ATC     L     I
  5 YAL069W  nonsynonymous      CTC       CAC     L     H
  6 YAL069W  nonsynonymous      CTC CCCTGCTCC     L   PCS
  
  But if I try to save it to file, for instance using the following command:
  write.table(coding, 'test.tsv', sep='\t', row.names=F)
  
  The output table looks like this:
  "seqnames"      "start" "end"   "width" "strand"        "paramRangeID"  "REF"   "ALT"   "QUAL"  "FILTER"        "varAllele"     "CDSLOC.start"  "CDSLOC.end"    "CDSLOC.width"  "PROTEINLOC"    "QUERYID"       "TXID"  "CDSID" "GENEID"        "CONSEQUENCE"   "REFCODON"      "VARCODON"      "REFAA" "VARAA"             
  "chrI"  455     455     1       "+"     NA      "C"     <S4 object of class "DNAStringSet">     40      "PASS"  "T"     121     121     1       41      1       "1"     1       "YAL069W"       "nonsynonymous" "CTC"   "TTC"   "L"     "F"                            
  "chrI"  455     455     1       "+"     NA      "C"     <S4 object of class "DNAStringSet">     40      "PASS"  ""      121     121     1       41      2       "1"     1       "YAL069W"       "not translated" "CTC"   "TC"    ""      ""
  
  Notice the <S4 object of class "DNAStringSet"> bit. Is there any way to force R to give me the same representation as head? I couldn't find anything in Biostrings' documentation.
  
  user29: 
  Is there any way to force R to give me the same representation as head?
  
  head just cuts off everything after the first six entries. The magic, as it were, happens in the default print method for the specific type. But the representation generated by it is only useful for ad-hoc display, not for storage in a structured data file.
  The best solution is therefore to manually convert the column types. Since it’s only one column:
  coding$ALT = sapply(coding$ALT, as.character)
  
  I’m a bit puzzled that the REF and ALT column have different types, anyway: that’s probably a bug in the {VariantAnnotation} package that should be reported.
  Furthermore, you probably want to use quote = FALSE for the write.table. In general, write.table has terrible defaults. readr::write_tsv is almost always a better choice.
  
original_text: 123: <p>I'm having some problems in exporting the annotations of some variants from a VCF file, after using the "<a href="https://bioconductor.org/packages/release/bioc/html/VariantAnnotation.html" rel="nofollow noreferrer">VariantAnnotation</a>" package from bioconductor. Below the script I've used:</p>
  
  <pre><code>#!/usr/bin/env Rscript
  
  library(VariantAnnotation)
  library(BSgenome.Scerevisiae.UCSC.sacCer3)
  library(TxDb.Scerevisiae.UCSC.sacCer3.sgdGene)
  
  args = commandArgs(trailingOnly=TRUE)
  
  vcf &lt;- readVcf(args[1], "sacCer3")
  
  sc &lt;- BSgenome.Scerevisiae.UCSC.sacCer3
  txdb &lt;- TxDb.Scerevisiae.UCSC.sacCer3.sgdGene
  
  coding &lt;- data.frame(predictCoding(vcf, txdb, seqSource=sc))
  </code></pre>
  
  <p>The <code>coding</code> dataframe looks like this:</p>
  
  <pre><code>  seqnames start end width strand paramRangeID REF     ALT QUAL FILTER
  1     chrI   455 455     1      +         &lt;NA&gt;   C       T   40   PASS
  2     chrI   455 455     1      +         &lt;NA&gt;   C           40   PASS
  3     chrI   455 455     1      +         &lt;NA&gt;   C       G   40   PASS
  4     chrI   455 455     1      +         &lt;NA&gt;   C       A   40   PASS
  5     chrI   456 456     1      +         &lt;NA&gt;   T       A   40   PASS
  6     chrI   456 456     1      +         &lt;NA&gt;   C CCTGCTC   40   PASS
    varAllele CDSLOC.start CDSLOC.end CDSLOC.width PROTEINLOC QUERYID TXID CDSID
  1         T          121        121            1         41       1    1     1
  2                    121        121            1         41       2    1     1
  3         G          121        121            1         41       3    1     1
  4         A          121        121            1         41       4    1     1
  5         A          122        122            1         41       5    1     1
  6   CCTGCTC          122        122            1         41       6    1     1
     GENEID    CONSEQUENCE REFCODON  VARCODON REFAA VARAA
  1 YAL069W  nonsynonymous      CTC       TTC     L     F
  2 YAL069W not translated      CTC        TC            
  3 YAL069W  nonsynonymous      CTC       GTC     L     V
  4 YAL069W  nonsynonymous      CTC       ATC     L     I
  5 YAL069W  nonsynonymous      CTC       CAC     L     H
  6 YAL069W  nonsynonymous      CTC CCCTGCTCC     L   PCS
  </code></pre>
  
  <p>But if I try to save it to file, for instance using the following command:</p>
  
  <pre><code>write.table(coding, 'test.tsv', sep='\t', row.names=F)
  </code></pre>
  
  <p>The output table looks like this:</p>
  
  <pre><code>"seqnames"      "start" "end"   "width" "strand"        "paramRangeID"  "REF"   "ALT"   "QUAL"  "FILTER"        "varAllele"     "CDSLOC.start"  "CDSLOC.end"    "CDSLOC.width"  "PROTEINLOC"    "QUERYID"       "TXID"  "CDSID" "GENEID"        "CONSEQUENCE"   "REFCODON"      "VARCODON"      "REFAA" "VARAA"             
  "chrI"  455     455     1       "+"     NA      "C"     &lt;S4 object of class "DNAStringSet"&gt;     40      "PASS"  "T"     121     121     1       41      1       "1"     1       "YAL069W"       "nonsynonymous" "CTC"   "TTC"   "L"     "F"                            
  "chrI"  455     455     1       "+"     NA      "C"     &lt;S4 object of class "DNAStringSet"&gt;     40      "PASS"  ""      121     121     1       41      2       "1"     1       "YAL069W"       "not translated" "CTC"   "TC"    ""      ""
  </code></pre>
  
  <p>Notice the <code>&lt;S4 object of class "DNAStringSet"&gt;</code> bit. Is there any way to force R to give me the same representation as <code>head</code>? I couldn't find anything in Biostrings' documentation.</p>
   29: <blockquote>
    <p>Is there any way to force R to give me the same representation as <code>head</code>?</p>
  </blockquote>
  
  <p><code>head</code> just cuts off everything after the first six entries. The magic, as it were, happens in the default <code>print</code> method for the specific type. But the representation generated by it is only useful for ad-hoc display, not for storage in a structured data file.</p>
  
  <p>The best solution is therefore to manually convert the column types. Since it’s only one column:</p>
  
  <pre><code>coding$ALT = sapply(coding$ALT, as.character)
  </code></pre>
  
  <p>I’m a bit puzzled that the <code>REF</code> and <code>ALT</code> column have different types, anyway: that’s probably a bug in the {VariantAnnotation} package that should be reported.</p>
  
  <p>Furthermore, you probably want to use <code>quote = FALSE</code> for the <code>write.table</code>. In general, <code>write.table</code> has terrible defaults. <code>readr::write_tsv</code> is almost always a better choice.</p>
  