コード例 #1
0
 def test_add_sequence(self):
   contig = EMBLContig()
   contig.header = self.create_blank_bit_of_contig()
   contig.features['feature_1'] = self.create_blank_bit_of_contig()
   contig.add_sequence('AAAACCCGGTNN')
   self.assertIsInstance(contig.sequence, EMBLSequence)
   self.assertRaises(ValueError, contig.add_sequence, 'AAAACCCGGTNN')
コード例 #2
0
 def visit_feature_node(self, feature_node):
     sequence_id = feature_node.get_seqid()
     contig = self.contigs.get(sequence_id)
     if contig:  # contig already exists, just try and update it
         contig.add_feature(sequence_id=sequence_id,
                            feature_type=feature_node.get_type(),
                            start=feature_node.get_start(),
                            end=feature_node.get_end(),
                            strand=feature_node.get_strand(),
                            feature_attributes=feature_node.attribs,
                            locus_tag=self.locus_tag,
                            translation_table=self.translation_table)
     else:
         contig = EMBLContig()
         successfully_added_feature = contig.add_feature(
             sequence_id=sequence_id,
             feature_type=feature_node.get_type(),
             start=feature_node.get_start(),
             end=feature_node.get_end(),
             strand=feature_node.get_strand(),
             feature_attributes=feature_node.attribs,
             locus_tag=self.locus_tag,
             translation_table=self.translation_table)
         if successfully_added_feature:
             self.contigs[sequence_id] = contig
         else:
             pass  # discard the contig because we didn't add a feature so it is empty
コード例 #3
0
 def test_format_line_too_long(self):
   contig = EMBLContig()
   header_mock = MagicMock()
   sequence_mock = MagicMock()
   header_mock.format.return_value = "Header"
   sequence_mock.format.return_value = "Very long line: " + '*'*100
   contig.header = header_mock
   contig.features = {}
   contig.sequence = sequence_mock
   self.assertRaises(ValueError, contig.format)
コード例 #4
0
 def test_add_feature(self):
   contig = EMBLContig()
   contig.add_feature(
       sequence_id = 1,
       feature_type = 'tRNA',
       start = 100,
       end = 200,
       strand = '+',
       feature_attributes =  {'some_attribute': 'ABC' }
   )
   self.assertEqual(len(contig.features), 1)
コード例 #5
0
 def test_add_ignored_feature(self, feature_mock):
   contig = EMBLContig()
   feature_mock.return_value.format.side_effect = lambda: None 
   contig.add_feature(
       sequence_id = 1,
       feature_type = 'tRNA',
       start = 100,
       end = 200,
       strand = '+',
       feature_attributes =  {'some_attribute': 'ABC' }
   )
   self.assertEquals(contig.features, {})
コード例 #6
0
ファイル: EMBLConverter.py プロジェクト: JTumelty/gff3toembl
 def visit_feature_node(self, feature_node):
   sequence_id = feature_node.get_seqid()
   contig = self.contigs.get(sequence_id)
   if contig: # contig already exists, just try and update it
     contig.add_feature(sequence_id = sequence_id, feature_type = feature_node.get_type(), start = feature_node.get_start(),
                        end = feature_node.get_end(), strand = feature_node.get_strand(),
                        feature_attributes = feature_node.attribs,
                        locus_tag = self.locus_tag, translation_table = self.translation_table)
   else:
     contig = EMBLContig()
     successfully_added_feature = contig.add_feature(sequence_id = sequence_id, feature_type = feature_node.get_type(), start = feature_node.get_start(),
                        end = feature_node.get_end(), strand = feature_node.get_strand(),
                        feature_attributes = feature_node.attribs,
                        locus_tag = self.locus_tag, translation_table = self.translation_table)
     if successfully_added_feature:
       self.contigs[sequence_id] = contig
     else:
       pass # discard the contig because we didn't add a feature so it is empty
コード例 #7
0
  def test_format(self):
    contig = EMBLContig()
    header_mock = MagicMock()
    feature_mock_1 = MagicMock()
    feature_mock_2 = MagicMock()
    sequence_mock = MagicMock()
    header_mock.format.return_value = "Header\n"
    feature_mock_1.format.return_value = "Feature 1\n"
    feature_mock_1.start = 0
    feature_mock_2.format.return_value = "Feature 2\n"
    feature_mock_2.start = 100
    sequence_mock.format.return_value = "Sequence\n"
    contig.header = header_mock
    contig.features = {1: feature_mock_1, 2: feature_mock_2}
    contig.sequence = sequence_mock
    calculated_string = contig.format()
    expected_string = """\
Header
Feature 1
Feature 2
Sequence
"""
    self.assertEqual(calculated_string, expected_string)
コード例 #8
0
 def test_add_header(self):
   contig = EMBLContig()
   contig.features['feature_1'] = self.create_blank_bit_of_contig()
   contig.sequence = self.create_blank_bit_of_contig()
   header_details = {
     "authors": "John Doe",
     "classification": "UNC",
     "genome_type": "circular",
     "organism": "My organism",
     "project": "PRJ1234",
     "publication": "Unpublished",
     "sequence_identifier": "**contig123",
     "sequence_length": 8,
     "sequence_name": "chromX",
     "taxon_id": 5678,
     "title": "My title"
   }
   contig.add_header(**header_details)
   self.assertIsInstance(contig.header, EMBLHeader)
   with self.assertRaises(ValueError):
     contig.add_header(**header_details)
コード例 #9
0
  def test_get_sorted_features_3(self):
    # Must be able to get a list of features sorted by (start, end) irrespective of strand
    contig = EMBLContig()
    feature_1 = MagicMock()
    feature_1.start = 100
    feature_1.end = 1500
    feature_2 = MagicMock()
    feature_2.start = 1100
    feature_2.end = 2000

    contig.features = {1: feature_1, 2: feature_2}
    expected_features = [feature_1, feature_2]
    self.assertEquals(contig.sorted_features(), expected_features)

    contig.features = {2: feature_2, 1: feature_1}
    expected_features = [feature_1, feature_2]
    self.assertEquals(contig.sorted_features(), expected_features)

    contig.features = {2: feature_1, 1: feature_2}
    expected_features = [feature_1, feature_2]
    self.assertEquals(contig.sorted_features(), expected_features)
コード例 #10
0
 def visit_sequence_node(self, sequence_node):
     sequence_id = sequence_node.get_description()
     contig = self.contigs.setdefault(sequence_id, EMBLContig())
     contig.add_sequence(sequence_node.get_sequence())
コード例 #11
0
 def test_format_no_header(self):
   contig = EMBLContig()
   contig.features['feature_1'] = self.create_blank_bit_of_contig()
   contig.sequence = self.create_blank_bit_of_contig()
   self.assertEqual(contig.header, None)
   self.assertRaises(ValueError, contig.format)
コード例 #12
0
 def test_format_no_features(self):
   contig = EMBLContig()
   contig.header = self.create_blank_bit_of_contig()
   contig.sequence = self.create_blank_bit_of_contig()
   self.assertEquals(contig.format(), '')