Skip to content

Commit

Permalink
We should have fixed #131
Browse files Browse the repository at this point in the history
  • Loading branch information
lucventurini committed Oct 4, 2018
1 parent 36e3ac3 commit ffbff8b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
54 changes: 42 additions & 12 deletions Mikado/loci/superlocus.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,8 +1120,50 @@ def define_loci(self):
if self.json_conf["pick"]["alternative_splicing"]["report"] is True:
self.define_alternative_splicing()

self.__find_lost_transcripts()
while len(self.lost_transcripts) > 0:
new_locus = None
for transcript in self.lost_transcripts.values():
if new_locus is None:
new_locus = Superlocus(transcript,
json_conf=self.json_conf,
use_transcript_scores=self._use_transcript_scores,
stranded=self.stranded,
verified_introns=self.locus_verified_introns,
logger = self.logger,
source=self.source
)
else:
new_locus.add_transcript_to_locus(transcript)
new_locus.define_loci()
self.loci.update(new_locus.loci)
self.__lost = new_locus.lost_transcripts
return

def __find_lost_transcripts(self):

if self.loci_defined is True:
return

loci_transcripts = itertools.chain(*[{self.loci[_].transcripts.keys()} for _ in self.loci])

for tid in set.difference({self.transcripts.keys()}, loci_transcripts):
found = False
for lid in self.loci:
if MonosublocusHolder.in_locus(self.loci[lid], self.transcripts[tid]):
found = True
break
else:
continue
if found is True:
continue
else:
self.__lost.update({tid: self.transcripts[tid]})

if len(self.__lost):
self.logger.warning("Lost %s transcripts from %s; starting the recovery process",
len(self.lost_transcripts), self.id)

def define_alternative_splicing(self):

"""
Expand Down Expand Up @@ -1180,7 +1222,6 @@ def define_alternative_splicing(self):

# Now we have to recheck that no AS event is linking more than one locus.
to_remove = collections.defaultdict(list)
lost_found_ids = set()
for lid in self.loci:
for tid, transcript in [_ for _ in self.loci[lid].transcripts.items() if
_[0] != self.loci[lid].primary_transcript_id]:
Expand All @@ -1191,23 +1232,12 @@ def define_alternative_splicing(self):
self.logger.warning("%s is compatible with more than one locus. Removing it.", tid)
to_remove[lid].append(tid)

for tid in self.__lost:
if MonosublocusHolder.in_locus(self.loci[lid], self.lost_transcripts[tid]):
lost_found_ids.add(tid)

for lid in to_remove:
for tid in to_remove[lid]:
self.loci[lid].remove_transcript_from_locus(tid)

self.loci[lid].finalize_alternative_splicing()

for tid in lost_found_ids:
del self.__lost[tid]

if len(self.__lost):
self.logger.warning("Lost %s transcripts from %s; starting the recovery process",
len(self.lost_transcripts), self.id)

return

def calculate_mono_metrics(self):
Expand Down
5 changes: 3 additions & 2 deletions Mikado/tests/test_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def test_transcript_missed(self):
locus.add_transcript_to_locus(t2)
locus.add_transcript_to_locus(t3)
locus.define_loci()
self.assertEqual(len(locus.loci), 1)
self.assertEqual(len(locus.loci), 2)
primaries = set([locus.loci[_].primary_transcript_id for _ in locus.loci])
self.assertEqual(primaries, {t3.id})
self.assertEqual(primaries, {t3.id, t1.id})
# self.assertEqual(set(locus.lost_transcripts.keys()), {t1.id})

0 comments on commit ffbff8b

Please sign in to comment.