Here's another beginner BioPython question from me... 

I'm running some genome assemblies for someone who has some new Illumina sequence data and also had done some sequencing a few years ago. They have some Sanger and 454 sequences (a couple thousand sequences with a couple thousand base pairs for each) and everything is in fasta format. They are trusted contigs and I'd like to use the data to help bridge assembly gaps of Illumina sequencing data (from the same extracted DNA that was kept frozen for a few years -- same bacterial strain). There are no quality files for the older data and if they ever existed they are long gone from the data directories.

What I want to do is create FASTQ files for the old Sanger and 454 FASTA files with a phred score of 40 -- I think that would be a `I` under PHRED-33.

(I know there are assemblers out there that take fasta files inputs along with fastq -- but my in-house makefile and pipeline does not and I really would like to incorporate these sequences in our current workflow without a lot of changes).

There are lots of resources for converting from fasta to fastq *WITH* a qual file -- see [here](/p/16458/), [here](/p/85929/), [here](http://qiime.org/scripts/convert_fastaqual_fastq.html), [here](http://seqanswers.com/forums/showthread.php?t=16925), and [here](http://sequenceconversion.bugaco.com/converter/biology/sequences/fasta_to_fastq-solexa.php); but I've looked all over but can't find anything for converting without a qual file.

[Here is a public perl script](https://code.google.com/p/fasta-to-fastq/) that does exactly what I want it to do -- but I can't get it to work for me and I keep getting an error.

As an exercise, I quickly wrote the script below, but I can't get it to provide the quality score as the length of the sequence. The quality string needs to be the same length as the input sequence string. Anyone have any hints for me? Any help is appreciated.

Here's my code so far:

    #!/usr/bin/env python
    
    """
    Convert FASTA to FASTQ file with a static quality read
    
    Usage:
    $ ./fasta_to_fastq NAME.fasta NAME.fastq
    """
    
    # import libraries
    import sys, os
    from Bio import SeqIO
    from Bio.SeqIO.QualityIO import PairedFastaQualIterator
    
    # Get inputs
    fa_path = sys.argv[1]
    fq_path = sys.argv[2]
    phred_quality = "I"
    
    # Check inputs
    if not os.path.exists(fa_path): raise Exception("No file at %s." % fa_path)
    
    # make fastq
    with open(fq_path, "w") as handle:
        records = PairedFastaQualIterator(open(fa_path), print("phred_quality"))
        count = SeqIO.write(records, handle, "fastq")
    
    # print fastq
    print "Converted %i records" % count
The solution is to create a record within each loop and assign qualities to that. This has some explanations: http://biopython.org/DIST/docs/api/Bio.SeqIO.QualityIO-module.html

```
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio import SeqIO

seq = Seq("NACGTACGTA")
rec = SeqRecord(seq, id="foo")
rec.letter_annotations["phred_quality"] = [40] * len(seq)
recs = [ rec ]
handle = file("out.fq", "wt")
SeqIO.write(recs, handle, "fastq")
```

Better yet do it with <a href="https://github.com/lh3/bioawk">bioawk</a>:

```
$ more fasta.awk 
{ 
  qual = ""
  for (i=0; I<length($seq); i++){
    qual = qual "I"
  }
  printf ("@%s\n%s\n+\n%s\n", $name, $seq, qual)
}
```

then run it as

    cat test.fa | awk -c fastx -f fasta.awk