1
1
extern crate bedder;
2
2
use bedder:: column:: { Column , ColumnReporter } ;
3
+ use bedder:: hts_format:: Format ;
3
4
use bedder:: report_options:: { IntersectionMode , IntersectionPart , OverlapAmount , ReportOptions } ;
5
+ use bedder:: writer:: { InputHeader , Writer } ;
4
6
use clap:: Parser ;
5
7
use pyo3:: prelude:: * ;
6
8
use std:: env;
@@ -92,11 +94,20 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
92
94
93
95
let ii = bedder:: intersection:: IntersectionIterator :: new ( aiter, b_iters, & chrom_order) ?;
94
96
97
+ /*
95
98
let mut output: Box<dyn Write> = if args.output_path.to_str().unwrap() == "-" {
96
99
Box::new(BufWriter::new(std::io::stdout().lock()))
97
100
} else {
98
101
Box::new(BufWriter::new(File::create(&args.output_path)?))
99
102
};
103
+ */
104
+
105
+ let mut output = Writer :: init (
106
+ args. output_path . to_str ( ) . unwrap ( ) ,
107
+ Some ( Format :: Bed ) ,
108
+ None ,
109
+ InputHeader :: None ,
110
+ ) ?;
100
111
101
112
// Parse columns
102
113
let columns: Vec < Column > = args
@@ -106,6 +117,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
106
117
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
107
118
108
119
// Print header
120
+ /*
109
121
writeln!(
110
122
output,
111
123
"#{}",
@@ -115,8 +127,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
115
127
.collect::<Vec<_>>()
116
128
.join("\t")
117
129
)?;
130
+ */
118
131
119
- // TODO: start here. add the appropriate argugments above and get a report options struct here.
120
132
let report_options = Arc :: new (
121
133
ReportOptions :: builder ( )
122
134
. a_mode ( args. intersection_mode )
@@ -128,7 +140,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
128
140
// Use Python for columns that need it
129
141
Python :: with_gil ( |py| {
130
142
// Initialize Python expressions in columns if needed
131
- let py_columns: Vec < Column > = columns
143
+ let py_columns: Vec < Column < ' _ > > = columns
132
144
. into_iter ( )
133
145
. map ( |mut col| {
134
146
if let Some ( bedder:: column:: ValueParser :: PythonExpression ( expr) ) = & col. value_parser
@@ -140,13 +152,16 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
140
152
col
141
153
} )
142
154
. collect ( ) ;
143
- log:: info!( "py_columns: {:?}" , py_columns) ;
155
+ // log::info!("py_columns: {:?}", py_columns);
144
156
bedder:: py:: initialize_python ( py) . expect ( "Failed to initialize Python environment" ) ;
145
157
146
158
// Process intersections with columns
147
159
for intersection in ii {
148
160
// TODO: brent start here. need to auto call report when needed.
149
- let intersection = intersection. expect ( "error getting intersection" ) ;
161
+ let mut intersection = intersection. expect ( "error getting intersection" ) ;
162
+
163
+ output. write ( & mut intersection, report_options. clone ( ) , & py_columns) ?;
164
+ /*
150
165
let values: Vec<String> = py_columns
151
166
.iter()
152
167
.map(
@@ -167,8 +182,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
167
182
}
168
183
}
169
184
}
185
+ */
170
186
}
171
- } ) ;
172
-
173
- Ok ( ( ) )
187
+ Ok :: < ( ) , Box < dyn std:: error:: Error > > ( ( ) )
188
+ } )
174
189
}
0 commit comments