diff --git a/Mikado/loci/sublocus.py b/Mikado/loci/sublocus.py index a8008b008..63cb159d6 100644 --- a/Mikado/loci/sublocus.py +++ b/Mikado/loci/sublocus.py @@ -84,13 +84,15 @@ def __init__(self, if isinstance(transcript_instance, Transcript): self.add_transcript_to_locus(transcript_instance) + self.attributes = transcript_instance.attributes.copy() + self.parent = transcript_instance.parent else: - self.parent = getattr(transcript_instance, "parent") + self.parent = getattr(transcript_instance, "parent", None) self.chrom = getattr(transcript_instance, "chrom") self.start = getattr(transcript_instance, "start") self.end = getattr(transcript_instance, "end") self.strand = getattr(transcript_instance, "strand") - self.attributes = getattr(transcript_instance, "attributes") + self.attributes = getattr(transcript_instance, "attributes", dict()) self.monosubloci = [] self.logger.debug("Initialized {0}".format(self.id)) diff --git a/Mikado/picking/picker.py b/Mikado/picking/picker.py index 074231845..dc8844218 100644 --- a/Mikado/picking/picker.py +++ b/Mikado/picking/picker.py @@ -861,7 +861,7 @@ def __submit_multi_threading(self, data_dict): elif row.is_transcript is True: if current_transcript is not None and invalid is False: self.__test_sortedness(row, current_transcript) - if Superlocus.in_locus( + if current_locus is not None and Superlocus.in_locus( current_locus, current_transcript, flank=self.json_conf["pick"]["clustering"]["flank"]) is True: current_locus.add_transcript_to_locus(current_transcript, @@ -893,7 +893,7 @@ def __submit_multi_threading(self, data_dict): intron_range=intron_range) if current_transcript is not None and invalid is False: - if Superlocus.in_locus( + if current_locus is not None and Superlocus.in_locus( current_locus, current_transcript, flank=self.json_conf["pick"]["clustering"]["flank"]) is True: current_locus.add_transcript_to_locus( @@ -1030,7 +1030,7 @@ def __submit_single_threaded(self, data_dict): elif row.is_transcript is True: if current_transcript is not None and invalid is False: self.__test_sortedness(row, current_transcript) - if Superlocus.in_locus( + if current_locus is not None and Superlocus.in_locus( current_locus, current_transcript, flank=self.json_conf["pick"]["clustering"]["flank"]) is True: current_locus.add_transcript_to_locus(current_transcript, @@ -1071,7 +1071,7 @@ def __submit_single_threaded(self, data_dict): intron_range=intron_range, logger=logger) if current_transcript is not None and invalid is False: - if Superlocus.in_locus( + if current_locus is not None and Superlocus.in_locus( current_locus, current_transcript, flank=self.json_conf["pick"]["clustering"]["flank"]) is True: current_locus.add_transcript_to_locus( diff --git a/Mikado/tests/locus_test.py b/Mikado/tests/locus_test.py index c0b89aa49..d6689e5f7 100644 --- a/Mikado/tests/locus_test.py +++ b/Mikado/tests/locus_test.py @@ -161,6 +161,24 @@ def test_evaluate_overlap(self): self.assertFalse(child1._evaluate_transcript_overlap(self.transcript1, self.transcript2)[0]) self.assertTrue(child1._evaluate_transcript_overlap(self.transcript1, self.transcript1)[0]) + def test_invalid_sublocus(self): + + with self.assertRaises(ValueError): + self.transcript1.json_conf = None + _ = Sublocus(self.transcript1, json_conf=None) + + with self.assertRaises(FileNotFoundError): + _ = Sublocus(self.transcript1, json_conf="test") + + def test_sublocus_from_sublocus(self): + + s = Sublocus(self.transcript1) + s2 = Sublocus(s) + self.assertFalse(s.fixed_size) + self.assertTrue(s2.fixed_size) + for attr in ["parent", "chrom", "start", "end", "strand", "attributes"]: + self.assertEqual(getattr(s, attr), getattr(s2, attr)) + class LocusTester(unittest.TestCase):