<p>A simple Biopython solution:</p>
<pre><code>from Bio import SeqIO

for r in SeqIO.parse(&quot;myfile.fa&quot;, &quot;fasta&quot;):
    r.letter_annotations[&quot;solexa_quality&quot;] = [40] * len(r)
    print(r.format(&quot;fastq&quot;), end='')
</code></pre>
<p>Example:</p>
<pre><code><span class="math-container">$ cat &lt;&lt; EOF &gt; myfile.fa 
&gt;1
ATG
&gt;2
ATGTAGA
EOF
$</span> python3 myscript.py 
@1
ATG
+
III
@2
ATGTAGA
+
IIIIIII
</code></pre>

CC BY-SA 4.0
2020-01-20T20:59:28.290Z
2021-04-30T12:26:16.180Z
2021-04-30T12:26:16.180Z
Chris_Rands
<p>Here's a quick one-liner with no dependencies other than the UNIX core utils and Perl.</p>

<pre><code>cat seqs.fasta | paste - - | perl -ne 'chomp; s/^&gt;/@/; @v = split /\t/; printf("%s\n%s\n+\n%s\n", $v[0], $v[1], "B"x length($v[1]))' &gt; seqs.fastq
</code></pre>

<p>Caveat: assumes your Fasta sequences are not wrapped, i.e. two lines per record.</p>

CC BY-SA 4.0
2020-01-22T14:42:30.503Z
2020-01-22T14:42:30.503Z
Daniel Standage
<p>I think the python package <a href="https://bioconvert.readthedocs.io/en/master/user_guide.html#explicit-conversion" rel="nofollow noreferrer">bioconvert</a> does what you want if you don't provide qualities: <a href="https://github.com/bioconvert/bioconvert/blob/master/bioconvert/fasta2fastq.py" rel="nofollow noreferrer">https://github.com/bioconvert/bioconvert/blob/master/bioconvert/fasta2fastq.py</a></p>

<p>The following outputs lots of warnings for me, but does generate a fastq file <code>test.fq</code> from an existing fasta file <code>test.fa</code> (using dummy quality "I", and adding "None" to sequence headers that do not have a comment part in the original fasta):</p>

<pre><code>bioconvert fasta2fastq test.fa test.fq
</code></pre>

<p>(This requires installing bioconvert using <code>pip</code> beforehand: <code>pip install bioconvert</code>.)</p>

CC BY-SA 4.0
2020-01-21T10:39:06.400Z
2020-01-22T11:45:44.253Z
2020-01-22T11:45:44.253Z
bli
<p>I have just uploaded a Python tool to convert fasta to fastq: <a href="https://github.com/Mostafa-MR/A_tool_to_convert_fasta_to_fastq" rel="nofollow noreferrer">https://github.com/Mostafa-MR/A_tool_to_convert_fasta_to_fastq</a></p>
<p>Please note this is presented directly from a Jupyter notebook, i.e. it is a ipynb.</p>

CC BY-SA 4.0
2022-03-17T01:00:41.417Z
2022-03-17T01:06:24.740Z
2022-03-17T01:06:24.740Z
Mostafa M. Rezaee
<p>One way of doing this is with two subcommands from the <a href="https://github.com/sanger-pathogens/Fastaq" rel="nofollow noreferrer"><code>pyfastaq</code></a> suite.</p>

<pre class="lang-sh prettyprint-override"><code>fastaq to_fake_qual in.fasta - | fastaq fasta_to_fastq in.fasta - out.fastq
</code></pre>

<p>The first tool, <code>to_fake_qual</code>, creates fake quality scores (default 40) for each base and the <code>-</code> sends that file (<code>.qual</code>) to stdout. The second tool, <code>fasta_to_fastq</code>, consumes both the original fasta and the quality scores coming from stdin and turns these into a fastq file.</p>

CC BY-SA 4.0
2020-01-20T14:15:13.417Z
2020-01-20T14:15:13.417Z
Michael Hall
<p>I have a FASTA file which I would like to convert into FASTQ format as the tool I want to use my data in requires it in FASTQ format. So dummy quality scores are fine.</p>

<p>Note: I am not using any functionality of the tool that will require the quality score.</p>

<fasta><fastq>
Convert FASTA to FASTQ with dummy quality scores
# Convert FASTA to FASTQ with dummy quality scores

(Asked by: username_0 on 2020-01-20)

I have a FASTA file which I would like to convert into FASTQ format as the tool I want to use my data in requires it in FASTQ format. So dummy quality scores are fine.

Note: I am not using any functionality of the tool that will require the quality score.

**Tags:** fasta, fastq

---

## 5 answers

### Answer by username_0 on 2020-01-20. Score: 4 | Accepted answer

One way of doing this is with two subcommands from the pyfastaq suite.
fastaq to_fake_qual in.fasta - | fastaq fasta_to_fastq in.fasta - out.fastq

The first tool, to_fake_qual, creates fake quality scores (default 40) for each base and the - sends that file (.qual) to stdout. The second tool, fasta_to_fastq, consumes both the original fasta and the quality scores coming from stdin and turns these into a fastq file.


---

### Answer by username_1 on 2020-01-20. Score: 6

A simple Biopython solution:
from Bio import SeqIO

for r in SeqIO.parse("myfile.fa", "fasta"):
    r.letter_annotations["solexa_quality"] = [40] * len(r)
    print(r.format("fastq"), end='')

Example:
$ cat << EOF > myfile.fa 
>1
ATG
>2
ATGTAGA
EOF
$ python3 myscript.py 
@1
ATG
+
III
@2
ATGTAGA
+
IIIIIII


---

### Answer by username_2 on 2020-01-22. Score: 2

Here's a quick one-liner with no dependencies other than the UNIX core utils and Perl.
cat seqs.fasta | paste - - | perl -ne 'chomp; s/^>/@/; @v = split /\t/; printf("%s\n%s\n+\n%s\n", $v[0], $v[1], "B"x length($v[1]))' > seqs.fastq

Caveat: assumes your Fasta sequences are not wrapped, i.e. two lines per record.


---

### Answer by username_3 on 2020-01-21. Score: 2

I think the python package bioconvert does what you want if you don't provide qualities: https://github.com/bioconvert/bioconvert/blob/master/bioconvert/fasta2fastq.py
The following outputs lots of warnings for me, but does generate a fastq file test.fq from an existing fasta file test.fa (using dummy quality "I", and adding "None" to sequence headers that do not have a comment part in the original fasta):
bioconvert fasta2fastq test.fa test.fq

(This requires installing bioconvert using pip beforehand: pip install bioconvert.)


---

### Answer by username_4 on 2022-03-17. Score: 0

I have just uploaded a Python tool to convert fasta to fastq: <https://github.com/Mostafa-MR/A_tool_to_convert_fasta_to_fastq>

Please note this is presented directly from a Jupyter notebook, i.e. it is a ipynb.


---

