-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix (gtf): created GTFSourceInferrer class
- Loading branch information
Showing
4 changed files
with
45 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" Infer GTF source (e.g. GENCODE/ENSEMBL) """ | ||
from __future__ import annotations | ||
from typing import Dict, TYPE_CHECKING | ||
|
||
|
||
if TYPE_CHECKING: | ||
from moPepGen.gtf.GTFSeqFeature import GTFSeqFeature | ||
|
||
class GTFSourceInferrer(): | ||
""" Infer GTF source (e.g. GENOCDE/ENSEMBL) """ | ||
def __init__(self): | ||
""" Constructor """ | ||
self.max_iter = 100 | ||
self.data:Dict[str,int] = {} | ||
self.count = 0 | ||
self.source:str = None | ||
|
||
def infer(self, record:GTFSeqFeature) -> str: | ||
""" Infer the source of a GTF record """ | ||
if self.count > self.max_iter: | ||
if not self.source: | ||
self.source = sorted(self.data.items(), key=lambda x:x[1])[-1][0] | ||
return self.source | ||
self.count += 1 | ||
record.infer_annotation_source() | ||
source = record.source | ||
if source not in self.data: | ||
self.data[source] = 1 | ||
else: | ||
self.data[source] += 1 | ||
return source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters