Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(8)  |  Call(6)  |  Derive(0)  |  Import(2)
Iterate over matched FASTA and QUAL files as SeqRecord objects.

For example, consider this short QUAL file with PHRED quality scores::

    >EAS54_6_R1_2_1_413_324
    26 26 18 26 26 26 26 26 26 26 26 26 26 26 26 22 26 26 26 26
    26 26 26 23 23
    >EAS54_6_R1_2_1_540_792
    26 26 26 26 26 26 26 26 26 26 26 22 26 26 26 26 26 12 26 26
    26 18 26 23 18(more...)

        def PairedFastaQualIterator(fasta_handle, qual_handle, alphabet=single_letter_alphabet, title2ids=None):
    """Iterate over matched FASTA and QUAL files as SeqRecord objects.

    For example, consider this short QUAL file with PHRED quality scores::

        >EAS54_6_R1_2_1_413_324
        26 26 18 26 26 26 26 26 26 26 26 26 26 26 26 22 26 26 26 26
        26 26 26 23 23
        >EAS54_6_R1_2_1_540_792
        26 26 26 26 26 26 26 26 26 26 26 22 26 26 26 26 26 12 26 26
        26 18 26 23 18
        >EAS54_6_R1_2_1_443_348
        26 26 26 26 26 26 26 26 26 26 26 24 26 22 26 26 13 22 26 18
        24 18 18 18 18

    And a matching FASTA file::

        >EAS54_6_R1_2_1_413_324
        CCCTTCTTGTCTTCAGCGTTTCTCC
        >EAS54_6_R1_2_1_540_792
        TTGGCAGGCCAAGGCCGATGGATCA
        >EAS54_6_R1_2_1_443_348
        GTTGCTTCTGGCGTGGGTGGGGGGG

    You can parse these separately using Bio.SeqIO with the "qual" and
    "fasta" formats, but then you'll get a group of SeqRecord objects with
    no sequence, and a matching group with the sequence but not the
    qualities.  Because it only deals with one input file handle, Bio.SeqIO
    can't be used to read the two files together - but this function can!
    For example,

    >>> rec_iter = PairedFastaQualIterator(open("Quality/example.fasta", "rU"),
    ...                                    open("Quality/example.qual", "rU"))
    >>> for record in rec_iter:
    ...     print("%s %s" % (record.id, record.seq))
    EAS54_6_R1_2_1_413_324 CCCTTCTTGTCTTCAGCGTTTCTCC
    EAS54_6_R1_2_1_540_792 TTGGCAGGCCAAGGCCGATGGATCA
    EAS54_6_R1_2_1_443_348 GTTGCTTCTGGCGTGGGTGGGGGGG

    As with the FASTQ or QUAL parsers, if you want to look at the qualities,
    they are in each record's per-letter-annotation dictionary as a simple
    list of integers:

    >>> print(record.letter_annotations["phred_quality"])
    [26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 24, 26, 22, 26, 26, 13, 22, 26, 18, 24, 18, 18, 18, 18]

    If you have access to data as a FASTQ format file, using that directly
    would be simpler and more straight forward.  Note that you can easily use
    this function to convert paired FASTA and QUAL files into FASTQ files:

    >>> from Bio import SeqIO
    >>> rec_iter = PairedFastaQualIterator(open("Quality/example.fasta", "rU"),
    ...                                    open("Quality/example.qual", "rU"))
    >>> with open("Quality/temp.fastq", "w") as out_handle:
    ...     SeqIO.write(rec_iter, out_handle, "fastq")
    3

    And don't forget to clean up the temp file if you don't need it anymore:

    >>> import os
    >>> os.remove("Quality/temp.fastq")
    """
    from Bio.SeqIO.FastaIO import FastaIterator
    fasta_iter = FastaIterator(fasta_handle, alphabet=alphabet,
                               title2ids=title2ids)
    qual_iter = QualPhredIterator(qual_handle, alphabet=alphabet,
                                  title2ids=title2ids)

    #Using (Python 3 style) zip wouldn't load everything into memory,
    #but also would not catch any extra records found in only one file.
    while True:
        try:
            f_rec = next(fasta_iter)
        except StopIteration:
            f_rec = None
        try:
            q_rec = next(qual_iter)
        except StopIteration:
            q_rec = None
        if f_rec is None and q_rec is None:
            #End of both files
            break
        if f_rec is None:
            raise ValueError("FASTA file has more entries than the QUAL file.")
        if q_rec is None:
            raise ValueError("QUAL file has more entries than the FASTA file.")
        if f_rec.id != q_rec.id:
            raise ValueError("FASTA and QUAL entries do not match (%s vs %s)."
                             % (f_rec.id, q_rec.id))
        if len(f_rec) != len(q_rec.letter_annotations["phred_quality"]):
            raise ValueError("Sequence length and number of quality scores disagree for %s"
                             % f_rec.id)
        #Merge the data....
        f_rec.letter_annotations[
            "phred_quality"] = q_rec.letter_annotations["phred_quality"]
        yield f_rec
        


src/j/c/jcvi-HEAD/formats/fasta.py   jcvi(Download)
def iter_fasta_qual(fastafile, qualfile, defaultqual=OKQUAL, modify=False):
    """
    used by trim, emits one SeqRecord with quality values in it
    """
    from Bio.SeqIO.QualityIO import PairedFastaQualIterator
    if not qualfile:
        qualfile = make_qual(fastafile, score=defaultqual)
 
    rec_iter = PairedFastaQualIterator(open(fastafile), open(qualfile))

src/s/e/seqmagick-0.5.0/seqmagick/subcommands/quality_filter.py   seqmagick(Download)
    with arguments.input_fastq as fp:
        if arguments.input_qual:
            sequences = QualityIO.PairedFastaQualIterator(fp,
                    arguments.input_qual)
        else:

src/s/e/seqmagick-HEAD/seqmagick/subcommands/quality_filter.py   seqmagick(Download)
    with arguments.input_fastq as fp:
        if arguments.input_qual:
            sequences = QualityIO.PairedFastaQualIterator(fp,
                    arguments.input_qual)
        else:

src/n/g/ngs-tools-0.1.8/ngstools/commands.py   ngs-tools(Download)
                with open(options_merge_fna_qual['<fna_file>']) as f:
                    with open(options_merge_fna_qual['<qual_file>']) as q:
                        records = SeqIO.QualityIO.PairedFastaQualIterator(f, q)
                        SeqIO.write(records, o, "fastq")
            except IOError as e:

src/s/e/seq_crumbs-HEAD/crumbs/utils/optional_modules.py   seq_crumbs(Download)
try:
    from Bio.SeqIO.QualityIO import QualPhredIterator
    from Bio.SeqIO.QualityIO import PairedFastaQualIterator
    from Bio.SeqIO.QualityIO import FastqPhredIterator
    from Bio.SeqIO.QualityIO import FastqSolexaIterator

src/b/i/biopython-1.63/Tests/test_SeqIO_QualityIO.py   biopython(Download)
    def test_paired(self):
        """Check FASTQ parsing matches FASTA+QUAL parsing"""
        with open("Quality/example.fasta") as f:
            with open("Quality/example.qual") as q:
                records1 = list(QualityIO.PairedFastaQualIterator(f, q ))

src/b/i/biopython-HEAD/Tests/test_SeqIO_QualityIO.py   biopython(Download)
    def test_paired(self):
        """Check FASTQ parsing matches FASTA+QUAL parsing"""
        with open("Quality/example.fasta") as f:
            with open("Quality/example.qual") as q:
                records1 = list(QualityIO.PairedFastaQualIterator(f, q ))