<p>I can't quite grok your sorting scheme, but you can use <a href="https://bioconductor.org/packages/release/bioc/vignettes/genbankr/inst/doc/genbankr.html" rel="nofollow noreferrer">genbankr</a> to read your genbank file into a genomic ranges object in R, and filter/sort it however you like:</p>

<pre><code>source("https://bioconductor.org/biocLite.R")
biocLite("genbankr")
library(genbankr)
gb = readGenBank("sequence.gb")
subset(cds(gb), gene %in% c('sigE', 'sigG', 'spoIIE', 'sleC', 'REV7'))
</code></pre>

<p>output:</p>

<pre><code>GRanges object with 1 range and 10 metadata columns:
      seqnames       ranges strand |        type        gene        note
         &lt;Rle&gt;    &lt;IRanges&gt;  &lt;Rle&gt; | &lt;character&gt; &lt;character&gt; &lt;character&gt;
  [1]       IX [3300, 4037]      - |         CDS        REV7        &lt;NA&gt;
      codon_start     product  protein_id   translation     loctype
        &lt;numeric&gt; &lt;character&gt; &lt;character&gt; &lt;AAStringSet&gt; &lt;character&gt;
  [1]           1       Rev7p  AAA98667.1     MNR...SLF      normal
          gene_id transcript_id
      &lt;character&gt;   &lt;character&gt;
  [1]        REV7        REV7.1
  -------
  seqinfo: 1 sequence from U49845.1 genome
</code></pre>

CC BY-SA 3.0
2018-02-06T19:16:20.550Z
2018-02-06T19:16:20.550Z
heathobrien
<p>I have a list of gene names which I know are present in a genbank file. I want to order these genes based on the order of their presence in the genbank. This should also account for whether they are on the positive or negative strand. So for example I have four genes; genes_1? are on the positive strand and genes_2? are negative </p>

<pre><code>&gt;nano Gene_names.txt
gene_1A  #assume this is the first gene for positive strand
gene_1B  
gene_2A #assume this is first gene for negative strand
gene_2B 


&gt;nano Desired_out.txt
gene_1A
gene_2B
gene_1B
gene_2A
</code></pre>

<p><a href="https://i.sstatic.net/8JEQY.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8JEQY.png" alt="enter image description here"></a></p>

<p>Edits</p>

<p>The genbank would be the standard flat file as <a href="https://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html" rel="nofollow noreferrer">linked below</a> by terdon. 
The gene names are from a text list file and I have edited them now to reflect this.Im not exactly sure how to approach the strandness issue but I would imagine the complement would be helpful. I am unsure as to the strandness of the genes as is. </p>

<p>A working example of my work is to get the order of SpoI-V and other sporulation genes from <a href="https://www.ncbi.nlm.nih.gov/nuccore/NZ_CP010905.2" rel="nofollow noreferrer">C. difficile 630</a> </p>

<p>e.g. sigE, sigG, spoIIE, sleC </p>

CC BY-SA 3.0
2018-02-06T18:14:18.723Z
Please [edit] your question and clarify. I assume you mean a genbank flat file, like [this one](https://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html), right? If so, why does your example have a fasta-like header? Should we be looking for the ["complement"](https://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html#ComplementA) field to get the strand? And should there always be one +, then one -, then one + and so on? What if there are more genes on one strand than on the other? Can you add an actual example of your data so we understand what you need?
terdon
<data-mining><genbank>
How do I get the gene order from genbank file using gene names?
# How do I get the gene order from genbank file using gene names?

(Asked by: username_0 on 2018-02-06)

I have a list of gene names which I know are present in a genbank file. I want to order these genes based on the order of their presence in the genbank. This should also account for whether they are on the positive or negative strand. So for example I have four genes; genes_1? are on the positive strand and genes_2? are negative 
>nano Gene_names.txt
gene_1A  #assume this is the first gene for positive strand
gene_1B  
gene_2A #assume this is first gene for negative strand
gene_2B 


>nano Desired_out.txt
gene_1A
gene_2B
gene_1B
gene_2A


Edits
The genbank would be the standard flat file as linked below by terdon. 
The gene names are from a text list file and I have edited them now to reflect this.Im not exactly sure how to approach the strandness issue but I would imagine the complement would be helpful. I am unsure as to the strandness of the genes as is. 
A working example of my work is to get the order of SpoI-V and other sporulation genes from C. difficile 630 
e.g. sigE, sigG, spoIIE, sleC

**Tags:** data-mining, genbank
> **Comments:**
> **username_1**: Please [edit] your question and clarify. I assume you mean a genbank flat file, like [this one](https://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html), right? If so, why does your example have a fasta-like header? Should we be looking for the ["complement"](https://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html#ComplementA) field to get the strand? And should there always be one +, then one -, then one + and so on? What if there are more genes on one strand than on the other? Can you add an actual example of your data so we understand what you need?  

---

## 1 answers

### Answer by username_2 on 2018-02-06. Score: 1

I can't quite grok your sorting scheme, but you can use genbankr to read your genbank file into a genomic ranges object in R, and filter/sort it however you like:
source("https://bioconductor.org/biocLite.R")
biocLite("genbankr")
library(genbankr)
gb = readGenBank("sequence.gb")
subset(cds(gb), gene %in% c('sigE', 'sigG', 'spoIIE', 'sleC', 'REV7'))

output:
GRanges object with 1 range and 10 metadata columns:
      seqnames       ranges strand |        type        gene        note
                |   
  [1]       IX [3300, 4037]      - |         CDS        REV7        
      codon_start     product  protein_id   translation     loctype
            
  [1]           1       Rev7p  AAA98667.1     MNR...SLF      normal
          gene_id transcript_id
         
  [1]        REV7        REV7.1
  -------
  seqinfo: 1 sequence from U49845.1 genome


---

