Answers.Body: <p>This doesn't use R, but a simple and quite convenient method is to use <code>bedtools getfasta</code> with your fasta file. You'll need to make a BED file out of the RepeatMasker output:</p>
  
  <pre><code>awk 'BEGIN{OFS="\t"}{name=sprintf("%s_%s", $10, $11); strand="+"; if($9 == "C"){strand="-"}; print $5,$6-1,$7,name,".", strand}' repeatmasker.output &gt; rmsk.bed
  </code></pre>
  
  <p>Then, given that and your <code>genome.fa</code> fasta:</p>
  
  <pre><code>bedtools getfasta -name -s -fi genome.fa -bed rmsk.bed -fo output.fa
  </code></pre>
  
  <p>This will produce a multiline fasta file names like <code>AluSx_SINE/Alu</code> (due to the <code>-name</code> option) where the sequences are reverse complemented if appropriate.</p>
  
  <p>You can install bedtools either via conda (<code>conda install -c bioconda bedtools</code>) or <a href="https://github.com/arq5x/bedtools2/releases/download/v2.26.0/bedtools-2.26.0.tar.gz" rel="nofollow noreferrer">github</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-02T18:07:03.620Z
Answers.LastActivityDate: 2017-12-02T18:07:03.620Z
Answers.UserDisplayName: Devon Ryan
Body: <p>I have a very, very long list of genome coordinates of areas. I need to gather a sequence in order to compare it to another database of sequences that I have. How do I produce the genome sequences from these coordinates in R?</p>
  
  <p>I am very new to this and need a detailed answer.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-01T22:06:32.047Z
Comments.Text: What genome? Namely, is it one for which there's already a [BSgenome](http://bioconductor.org/packages/release/BiocViews.html#___AnnotationData) package?
Comments.UserDisplayName: Devon Ryan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-01T22:36:17.593Z
Comments.Text: The genome was given to me, it is not on there. My problem, more specifically I suppose, is that I was given a couple files. The genome was run through RepeatMasker to obtain coordinates of transposable elements. So, I have the coordinates from the map file that was produced from RepeatMasker and I would like to identify the sequences of these coordinates from my genome (which is too big to view). After I obtain the sequences, I will need to compare those sequences to a library of known elements that was also given to me in another file. So, I am lost especially since I am very new to this
Comments.UserDisplayName: Noob
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-01T22:39:18.383Z
Comments.Text: OK, does this really have to be done in R? This particular task is a bit better done on the command line than in R.
Comments.UserDisplayName: Devon Ryan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-27T03:30:28.450Z
Comments.Text: Do you know what type of commands this would consist of?
Comments.UserDisplayName: Noob
Tags: <r><genome><phylogenetics><ngs>
Title: Coordinates to Genome R Studio Script?
ThreadText: # Coordinates to Genome R Studio Script?
  
  (Asked by: username_0 on 2017-12-01)
  
  I have a very, very long list of genome coordinates of areas. I need to gather a sequence in order to compare it to another database of sequences that I have. How do I produce the genome sequences from these coordinates in R?
  
  I am very new to this and need a detailed answer.
  
  **Tags:** r, genome, phylogenetics, ngs
  
  > **Comments:**
  > **username_1**: What genome? Namely, is it one for which there's already a [BSgenome](http://bioconductor.org/packages/release/BiocViews.html#___AnnotationData) package?  
  > **username_0**: The genome was given to me, it is not on there. My problem, more specifically I suppose, is that I was given a couple files. The genome was run through RepeatMasker to obtain coordinates of transposable elements. So, I have the coordinates from the map file that was produced from RepeatMasker and I would like to identify the sequences of these coordinates from my genome (which is too big to view). After I obtain the sequences, I will need to compare those sequences to a library of known elements that was also given to me in another file. So, I am lost especially since I am very new to this  
  > **username_1**: OK, does this really have to be done in R? This particular task is a bit better done on the command line than in R.  
  > **username_0**: Do you know what type of commands this would consist of?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-12-02. Score: 2
  
  This doesn't use R, but a simple and quite convenient method is to use `bedtools getfasta` with your fasta file. You'll need to make a BED file out of the RepeatMasker output:
  
  ```
  awk 'BEGIN{OFS="\t"}{name=sprintf("%s_%s", $10, $11); strand="+"; if($9 == "C"){strand="-"}; print $5,$6-1,$7,name,".", strand}' repeatmasker.output > rmsk.bed
  
  ```
  
  Then, given that and your `genome.fa` fasta:
  
  ```
  bedtools getfasta -name -s -fi genome.fa -bed rmsk.bed -fo output.fa
  
  ```
  
  This will produce a multiline fasta file names like `AluSx_SINE/Alu` (due to the `-name` option) where the sequences are reverse complemented if appropriate.
  
  You can install bedtools either via conda (`conda install -c bioconda bedtools`) or [github](https://github.com/arq5x/bedtools2/releases/download/v2.26.0/bedtools-2.26.0.tar.gz).
  
  
  ---
  
  