示例#1
0
    def test_invalid_create(self):
        start = 0
        end = 10
        r = sbol3.Range(sbol3.PYSBOL3_MISSING, start, end)
        report = r.validate()
        self.assertIsNotNone(report)
        self.assertEqual(1, len(report.errors))

        # end must be > 0, and end must be > start
        start = 1
        end = 0
        r = sbol3.Range(sbol3.PYSBOL3_MISSING, start, end)
        report = r.validate()
        self.assertIsNotNone(report)
        self.assertEqual(2, len(report.errors))

        # end must be >= start
        start = 10
        end = 9
        r = sbol3.Range(sbol3.PYSBOL3_MISSING, start, end)
        report = r.validate()
        self.assertIsNotNone(report)
        self.assertEqual(1, len(report.errors))

        start = 7
        end = 7
        r = sbol3.Range(sbol3.PYSBOL3_MISSING, start, end)
        self.assertEqual(start, r.start)
        self.assertEqual(end, r.end)
        report = r.validate()
        self.assertIsNotNone(report)
        self.assertEqual(0, len(report.errors))
def compute_sequence(component: sbol3.Component) -> sbol3.Sequence:
    """Compute the sequence of a component and add this information into the Component in place

    :param component: Component whose sequence is to be computed
    :return: Sequence that has been computed
    """
    sorted, circular = order_subcomponents(component)
    # make the blank sequence
    sequence = sbol3.Sequence(
        component.display_id + "_sequence",
        encoding='https://identifiers.org/edam:format_1207'
    )  #   ### BUG: pySBOL #185
    sequence.elements = ''  # Should be in keywords, except pySBOL3 #208
    # for each component in turn, add it and set its location
    for i in range(len(sorted)):
        subc = sorted[i].instance_of.lookup()
        assert len(subc.sequences) == 1
        subseq = subc.sequences[0].lookup()
        assert sequence.encoding == subseq.encoding
        sorted[i].locations.append(
            sbol3.Range(sequence,
                        len(sequence.elements) + 1,
                        len(sequence.elements) + len(subseq.elements)))
        sequence.elements += subseq.elements
    # when all have been handled, the sequence is fully realized
    component.document.add(sequence)
    component.sequences.append(sequence)
    return sequence
示例#3
0
 def test_creation(self):
     start = 1
     end = 10
     r = sbol3.Range(sbol3.PYSBOL3_MISSING, start, end)
     self.assertIsNotNone(r)
     self.assertEqual(start, r.start)
     self.assertEqual(end, r.end)
     self.assertEqual(sbol3.SBOL_RANGE, r.type_uri)
示例#4
0
 def test_recursive_validation(self):
     # Test that the owned object, in this case the Range,
     # is also validated when the SequenceFeature is validated.
     seq_uri = 'https://github.com/synbiodex/pysbol3/sequence'
     start = 10
     end = 1
     r = sbol3.Range(seq_uri, start, end)
     report = r.validate()
     # end < start is a validation error
     self.assertEqual(1, len(report.errors))
     sf = sbol3.SequenceFeature([r])
     report = sf.validate()
     # We should find the validation issue in the owned
     # object (the range).
     self.assertEqual(1, len(report.errors))
示例#5
0
 def test_keyword_args(self):
     # Test that all arguments, both required and optional, can be
     # specified by keyword
     seq_uri = 'https://example.com/pysbol3/seq1'
     start = 7
     end = 14
     range_uri = 'https://example.com/pysbol3/r1'
     r1 = sbol3.Range(sequence=seq_uri,
                      end=end,
                      start=start,
                      identity=range_uri)
     self.assertEqual(seq_uri, r1.sequence)
     self.assertEqual(start, r1.start)
     self.assertEqual(end, r1.end)
     self.assertEqual(range_uri, r1.identity)
     display_id = range_uri[range_uri.rindex('/') + 1:]
     self.assertEqual(display_id, r1.display_id)
示例#6
0
 def test_validate(self):
     # Test the document level validation
     # This should validate all the objects in the document
     # and return a report containing all errors and warnings.
     doc = sbol3.Document()
     c1 = sbol3.Component('https://github.com/synbiodex/pysbol3/c1',
                          sbol3.SBO_DNA)
     doc.add(c1)
     s1 = sbol3.Sequence('https://github.com/synbiodex/pysbol3/s1')
     doc.add(s1)
     start = 10
     end = 1
     r = sbol3.Range(s1, start, end)
     sf = sbol3.SequenceFeature([r])
     c1.features.append(sf)
     report = doc.validate()
     # We should find the validation issue in the Range
     self.assertEqual(1, len(report))
示例#7
0
 def test_type_constraint(self):
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     c = sbol3.Component('foo', sbol3.SBO_DNA)
     with self.assertRaises(TypeError):
         c.features = [sbol3.Range('https://example.com/fake', 1, 2)]
     self.assertEqual(c.features.type_constraint, sbol3.Feature)