def test_write_arguments(self): """Check how the write methods respond to output format arguments.""" gdd = Diagram('Test Diagram') gdd.drawing = None # Hack - need the ReportLab drawing object to be created. filename = os.path.join("Graphics", "error.txt") # We (now) allow valid formats in any case. for output in ["XXX", "xxx", None, 123, 5.9]: with self.assertRaises(ValueError): gdd.write(filename, output) with self.assertRaises(ValueError): gdd.write_to_string(output)
def test_write_arguments(self): """Check how the write methods respond to output format arguments.""" gdd = Diagram("Test Diagram") gdd.drawing = None # Hack - need the ReportLab drawing object to be created. filename = os.path.join("Graphics", "error.txt") # We (now) allow valid formats in any case. for output in ["XXX", "xxx", None, 123, 5.9]: with self.assertRaises(ValueError): gdd.write(filename, output) with self.assertRaises(ValueError): gdd.write_to_string(output)
def test_write_arguments(self) : """Check how the write methods respond to output format arguments.""" gdd = Diagram('Test Diagram') filename = os.path.join("Graphics","error.txt") #We (now) allow valid formats in any case. for output in ["XXX","xxx",None,123,5.9] : try : gdd.write(filename, output) assert False, \ "Should have rejected %s as an output format" % output except ValueError, e : #Good! pass try : gdd.write_to_string(output) assert False, \ "Should have rejected %s as an output format" % output except ValueError, e : #Good! pass
def test_write_arguments(self): """Check how the write methods respond to output format arguments.""" gdd = Diagram('Test Diagram') filename = os.path.join("Graphics", "error.txt") #We (now) allow valid formats in any case. for output in ["XXX", "xxx", None, 123, 5.9]: try: gdd.write(filename, output) assert False, \ "Should have rejected %s as an output format" % output except ValueError, e: #Good! pass try: gdd.write_to_string(output) assert False, \ "Should have rejected %s as an output format" % output except ValueError, e: #Good! pass
def test_partial_diagram(self): """construct and draw SVG and PDF for just part of a SeqRecord.""" genbank_entry = self.record start = 6500 end = 8750 gdd = Diagram( 'Test Diagram', # For the circular diagram we don't want a closed cirle: circular=False, ) # Add a track of features, gdt_features = gdd.new_track(1, greytrack=True, name="CDS Features", scale_largetick_interval=1000, scale_smalltick_interval=100, scale_format="SInt", greytrack_labels=False, height=0.5) # We'll just use one feature set for these features, gds_features = gdt_features.new_set() for feature in genbank_entry.features: if feature.type != "CDS": # We're going to ignore these. continue if feature.location.end.position < start: # Out of frame (too far left) continue if feature.location.start.position > end: # Out of frame (too far right) continue # This URL should work in SVG output from recent versions # of ReportLab. You need ReportLab 2.4 or later try: url = "http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi" +\ "?db=protein&id=%s" % feature.qualifiers["protein_id"][0] except KeyError: url = None # Note that I am using strings for color names, instead # of passing in color objects. This should also work! if len(gds_features) % 2 == 0: color = "white" # for testing the automatic black border! else: color = "red" # Checking it can cope with the old UK spelling colour. # Also show the labels perpendicular to the track. gds_features.add_feature(feature, colour=color, url=url, sigil="ARROW", label_position=None, label_size=8, label_angle=90, label=True) # And draw it... gdd.draw(format='linear', orientation='landscape', tracklines=False, pagesize=(10 * cm, 6 * cm), fragments=1, start=start, end=end) output_filename = os.path.join('Graphics', 'GD_region_linear.pdf') gdd.write(output_filename, 'PDF') # Also check the write_to_string (bytes string) method matches, # (Note the possible confusion over new lines on Windows) assert open(output_filename, "rb").read().replace(b"\r\n", b"\n") \ == gdd.write_to_string('PDF').replace(b"\r\n", b"\n") output_filename = os.path.join('Graphics', 'GD_region_linear.svg') gdd.write(output_filename, 'SVG') # Circular with a particular start/end is a bit odd, but by setting # circular=False (above) a sweep of 90% is used (a wedge is left out) gdd.draw(format='circular', tracklines=False, pagesize=(10 * cm, 10 * cm), start=start, end=end) output_filename = os.path.join('Graphics', 'GD_region_circular.pdf') gdd.write(output_filename, 'PDF') output_filename = os.path.join('Graphics', 'GD_region_circular.svg') gdd.write(output_filename, 'SVG')
def test_partial_diagram(self): """construct and draw SVG and PDF for just part of a SeqRecord.""" genbank_entry = self.record start = 6500 end = 8750 gdd = Diagram('Test Diagram', #For the circular diagram we don't want a closed cirle: circular=False, ) #Add a track of features, gdt_features = gdd.new_track(1, greytrack=True, name="CDS Features", scale_largetick_interval=1000, scale_smalltick_interval=100, scale_format = "SInt", greytrack_labels=False, height=0.5) #We'll just use one feature set for these features, gds_features = gdt_features.new_set() for feature in genbank_entry.features: if feature.type != "CDS": #We're going to ignore these. continue if feature.location.end.position < start: #Out of frame (too far left) continue if feature.location.start.position > end: #Out of frame (too far right) continue #This URL should work in SVG output from recent versions #of ReportLab. You need ReportLab 2.4 or later try : url = "http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi"+\ "?db=protein&id=%s" % feature.qualifiers["protein_id"][0] except KeyError : url = None #Note that I am using strings for color names, instead #of passing in color objects. This should also work! if len(gds_features) % 2 == 0: color = "white" # for testing the automatic black border! else: color = "red" #Checking it can cope with the old UK spelling colour. #Also show the labels perpendicular to the track. gds_features.add_feature(feature, colour=color, url = url, sigil="ARROW", label_position = None, label_size = 8, label_angle = 90, label=True) #And draw it... gdd.draw(format='linear', orientation='landscape', tracklines=False, pagesize=(10*cm,6*cm), fragments=1, start=start, end=end) output_filename = os.path.join('Graphics', 'GD_region_linear.pdf') gdd.write(output_filename, 'PDF') #Also check the write_to_string method matches, #(Note the possible confusion over new lines on Windows) assert open(output_filename).read().replace("\r\n","\n") \ == gdd.write_to_string('PDF').replace("\r\n","\n") output_filename = os.path.join('Graphics', 'GD_region_linear.svg') gdd.write(output_filename, 'SVG') #Circular with a particular start/end is a bit odd, but by setting #circular=False (above) a sweep of 90% is used (a wedge is left out) gdd.draw(format='circular', tracklines=False, pagesize=(10*cm,10*cm), start=start, end=end) output_filename = os.path.join('Graphics', 'GD_region_circular.pdf') gdd.write(output_filename, 'PDF') output_filename = os.path.join('Graphics', 'GD_region_circular.svg') gdd.write(output_filename, 'SVG')