1
1
use crate :: intersection:: Intersections ;
2
2
use crate :: py:: { CompiledPython , PyReportOptions } ;
3
3
use crate :: report_options:: ReportOptions ;
4
-
4
+ use std :: sync :: Arc ;
5
5
#[ derive( Debug , PartialEq ) ]
6
6
pub enum Value {
7
7
Int ( i32 ) ,
@@ -67,7 +67,7 @@ pub trait ColumnReporter {
67
67
fn value (
68
68
& self ,
69
69
r : & Intersections ,
70
- report_options : Option < & ReportOptions > ,
70
+ report_options : Arc < ReportOptions > ,
71
71
) -> Result < Value , ColumnError > ;
72
72
}
73
73
@@ -185,28 +185,15 @@ impl ColumnReporter for Column<'_> {
185
185
fn value (
186
186
& self ,
187
187
r : & Intersections ,
188
- report_options : Option < & ReportOptions > ,
188
+ report_options : Arc < ReportOptions > ,
189
189
) -> Result < Value , ColumnError > {
190
190
match & self . value_parser {
191
191
Some ( ValueParser :: Count ( false ) ) => {
192
192
// Return the count of overlapping intervals
193
193
Ok ( Value :: Int ( r. overlapping . len ( ) as i32 ) )
194
194
}
195
195
Some ( ValueParser :: Count ( true ) ) => {
196
- // Return the count of overlapping intervals
197
- // BARF: TODO: this sucks.
198
- let report = r. report (
199
- & report_options. map ( |o| & o. a_mode ) . unwrap_or_default ( ) ,
200
- & report_options. map ( |o| & o. b_mode ) . unwrap_or_default ( ) ,
201
- & report_options. map ( |o| & o. a_part ) . unwrap_or_default ( ) ,
202
- & report_options. map ( |o| & o. b_part ) . unwrap_or_default ( ) ,
203
- & report_options
204
- . map ( |o| & o. a_requirements )
205
- . unwrap_or_default ( ) ,
206
- & report_options
207
- . map ( |o| & o. b_requirements )
208
- . unwrap_or_default ( ) ,
209
- ) ;
196
+ let report = r. report ( report_options. clone ( ) ) ;
210
197
Ok ( Value :: Int ( report. len ( ) as i32 ) )
211
198
}
212
199
Some ( ValueParser :: Sum ) => {
@@ -218,18 +205,8 @@ impl ColumnReporter for Column<'_> {
218
205
Some ( ValueParser :: Bases ) => {
219
206
// Calculate total number of bases covered by overlapping intervals
220
207
// Use the report functionality to get the base count
221
- let default_mode = crate :: report_options:: IntersectionMode :: default ( ) ;
222
- let whole_part = crate :: report_options:: IntersectionPart :: Whole ;
223
- let base_requirement = crate :: report_options:: OverlapAmount :: Bases ( 1 ) ;
224
-
225
- let report = r. report (
226
- & default_mode,
227
- & default_mode,
228
- & whole_part,
229
- & whole_part,
230
- & base_requirement,
231
- & base_requirement,
232
- ) ;
208
+
209
+ let report = r. report ( report_options. clone ( ) ) ;
233
210
234
211
let bases = report. count_bases_by_id ( ) ;
235
212
let total_bases: i32 = bases. iter ( ) . sum :: < u64 > ( ) as i32 ;
@@ -259,10 +236,9 @@ impl ColumnReporter for Column<'_> {
259
236
// For Python expressions, we should use the compiled Python object
260
237
if let Some ( py) = & self . py {
261
238
// Convert intersection to PyIntersections and evaluate
262
- let py_intersection = crate :: py:: PyIntersections :: from ( r. clone ( ) ) ;
263
- let py_report_options =
264
- report_options. map ( |ro| PyReportOptions :: new ( ro. clone ( ) ) ) ;
265
- match py. eval ( py_intersection, py_report_options) {
239
+ let py_intersection =
240
+ crate :: py:: PyIntersections :: new ( r. clone ( ) , report_options. clone ( ) ) ;
241
+ match py. eval ( py_intersection) {
266
242
Ok ( result) => Ok ( Value :: String ( result) ) ,
267
243
Err ( e) => Err ( ColumnError :: PythonError ( format ! (
268
244
"Python error when evaluating expression: \" {}\" : {}" ,
0 commit comments