Commit e543111 1 parent e171d33 commit e543111 Copy full SHA for e543111
File tree 3 files changed +26
-1
lines changed
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,12 @@ class RegionSet:
82
82
"""
83
83
...
84
84
85
+ def mean_region_width (self ) -> int :
86
+ """
87
+ Mean width of the regions
88
+ """
89
+ ...
90
+
85
91
def __len__ (self ) -> int :
86
92
"""
87
93
Size of the regionset
Original file line number Diff line number Diff line change @@ -157,6 +157,10 @@ impl PyRegionSet {
157
157
self . regionset . sort ( ) ;
158
158
Ok ( ( ) )
159
159
}
160
+
161
+ fn mean_region_width ( & self ) -> PyResult < u32 > {
162
+ Ok ( self . regionset . mean_region_width ( ) )
163
+ }
160
164
}
161
165
162
166
#[ pyclass( name = "TokenizedRegionSet" , module = "gtars.models" ) ]
Original file line number Diff line number Diff line change @@ -50,7 +50,8 @@ impl TryFrom<&Path> for RegionSet {
50
50
51
51
let reader = match path. is_file ( ) {
52
52
true => get_dynamic_reader ( path) . expect ( "!Can't read file" ) ,
53
- false => get_dynamic_reader_from_url ( path) . expect ( "!Can't get file neither from path or url!" )
53
+ false => get_dynamic_reader_from_url ( path)
54
+ . expect ( "!Can't get file neither from path or url!" ) ,
54
55
} ;
55
56
56
57
let mut header: String = String :: new ( ) ;
@@ -368,6 +369,20 @@ impl RegionSet {
368
369
false
369
370
}
370
371
372
+ pub fn mean_region_width ( & self ) -> u32 {
373
+ if self . is_empty ( ) {
374
+ return 0 ;
375
+ }
376
+ let sum: u32 = self
377
+ . regions
378
+ . iter ( )
379
+ . map ( |region| region. end - region. start )
380
+ . sum ( ) ;
381
+ let count: u32 = self . regions . len ( ) as u32 ;
382
+
383
+ sum / count
384
+ }
385
+
371
386
///
372
387
/// Get number of regions in RegionSet
373
388
///
You can’t perform that action at this time.
0 commit comments