<p>I don't believe this is possible using <code>biomaRt</code>, nor using <code>AnnotationHub</code>.</p>

<p>I have two suggestions, neither of them very satisfactory. First, you can specify an Ensembl archive for <code>biomaRt</code>, for example:</p>

<pre><code>mart72.hs &lt;- useMart("ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl", 
                      host = "jun2013.archive.ensembl.org")
</code></pre>

<p>Of course, that requires that you have some idea of the date for each accession version and that the archives span that date - so not especially useful.</p>

<p>The other option is to access EUtils using <em>e.g.</em> <code>rentrez</code>, which does allow search by version number:</p>

<pre><code>library(rentrez)
es &lt;- entrez_search("nuccore", "NM_002084.1 NM_002084.2")
es$ids

[1] "4504104" "6006000"
</code></pre>

<p>So knowing the accession, you could simply append 1, 2, 3... to it, run the search and see if UIDs come back, then get them using <code>entrez_fetch</code>.</p>

<p>EDIT: here's a quick and dirty function which takes an accession as query, appends version = 1, fetches the ID, then increments the version and repeats until no more results are returned. It is not well-tested!</p>

<pre><code>getVersions &lt;- function(accession) {
  require(rentrez)
  ids &lt;- character()
  version &lt;- 1
  repeat({
    es &lt;- entrez_search("nuccore", paste0(accession, ".", version))
    if(length(es$ids) == 0) {
      break
    }
    ids[version] &lt;- es$ids
    version &lt;- version + 1
  })
  ids
}
</code></pre>

<p>Example:</p>

<pre><code>getVersions("NM_002084")
[1] "4504104"    "6006000"    "89903006"   "1048339180"
</code></pre>

CC BY-SA 3.0
2017-06-15T06:42:44.560Z
`rentrez` library looks like a good solution, could you please expand with code the last sentence?
zx8754
CC BY-SA 3.0
2017-06-15T07:16:41.620Z
Edited with some extra code.
neilfws
CC BY-SA 3.0
2017-06-15T11:40:39.233Z
Are the ID's returned GI numbers? If yes, then they are not going to be very useful.
GenoMax
CC BY-SA 3.0
2017-06-15T11:53:47.590Z
Well, that depends on what you want to do with the versions. If you want chromosome and coordinates as in the original question: that's always going to be difficult with old versions from old builds. If you want to retrieve the RefSeq records to compare versions, then UIDs are just fine.
neilfws
CC BY-SA 3.0
2017-06-15T05:40:30.137Z
2017-06-15T10:17:12.697Z
2017-06-15T10:17:12.697Z
neilfws
<p>Google searching for <strong>NM_002084</strong> gives the following result:</p>

<p><a href="https://www.ncbi.nlm.nih.gov/nuccore/NM_002084" rel="nofollow noreferrer">NM_002084.4</a></p>

<p>This, I assume, is the latest version v4, hence the <code>.4</code> suffix.</p>

<p>Searching for previous versions I get the following results, along with notes saying it was updated or removed.</p>

<p><a href="https://www.ncbi.nlm.nih.gov/nuccore/89903006" rel="nofollow noreferrer">NM_002084.3</a></p>

<blockquote>
  <p>This sequence has been updated. See current version.</p>
</blockquote>

<p><a href="https://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?val=NM_002084.2" rel="nofollow noreferrer">NM_002084.2</a></p>

<p><a href="https://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?val=NM_002084.1" rel="nofollow noreferrer">NM_002084.1</a></p>

<blockquote>
  <p>Record removed. This record was replaced or removed.</p>
</blockquote>

<p>Using <em>biomaRt</em> I can get the latest(<strong>?</strong>) version as follows:</p>

<pre><code>library("biomaRt")

# define db
ensembl &lt;- useMart("ensembl", dataset = "hsapiens_gene_ensembl")

# get refseqs
getBM(attributes = c('refseq_mrna',
                     'chromosome_name',
                     'transcript_start',
                     'transcript_end',
                     'strand'),
      filters = c('refseq_mrna'),
      values = list(refseq_mrna = "NM_002084"),
      mart = ensembl)
#  refseq_mrna chromosome_name transcript_start transcript_end strand
#1   NM_002084               5        151020438      151028992      1
</code></pre>

<p>But querying for specific versions gives nothing:</p>

<pre><code>getBM(attributes = c('refseq_mrna',
                     'chromosome_name',
                     'transcript_start',
                     'transcript_end',
                     'strand'),
      filters = c('refseq_mrna'),
      values = list(refseq_mrna = c("NM_002084.1", "NM_002084.2", "NM_002084.3", "NM_002084.4")),
      mart = ensembl)
# [1] refseq_mrna      chromosome_name  transcript_start transcript_end   strand          
# &lt;0 rows&gt; (or 0-length row.names)
</code></pre>

<p><strong>Question:</strong> How can I get all versions (preferably using R)?</p>

CC BY-SA 3.0
2017-06-14T22:31:11.427Z
Can you please explain why it's important to get all versions? The most recent version is typically an update of the sequence to correct errors in previous versions.
gringer
CC BY-SA 3.0
2017-06-15T06:48:05.070Z
@gringer True having the latest version should suffice, but I find it strange that it is *not possible* to get all versions automatically, when data is available online through manual search.
zx8754
<r><bioconductor><biomart><refseq>
Get RefSeq accession numbers with versions
# Get RefSeq accession numbers with versions

(Asked by: username_0 on 2017-06-14)

Google searching for NM_002084 gives the following result:
NM_002084.4
This, I assume, is the latest version v4, hence the .4 suffix.
Searching for previous versions I get the following results, along with notes saying it was updated or removed.
NM_002084.3

This sequence has been updated. See current version.

NM_002084.2
NM_002084.1

Record removed. This record was replaced or removed.

Using biomaRt I can get the latest(?) version as follows:
library("biomaRt")

# define db
ensembl <- useMart("ensembl", dataset = "hsapiens_gene_ensembl")

# get refseqs
getBM(attributes = c('refseq_mrna',
                     'chromosome_name',
                     'transcript_start',
                     'transcript_end',
                     'strand'),
      filters = c('refseq_mrna'),
      values = list(refseq_mrna = "NM_002084"),
      mart = ensembl)
#  refseq_mrna chromosome_name transcript_start transcript_end strand
#1   NM_002084               5        151020438      151028992      1

But querying for specific versions gives nothing:
getBM(attributes = c('refseq_mrna',
                     'chromosome_name',
                     'transcript_start',
                     'transcript_end',
                     'strand'),
      filters = c('refseq_mrna'),
      values = list(refseq_mrna = c("NM_002084.1", "NM_002084.2", "NM_002084.3", "NM_002084.4")),
      mart = ensembl)
# [1] refseq_mrna      chromosome_name  transcript_start transcript_end   strand          
# <0 rows> (or 0-length row.names)

Question: How can I get all versions (preferably using R)?

**Tags:** r, bioconductor, biomart, refseq
> **Comments:**
> **username_1**: Can you please explain why it's important to get all versions? The most recent version is typically an update of the sequence to correct errors in previous versions.  
> **username_0**: @gringer True having the latest version should suffice, but I find it strange that it is *not possible* to get all versions automatically, when data is available online through manual search.  

---

## 1 answers

### Answer by username_2 on 2017-06-15. Score: 6 | Accepted answer

I don't believe this is possible using biomaRt, nor using AnnotationHub.
I have two suggestions, neither of them very satisfactory. First, you can specify an Ensembl archive for biomaRt, for example:
mart72.hs <- useMart("ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl", 
                      host = "jun2013.archive.ensembl.org")

Of course, that requires that you have some idea of the date for each accession version and that the archives span that date - so not especially useful.
The other option is to access EUtils using e.g. rentrez, which does allow search by version number:
library(rentrez)
es <- entrez_search("nuccore", "NM_002084.1 NM_002084.2")
es$ids

[1] "4504104" "6006000"

So knowing the accession, you could simply append 1, 2, 3... to it, run the search and see if UIDs come back, then get them using entrez_fetch.
EDIT: here's a quick and dirty function which takes an accession as query, appends version = 1, fetches the ID, then increments the version and repeats until no more results are returned. It is not well-tested!
getVersions <- function(accession) {
  require(rentrez)
  ids <- character()
  version <- 1
  repeat({
    es <- entrez_search("nuccore", paste0(accession, ".", version))
    if(length(es$ids) == 0) {
      break
    }
    ids[version] <- es$ids
    version <- version + 1
  })
  ids
}

Example:
getVersions("NM_002084")
[1] "4504104"    "6006000"    "89903006"   "1048339180"

> **Comments:**
> **username_0**: `rentrez` library looks like a good solution, could you please expand with code the last sentence?  
> **username_2**: Edited with some extra code.  
> **username_3**: Are the ID's returned GI numbers? If yes, then they are not going to be very useful.  
> **username_2**: Well, that depends on what you want to do with the versions. If you want chromosome and coordinates as in the original question: that's always going to be difficult with old versions from old builds. If you want to retrieve the RefSeq records to compare versions, then UIDs are just fine.  

---

