Answers.Body: <p>Blast uses a 1-based coordinate system. Bed is 0-based half open. Your code needs to convert appropriately. See for example: <a href="https://www.biostars.org/p/317112/" rel="nofollow noreferrer">https://www.biostars.org/p/317112/</a> .</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-14T12:58:48.833Z
Answers.Text: thank you very much !
Answers.UserDisplayName: Grendel
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-14T12:55:16.113Z
Answers.LastActivityDate: 2019-11-14T12:55:16.113Z
Answers.UserDisplayName: Timur Shtatland
Body: <p>Hello I made a <code>blastX research</code>  (A query genome in nucleotide format translated into protein in 6 reading frames against a protein dabatase) </p>
  
  <p>And here is a head of the result : </p>
  
  <pre><code>IDBA_scaffold_7517  493 YP_009316100    0.360   61  27  1   150 4   126 186 6.775E-03   37
  IDBA_scaffold_29149 519 AIG51500    0.428   35  18  1   2792    2896    392 424 2.712E-03   40
  </code></pre>
  
  <p>I have 2 hits: </p>
  
  <p>The first one is the query <code>IDBA_scaffold_7517</code> that have a hit with a protein sequence <code>YP_009316100</code> in the <code>(-)</code> strand because the start begins by <code>150</code> and ends with <code>4</code>. </p>
  
  <p>The seconde one is the query <code>IDBA_scaffold_29149</code> that have a hit with a protein sequence <code>AIG51500</code> in the <code>(+)</code> strand because the start <code>begins 2794</code> and <code>ends by 2893</code>.</p>
  
  <p>so with that I actually created a bed file in order to extract the fasta sequences from my genome ( I assume that since there is a hit with a protein in the Genomes the coordinates of this hit should be in a good ORF (without stop codon). </p>
  
  <p>Here is the <code>bed_file</code> I made : </p>
  
  <pre><code>IDBA_scaffold_7517  4   150 Species 0   -
  IDBA_scaffold_29149 2794    2893    Species 0   +
  </code></pre>
  
  <p>Then in order to extract the sequences from the coordinates in the Genome I used:</p>
  
  <pre><code>bedtools getfasta -fi Genome.fa -bed bed_file -s -fo test
  </code></pre>
  
  <p>with <code>-s</code> to force strandedness. If the feature occupies the antisense, strand, the sequence will be reverse complemented.</p>
  
  <p>But when I do that the sequences extracted from the query are not in the good ORF. 
  I guess it is because I should take into account the fact that the coordinates are from nuc translated to portein but how could I do that? Should I change the coordinates manually from the bed file according to the fact that it is a negative of positif strand ? </p>
  
  <p>Thank you for your help. </p>
  
Tags: <fasta><bedtools><orf>
Title: Bedtools get fasta and ORF from a blastX run
ThreadText: # Bedtools get fasta and ORF from a blastX run
  
  (Asked by: username_0 on 2019-11-14)
  
  Hello I made a `blastX research` (A query genome in nucleotide format translated into protein in 6 reading frames against a protein dabatase)
  
  And here is a head of the result :
  
  ```
  IDBA_scaffold_7517  493 YP_009316100    0.360   61  27  1   150 4   126 186 6.775E-03   37
  IDBA_scaffold_29149 519 AIG51500    0.428   35  18  1   2792    2896    392 424 2.712E-03   40
  
  ```
  
  I have 2 hits:
  
  The first one is the query `IDBA_scaffold_7517` that have a hit with a protein sequence `YP_009316100` in the `(-)` strand because the start begins by `150` and ends with `4`.
  
  The seconde one is the query `IDBA_scaffold_29149` that have a hit with a protein sequence `AIG51500` in the `(+)` strand because the start `begins 2794` and `ends by 2893`.
  
  so with that I actually created a bed file in order to extract the fasta sequences from my genome ( I assume that since there is a hit with a protein in the Genomes the coordinates of this hit should be in a good ORF (without stop codon).
  
  Here is the `bed_file` I made :
  
  ```
  IDBA_scaffold_7517  4   150 Species 0   -
  IDBA_scaffold_29149 2794    2893    Species 0   +
  
  ```
  
  Then in order to extract the sequences from the coordinates in the Genome I used:
  
  ```
  bedtools getfasta -fi Genome.fa -bed bed_file -s -fo test
  
  ```
  
  with `-s` to force strandedness. If the feature occupies the antisense, strand, the sequence will be reverse complemented.
  
  But when I do that the sequences extracted from the query are not in the good ORF.
  I guess it is because I should take into account the fact that the coordinates are from nuc translated to portein but how could I do that? Should I change the coordinates manually from the bed file according to the fact that it is a negative of positif strand ?
  
  Thank you for your help.
  
  **Tags:** fasta, bedtools, orf
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-11-14. Score: 2 | Accepted answer
  
  Blast uses a 1-based coordinate system. Bed is 0-based half open. Your code needs to convert appropriately. See for example: <https://www.biostars.org/p/317112/> .
  
  > **Comments:**
  > **username_0**: thank you very much !  
  
  ---
  
  