Back to index

python-biopython  1.60
Classes | Functions | Variables
test_SeqIO_QualityIO Namespace Reference

Classes

class  TestFastqErrors
class  TestReferenceSffConversions
class  TestReferenceFastqConversions
class  TestQual
class  TestReadWrite
class  TestWriteRead
class  MappingTests

Functions

def truncation_expected
def write_read
def compare_record
def compare_records
def funct
def funct

Variables

 BytesIO = StringIO
list BINARY_FORMATS = ["sff", "sff-trim"]
list tests
tuple runner = unittest.TextTestRunner(verbosity = 2)

Function Documentation

def test_SeqIO_QualityIO.compare_record (   old,
  new,
  truncate = None 
)
Quality aware SeqRecord comparision.

This will check the mapping between Solexa and PHRED scores.
It knows to ignore UnknownSeq objects for string matching (i.e. QUAL files).

Definition at line 55 of file test_SeqIO_QualityIO.py.

00055 
00056 def compare_record(old, new, truncate=None):
00057     """Quality aware SeqRecord comparision.
00058 
00059     This will check the mapping between Solexa and PHRED scores.
00060     It knows to ignore UnknownSeq objects for string matching (i.e. QUAL files).
00061     """
00062     if old.id != new.id:
00063         raise ValueError("'%s' vs '%s' " % (old.id, new.id))
00064     if old.description != new.description \
00065     and (old.id+" "+old.description).strip() != new.description:
00066         raise ValueError("'%s' vs '%s' " % (old.description, new.description))
00067     if len(old.seq) != len(new.seq):
00068         raise ValueError("%i vs %i" % (len(old.seq), len(new.seq)))
00069     if isinstance(old.seq, UnknownSeq) or isinstance(new.seq, UnknownSeq):
00070         pass
00071     elif str(old.seq) != str(new.seq):
00072         if len(old.seq) < 200:
00073             raise ValueError("'%s' vs '%s'" % (old.seq, new.seq))
00074         else:
00075             raise ValueError("'%s...' vs '%s...'" % (old.seq[:100], new.seq[:100]))
00076     if "phred_quality" in old.letter_annotations \
00077     and "phred_quality" in new.letter_annotations \
00078     and old.letter_annotations["phred_quality"] != new.letter_annotations["phred_quality"]:
00079         if truncate and [min(q,truncate) for q in old.letter_annotations["phred_quality"]] == \
00080                         [min(q,truncate) for q in new.letter_annotations["phred_quality"]]:
00081             pass
00082         else:
00083             raise ValuerError("Mismatch in phred_quality")
00084     if "solexa_quality" in old.letter_annotations \
00085     and "solexa_quality" in new.letter_annotations \
00086     and old.letter_annotations["solexa_quality"] != new.letter_annotations["solexa_quality"]:
00087         if truncate and [min(q,truncate) for q in old.letter_annotations["solexa_quality"]] == \
00088                         [min(q,truncate) for q in new.letter_annotations["solexa_quality"]]:
00089             pass
00090         else:
00091             raise ValueError("Mismatch in phred_quality")
00092     if "phred_quality" in old.letter_annotations \
00093     and "solexa_quality" in new.letter_annotations:
00094         #Mapping from Solexa to PHRED is lossy, but so is PHRED to Solexa.
00095         #Assume "old" is the original, and "new" has been converted.
00096         converted = [round(QualityIO.solexa_quality_from_phred(q)) \
00097                      for q in old.letter_annotations["phred_quality"]]
00098         if truncate:
00099             converted = [min(q,truncate) for q in converted]
00100         if converted != new.letter_annotations["solexa_quality"]:
00101             print
00102             print old.letter_annotations["phred_quality"]
00103             print converted
00104             print new.letter_annotations["solexa_quality"]
00105             raise ValueError("Mismatch in phred_quality vs solexa_quality")
00106     if "solexa_quality" in old.letter_annotations \
00107     and "phred_quality" in new.letter_annotations:
00108         #Mapping from Solexa to PHRED is lossy, but so is PHRED to Solexa.
00109         #Assume "old" is the original, and "new" has been converted.
00110         converted = [round(QualityIO.phred_quality_from_solexa(q)) \
00111                      for q in old.letter_annotations["solexa_quality"]]
00112         if truncate:
00113             converted = [min(q,truncate) for q in converted]
00114         if converted != new.letter_annotations["phred_quality"]:
00115             print old.letter_annotations["solexa_quality"]
00116             print converted
00117             print new.letter_annotations["phred_quality"]
00118             raise ValueError("Mismatch in solexa_quality vs phred_quality")
00119     return True

Here is the caller graph for this function:

def test_SeqIO_QualityIO.compare_records (   old_list,
  new_list,
  truncate_qual = None 
)
Check two lists of SeqRecords agree, raises a ValueError if mismatch.

Definition at line 120 of file test_SeqIO_QualityIO.py.

00120 
00121 def compare_records(old_list, new_list, truncate_qual=None):
00122     """Check two lists of SeqRecords agree, raises a ValueError if mismatch."""
00123     if len(old_list) != len(new_list):
00124         raise ValueError("%i vs %i records" % (len(old_list), len(new_list)))
00125     for old, new in zip(old_list, new_list):
00126         if not compare_record(old,new,truncate_qual):
00127             return False
00128     return True
00129 

Here is the call graph for this function:

Here is the caller graph for this function:

def test_SeqIO_QualityIO.funct (   name,
  c 
)

Definition at line 190 of file test_SeqIO_QualityIO.py.

00190 
00191     def funct(name,c):
00192         f = lambda x : x.check_all_fail("Quality/error_%s.fastq" % name,c)
00193         f.__doc__ = "Reject FASTQ with %s" % name.replace("_"," ")
        return f

Here is the caller graph for this function:

def test_SeqIO_QualityIO.funct (   name,
  c1,
  c2 
)

Definition at line 208 of file test_SeqIO_QualityIO.py.

00208 
00209     def funct(name,c1,c2):
00210         f = lambda x : x.check_qual_char("Quality/error_qual_%s.fastq"%name,c1,c2)
00211         f.__doc__ = "Reject FASTQ with %s in quality" % name.replace("_"," ")
        return f

Here is the call graph for this function:

Definition at line 28 of file test_SeqIO_QualityIO.py.

00028 
00029 def truncation_expected(format):
00030     if format in ["fastq-solexa", "fastq-illumina"] :
00031         return 62
00032     elif format in ["fastq", "fastq-sanger"]:
00033         return 93
00034     else:
00035         assert format in ["fasta", "qual", "phd", "sff"]
00036         return None
00037 
#Top level function as this makes it easier to use for debugging:

Here is the caller graph for this function:

def test_SeqIO_QualityIO.write_read (   filename,
  in_format,
  out_format 
)

Definition at line 38 of file test_SeqIO_QualityIO.py.

00038 
00039 def write_read(filename, in_format, out_format):
00040     if in_format in BINARY_FORMATS:
00041         mode = "rb"
00042     else:
00043         mode = "r"
00044     records = list(SeqIO.parse(open(filename, mode),in_format))
00045     #Write it out...
00046     if out_format in BINARY_FORMATS:
00047         handle = BytesIO()
00048     else :
00049         handle = StringIO()
00050     SeqIO.write(records, handle, out_format)
00051     handle.seek(0)
00052     #Now load it back and check it agrees,
00053     records2 = list(SeqIO.parse(handle,out_format))
00054     compare_records(records, records2, truncation_expected(out_format))

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

list test_SeqIO_QualityIO.BINARY_FORMATS = ["sff", "sff-trim"]

Definition at line 26 of file test_SeqIO_QualityIO.py.

Definition at line 16 of file test_SeqIO_QualityIO.py.

tuple test_SeqIO_QualityIO.runner = unittest.TextTestRunner(verbosity = 2)

Definition at line 716 of file test_SeqIO_QualityIO.py.

Initial value:
00001 [("diff_ids", 2),
00002          ("no_qual", 0),
00003          ("long_qual", 3),
00004          ("short_qual", 2),
00005          ("double_seq", 3),
00006          ("double_qual", 2),
00007          ("tabs", 0),
00008          ("spaces", 0),
00009          ("trunc_in_title", 4),
00010          ("trunc_in_seq", 4),
00011          ("trunc_in_plus", 4),
00012          ("trunc_in_qual", 4),
00013          ("trunc_at_seq", 4),
00014          ("trunc_at_plus", 4),
00015          ("trunc_at_qual", 4)]

Definition at line 174 of file test_SeqIO_QualityIO.py.