1
1
use bincode:: Options ;
2
2
use echtvar_lib:: { echtvar:: bstrip_chr, fields, kmer16, var32, zigzag} ;
3
- use rust_htslib:: bcf:: header:: { TagLength , TagType , HeaderRecord } ;
3
+ use rust_htslib:: bcf:: header:: { HeaderRecord , TagLength , TagType } ;
4
4
use rust_htslib:: bcf:: record:: { Buffer , Record } ;
5
5
use rust_htslib:: bcf:: { Read as BCFRead , Reader } ;
6
6
use stream_vbyte:: { encode:: encode, x86:: Sse41 } ;
@@ -74,7 +74,11 @@ fn get_string_field<'a, B: BorrowMut<Buffer> + Borrow<Buffer> + 'a>(
74
74
. string ( )
75
75
. unwrap_or ( None )
76
76
{
77
- Some ( v) => unsafe { String :: from_utf8_unchecked ( v[ 0 ] . to_vec ( ) ) } ,
77
+ Some ( v) => v
78
+ . iter ( )
79
+ . map ( |s| unsafe { String :: from_utf8_unchecked ( s. to_vec ( ) ) } )
80
+ . collect :: < Vec < String > > ( )
81
+ . join ( "," ) ,
78
82
None => default. to_string ( ) ,
79
83
}
80
84
} ;
@@ -166,14 +170,23 @@ fn hdr_info_id2description(
166
170
default : & std:: string:: String ,
167
171
) -> std:: string:: String {
168
172
hrecs. retain ( |rec| match rec {
169
- HeaderRecord :: Info { key : _, values : v} => & v[ "ID" ] == id,
170
- _ => false }
171
- ) ;
173
+ HeaderRecord :: Info { key : _, values : v } => & v[ "ID" ] == id,
174
+ _ => false ,
175
+ } ) ;
172
176
if hrecs. len ( ) != 1 {
173
- panic ! ( "Field {} is either not present in the header or present multiple times!" , id) ;
177
+ panic ! (
178
+ "Field {} is either not present in the header or present multiple times!" ,
179
+ id
180
+ ) ;
174
181
} ;
175
182
let description = match hrecs. first ( ) . unwrap ( ) {
176
- HeaderRecord :: Info { key : _, values : v} => if v. contains_key ( "Description" ) { & v[ "Description" ] } else { default } ,
183
+ HeaderRecord :: Info { key : _, values : v } => {
184
+ if v. contains_key ( "Description" ) {
185
+ & v[ "Description" ]
186
+ } else {
187
+ default
188
+ }
189
+ }
177
190
_ => default,
178
191
} ;
179
192
return description. trim_matches ( '"' ) . to_string ( ) ;
@@ -185,11 +198,11 @@ pub fn encoder_main(vpaths: Vec<&str>, opath: &str, jpath: &str) {
185
198
186
199
let mut json = String :: new ( ) ;
187
200
File :: open ( jpath)
188
- . expect ( "error opening json file" )
201
+ . unwrap_or_else ( |_| panic ! ( "error opening json file {:?}" , jpath ) )
189
202
. read_to_string ( & mut json)
190
- . expect ( "error parsing json file" ) ;
203
+ . unwrap_or_else ( |_| panic ! ( "error parsing json file {:?}" , jpath ) ) ;
191
204
let mut fields: Vec < fields:: Field > =
192
- json5:: from_str ( & json) . expect ( "error reading json into fields" ) ;
205
+ json5:: from_str ( & json) . unwrap_or_else ( |_| panic ! ( "error reading json into fields {:?}" , jpath ) ) ;
193
206
194
207
let mut vcf = if !( * vpaths[ 0 ] ) . eq ( "/dev/stdin" ) && !( * vpaths[ 0 ] ) . eq ( "-" ) {
195
208
Reader :: from_path ( vpaths[ 0 ] ) . expect ( "Error opening vcf." )
@@ -242,7 +255,8 @@ pub fn encoder_main(vpaths: Vec<&str>, opath: &str, jpath: &str) {
242
255
TagLength :: Variable => f. number = "." . to_string ( ) ,
243
256
} ;
244
257
if f. field != "FILTER" && f. description == fields:: default_description_string ( ) {
245
- f. description = hdr_info_id2description ( header. header_records ( ) , & f. field , & f. description ) ;
258
+ f. description =
259
+ hdr_info_id2description ( header. header_records ( ) , & f. field , & f. description ) ;
246
260
} ;
247
261
}
248
262
@@ -401,7 +415,18 @@ pub fn encoder_main(vpaths: Vec<&str>, opath: &str, jpath: &str) {
401
415
402
416
let mut alleles = rec. alleles ( ) ;
403
417
if alleles. len ( ) == 1 {
404
- alleles. push ( alleles[ 0 ] ) ;
418
+ /*
419
+ let last_rid = rec.rid().unwrap() as i32;
420
+ let n: &[u8] = header.rid2name(last_rid as u32).unwrap();
421
+ let chrom = bstrip_chr(str::from_utf8(n).unwrap());
422
+ eprintln!(
423
+ "[echtvar] variant {}:{} has only one allele, encoding as {}/T",
424
+ chrom,
425
+ rec.pos(),
426
+ String::from_utf8_lossy(alleles[0])
427
+ );
428
+ */
429
+ alleles. push ( b"T" ) ; // NOTE: we always encode . to T here.
405
430
} else if alleles. len ( ) != 2 {
406
431
last_rid = rec. rid ( ) . unwrap ( ) as i32 ;
407
432
let n: & [ u8 ] = header. rid2name ( last_rid as u32 ) . unwrap ( ) ;
0 commit comments