Skip to content

Commit e03b696

Browse files
committed
Allow gene predictions to overlap on opposite strands
1 parent 3ce4d59 commit e03b696

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/geneml/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def parse_args(argv=None):
239239
advanced.add_argument('--gene-candidates', type=int, default=100, help="Maximum number of gene candidates to consider (default: %(default)s).")
240240
advanced.add_argument('--gene-range-time-limit', type=int, default=None, help="Time limit for each gene prediction, in seconds (default: %(default)s)")
241241
advanced.add_argument('--hardmask-repeats-min-size', type=int, default=None, help="Minimum size of softmasked repeat stretches to hardmask (default: %(default)s).")
242+
advanced.add_argument('--allow_opposite_strand_overlaps', type=bool, default=True, help="Predict overlapping genes on opposite strands (default: %(default)s).")
242243

243244
args = parser.parse_args(argv)
244245
check_args(parser, args)

src/geneml/params.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Params(namedtuple('Params', (
2727
'contigs_filter', 'output_segs', 'output_genes', 'output_proteins',
2828
'num_cores', 'debug', 'verbose', 'basepath', 'inpath', 'outpath',
2929
'hardmask_repeats_min_size', 'single_recurse_max_num_ops', 'recurse_region_max_num_ops',
30+
'allow_opposite_strand_overlaps',
3031
))):
3132
def to_json(self, **kwargs):
3233
return json.dumps(self._asdict(), cls=EnhancedJSONEncoder, **kwargs)
@@ -69,6 +70,8 @@ def build_params_namedtuple(args: Namespace) -> Params:
6970
'min_gene_score': args.min_gene_score,
7071
'gene_candidates': args.gene_candidates,
7172
'hardmask_repeats_min_size': args.hardmask_repeats_min_size,
73+
'allow_opposite_strand_overlaps': args.allow_opposite_strand_overlaps,
74+
7275
'single_recurse_max_num_ops': 100000,
7376
'recurse_region_max_num_ops': 200000,
7477
}

src/geneml/produce_genes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def create_transcripts(scored_gene_calls: list[tuple[float, list[GeneEvent]]],
9090
return transcripts
9191

9292

93-
def filter_transcripts(transcripts: list[Transcript], min_score: float):
93+
def filter_transcripts(transcripts: list[Transcript], min_score: float,
94+
allow_opposite_strand_overlaps: bool) -> list[Transcript]:
9495
""" This takes potential gene calls on both forward strand and reverse complement, filters them to remove
9596
overlapping calls, starting from highest scores first, and returns the best ones"""
9697

@@ -103,7 +104,7 @@ def filter_transcripts(transcripts: list[Transcript], min_score: float):
103104
valid_transcripts.sort(key=lambda x: x.start)
104105
non_overlapping = [valid_transcripts[0]]
105106
for t in valid_transcripts[1:]:
106-
if non_overlapping[-1].overlaps_with(t, ignore_strand=True):
107+
if non_overlapping[-1].overlaps_with(t, ignore_strand=not allow_opposite_strand_overlaps):
107108
if t.score > non_overlapping[-1].score:
108109
non_overlapping[-1] = t
109110
else:
@@ -141,7 +142,7 @@ def build_transcripts(preds: Optional[np.ndarray], rc_preds: Optional[np.ndarray
141142

142143
logger.info('Selecting best gene calls for %s', contig_id)
143144
filtered_transcripts = filter_transcripts(
144-
transcripts, params.min_gene_score)
145+
transcripts, params.min_gene_score, params.allow_opposite_strand_overlaps)
145146

146147
return filtered_transcripts
147148

0 commit comments

Comments
 (0)