Answers.Body: <p>The <a href="http://ccb.jhu.edu/software/stringtie/gff.shtml#gffread" rel="nofollow noreferrer">gffread utility</a> in Cufflinks package might be interesting for you. To generate a multi-fasta file with nucleotide sequences from your GFF file, then you can try: </p>
  
  <pre><code>gffread -w output_transcripts.fasta -g reference_genome.fa input_transcripts.gff
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-21T11:23:34.903Z
Answers.LastActivityDate: 2017-08-21T11:23:34.903Z
Answers.UserDisplayName: aechchiki
Answers.Body: <p>Using python and <a href="https://github.com/chapmanb/bcbb/tree/master/gff" rel="nofollow noreferrer">this GFF parser</a> that mimics <a href="http://biopython.org/wiki/SeqIO" rel="nofollow noreferrer">Biopython's SeqIO parsers</a>:</p>
  
  <pre><code>from BCBio import GFF
  
  # Read the gff
  for seq in GFF.parse('my_file.gff'):
      # only focus on the CDSs
      for feat in filter(lambda x: x.type == 'CDS',
                         seq.features):
          # extract the locus tag
          locus_tag = feat.qualifiers.get('locus_tag',
                                          ['unspecified'])[0]
          # extract the sequence
          dna_seq = seq = str(feat.extract(seq).seq)
          # simply print the sequence in fasta format
          print('&gt;%s\n%s' % (locus_tag, dna_seq))
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-21T11:16:00.020Z
Answers.Text: AFAIK GFF3 is a version of GFF, and the page that advertises the BCBio parser indicates that it is compatible in reading/writing GFF3: http://biopython.org/wiki/GFF_Parsing
Answers.UserDisplayName: mgalardini
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-21T09:57:25.883Z
Answers.LastActivityDate: 2017-08-21T09:57:25.883Z
Answers.UserDisplayName: mgalardini
Answers.Body: <p>The <code>xtractore</code> program from the <a href="http://brendelgroup.github.io/AEGeAn/" rel="nofollow noreferrer">AEGeAn Toolkit</a> was designed for this type of use case. Just set <code>--type=CDS</code>.</p>
  
  <pre><code>$ xtractore -h
  
  xtractore: extract sequences corresponding to annotated features from the
             given sequence file
  
  Usage: xtractore [options] features.gff3 sequences.fasta
    Options:
      -d|--debug            print debugging output
      -h|--help             print this help message and exit
      -i|--idfile: FILE     file containing a list of feature IDs (1 per line
                            with no spaces); if provided, only features with
                            IDs in this file will be extracted
      -o|--outfile: FILE    file to which output sequences will be written;
                            default is terminal (stdout)
      -t|--type: STRING     feature type to extract; can be used multiple
                            times to extract features of multiple types
      -v|--version          print version number and exit
      -V|--verbose          print verbose warning and error messages
      -w|--width: INT       width of each line of sequence in the Fasta
                            output; default is 80; set to 0 for no
                            formatting
  </code></pre>
  
  <p>It looks like you're processing prokaryotic genomes, but this program works also on eukaryotic genomes where CDSs often have introns interspersed.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-23T04:12:35.133Z
Answers.LastActivityDate: 2017-08-23T04:12:35.133Z
Answers.UserDisplayName: Daniel Standage
Answers.Body: <p>You can use <code>agat_sp_extract_sequences.pl</code> from <a href="https://github.com/NBISweden/AGAT" rel="nofollow noreferrer">AGAT</a>.
  See here for all option: <a href="https://agat.readthedocs.io/en/latest/tools/agat_sp_extract_sequences.html" rel="nofollow noreferrer">https://agat.readthedocs.io/en/latest/tools/agat_sp_extract_sequences.html</a>.</p>
  <p>Below example of use:</p>
  <p><a href="https://i.sstatic.net/vygC4.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vygC4.jpg" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-19T18:56:58.603Z
Answers.LastActivityDate: 2021-04-19T18:56:58.603Z
Answers.UserDisplayName: juke34
Answers.Body: <p>I like <code>bedtools getfasta</code>.  My typical option set is <code>bedtools getfasta -fi &lt;reference&gt; -bed &lt;gff_file&gt; -name -s</code>.  Be aware of the <code>-s</code> to make sure you are pulling the correct strand.  I like bedtools because it is a versatile tool overall for handling bed, gff and vcf file manipulations. </p>
  
  <pre><code># bedtools getfasta
  
  Tool:    bedtools getfasta (aka fastaFromBed)
  Version: v2.26.0
  Summary: Extract DNA sequences from a fasta file based on feature coordinates.
  
  Usage:   bedtools getfasta [OPTIONS] -fi &lt;fasta&gt; -bed &lt;bed/gff/vcf&gt;
  
  Options: 
      -fi Input FASTA file
      -bed    BED/GFF/VCF file of ranges to extract from -fi
      -name   Use the name field for the FASTA header
      -split  given BED12 fmt., extract and concatenate the sequencesfrom the BED "blocks" (e.g., exons)
      -tab    Write output in TAB delimited format.
          - Default is FASTA format.
  
      -s  Force strandedness. If the feature occupies the antisense,
          strand, the sequence will be reverse complemented.
          - By default, strand information is ignored.
  
      -fullHeader Use full fasta header.
          - By default, only the word before the first space or tab is used.
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-23T02:13:50.693Z
Answers.LastActivityDate: 2017-08-23T02:13:50.693Z
Answers.UserDisplayName: Bioathlete
Body: <p>I would like to extract all the CDS from a batch of genomes. I have found a perl script from <a href="https://www.biostars.org/p/46281/" rel="noreferrer">BioStars</a> but this does not seem to work for me. I would preferably like to have a script/ method which will use the locus tag as a header.</p>
  
  <p><strong>Example</strong></p>
  
  <p>My gff files are from prokka output</p>
  
  <pre><code>ATCC0000    Prodigal:2.6    CDS 243 434 .   +   0   ID=FKKLIMLP_00001;Parent=FKKLIMLP_00001_gene;inference=ab initio prediction:Prodigal:2.6;locus_tag=FKKLIMLP_00001;product=hypothetical protein
  ATCC0000    prokka  gene    243 434 .   +   .   ID=FKKLIMLP_00001_gene;locus_tag=FKKLIMLP_00001
  ATCC0000    Prodigal:2.6    CDS 1727    2131    .   -   0   ID=FKKLIMLP_00002;Parent=FKKLIMLP_00002_gene;inference=ab initio prediction:Prodigal:2.6;locus_tag=FKKLIMLP_00002;product=hypothetical protein
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-04-21T10:15:07.147Z
Comments.Text: I think gffread is the best choice.
Comments.UserDisplayName: YP CHEN
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-21T09:51:42.350Z
Comments.Text: If you are comfortable with python/biopython you can look into this GFF parser: https://github.com/chapmanb/bcbb/tree/master/gff
Comments.UserDisplayName: mgalardini
Tags: <fasta><software-recommendation><format-conversion><gff3>
Title: How to extract / convert gff3 CDS sequences to multifasta
ThreadText: # How to extract / convert gff3 CDS sequences to multifasta
  
  (Asked by: username_0 on 2017-08-21)
  
  I would like to extract all the CDS from a batch of genomes. I have found a perl script from [BioStars](https://www.biostars.org/p/46281/) but this does not seem to work for me. I would preferably like to have a script/ method which will use the locus tag as a header.
  
  **Example**
  
  My gff files are from prokka output
  
  ```
  ATCC0000    Prodigal:2.6    CDS 243 434 .   +   0   ID=FKKLIMLP_00001;Parent=FKKLIMLP_00001_gene;inference=ab initio prediction:Prodigal:2.6;locus_tag=FKKLIMLP_00001;product=hypothetical protein
  ATCC0000    prokka  gene    243 434 .   +   .   ID=FKKLIMLP_00001_gene;locus_tag=FKKLIMLP_00001
  ATCC0000    Prodigal:2.6    CDS 1727    2131    .   -   0   ID=FKKLIMLP_00002;Parent=FKKLIMLP_00002_gene;inference=ab initio prediction:Prodigal:2.6;locus_tag=FKKLIMLP_00002;product=hypothetical protein
  
  ```
  
  **Tags:** fasta, software-recommendation, format-conversion, gff3
  
  > **Comments:**
  > **username_2**: If you are comfortable with python/biopython you can look into this GFF parser: https://github.com/chapmanb/bcbb/tree/master/gff  
  > **username_1**: I think gffread is the best choice.  
  
  ---
  
  ## 5 answers
  
  ### Answer by username_6 on 2017-08-23. Score: 6 | Accepted answer
  
  I like `bedtools getfasta`. My typical option set is `bedtools getfasta -fi <reference> -bed <gff_file> -name -s`. Be aware of the `-s` to make sure you are pulling the correct strand. I like bedtools because it is a versatile tool overall for handling bed, gff and vcf file manipulations.
  
  ```
  # bedtools getfasta
  
  Tool:    bedtools getfasta (aka fastaFromBed)
  Version: v2.26.0
  Summary: Extract DNA sequences from a fasta file based on feature coordinates.
  
  Usage:   bedtools getfasta [OPTIONS] -fi <fasta> -bed <bed/gff/vcf>
  
  Options: 
      -fi Input FASTA file
      -bed    BED/GFF/VCF file of ranges to extract from -fi
      -name   Use the name field for the FASTA header
      -split  given BED12 fmt., extract and concatenate the sequencesfrom the BED "blocks" (e.g., exons)
      -tab    Write output in TAB delimited format.
          - Default is FASTA format.
  
      -s  Force strandedness. If the feature occupies the antisense,
          strand, the sequence will be reverse complemented.
          - By default, strand information is ignored.
  
      -fullHeader Use full fasta header.
          - By default, only the word before the first space or tab is used.
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2017-08-21. Score: 4
  
  The [gffread utility](http://ccb.jhu.edu/software/stringtie/gff.shtml#gffread) in Cufflinks package might be interesting for you. To generate a multi-fasta file with nucleotide sequences from your GFF file, then you can try:
  
  ```
  gffread -w output_transcripts.fasta -g reference_genome.fa input_transcripts.gff
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2017-08-21. Score: 3
  
  Using python and [this GFF parser](https://github.com/chapmanb/bcbb/tree/master/gff) that mimics [Biopython's SeqIO parsers](http://biopython.org/wiki/SeqIO):
  
  ```
  from BCBio import GFF
  
  # Read the gff
  for seq in GFF.parse('my_file.gff'):
      # only focus on the CDSs
      for feat in filter(lambda x: x.type == 'CDS',
                         seq.features):
          # extract the locus tag
          locus_tag = feat.qualifiers.get('locus_tag',
                                          ['unspecified'])[0]
          # extract the sequence
          dna_seq = seq = str(feat.extract(seq).seq)
          # simply print the sequence in fasta format
          print('>%s\n%s' % (locus_tag, dna_seq))
  
  ```
  
  > **Comments:**
  > **username_2**: AFAIK GFF3 is a version of GFF, and the page that advertises the BCBio parser indicates that it is compatible in reading/writing GFF3: http://biopython.org/wiki/GFF_Parsing  
  
  ---
  
  ### Answer by username_4 on 2017-08-23. Score: 2
  
  The `xtractore` program from the [AEGeAn Toolkit](http://brendelgroup.github.io/AEGeAn/) was designed for this type of use case. Just set `--type=CDS`.
  
  ```
  $ xtractore -h
  
  xtractore: extract sequences corresponding to annotated features from the
             given sequence file
  
  Usage: xtractore [options] features.gff3 sequences.fasta
    Options:
      -d|--debug            print debugging output
      -h|--help             print this help message and exit
      -i|--idfile: FILE     file containing a list of feature IDs (1 per line
                            with no spaces); if provided, only features with
                            IDs in this file will be extracted
      -o|--outfile: FILE    file to which output sequences will be written;
                            default is terminal (stdout)
      -t|--type: STRING     feature type to extract; can be used multiple
                            times to extract features of multiple types
      -v|--version          print version number and exit
      -V|--verbose          print verbose warning and error messages
      -w|--width: INT       width of each line of sequence in the Fasta
                            output; default is 80; set to 0 for no
                            formatting
  
  ```
  
  It looks like you're processing prokaryotic genomes, but this program works also on eukaryotic genomes where CDSs often have introns interspersed.
  
  
  ---
  
  ### Answer by username_5 on 2021-04-19. Score: 0
  
  You can use `agat_sp_extract_sequences.pl` from [AGAT](https://github.com/NBISweden/AGAT).
  See here for all option: <https://agat.readthedocs.io/en/latest/tools/agat_sp_extract_sequences.html>.
  
  Below example of use:
  
  [![enter image description here](https://i.sstatic.net/vygC4.jpg)](https://i.sstatic.net/vygC4.jpg)
  
  
  ---
  
  