1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
use crate::Range;
use std::collections::{BTreeMap, VecDeque};
use std::{fmt, io, str};

pub struct LinesRef<'a, B: 'a> {
    buf: &'a mut B,
}

impl<'a, B: io::BufRead> Iterator for LinesRef<'a, B> {
    type Item = io::Result<String>;

    fn next(&mut self) -> Option<io::Result<String>> {
        let mut buf = String::new();
        match self.buf.read_line(&mut buf) {
            Ok(0) => None,
            Ok(_n) => {
                if buf.ends_with('\n') {
                    buf.pop();
                    if buf.ends_with('\r') {
                        buf.pop();
                    }
                }
                Some(Ok(buf))
            }
            Err(e) => Some(Err(e)),
        }
    }
}

/// Indicates one of the two strands.
fn parse_strand(strand: &str) -> Result<String, io::Error> {
    match strand {
        "+" => Ok("+".to_string()),
        "-" => Ok("-".to_string()),
        _ => Err(io::Error::new(io::ErrorKind::Other, "Strand not valid")),
    }
}

#[derive(Default, Clone)]
pub struct FasEntry {
    range: Range,
    seq: Vec<u8>,
}

impl FasEntry {
    // Immutable accessors
    pub fn range(&self) -> &Range {
        &self.range
    }
    pub fn seq(&self) -> &Vec<u8> {
        &self.seq
    }

    pub fn new() -> Self {
        Self {
            range: Range::new(),
            seq: vec![],
        }
    }

    /// Constructed from range and seq
    ///
    /// ```
    /// # use intspan::Range;
    /// # use intspan::FasEntry;
    /// let range = Range::from("I", 1, 10);
    /// let seq = "ACAGCTGA-AA".as_bytes().to_vec();
    /// let entry = FasEntry::from(&range, &seq);
    /// # assert_eq!(*entry.range().chr(), "I");
    /// # assert_eq!(*entry.range().start(), 1);
    /// # assert_eq!(*entry.range().end(), 10);
    /// # assert_eq!(std::str::from_utf8(entry.seq()).unwrap(), "ACAGCTGA-AA".to_string());
    /// ```
    pub fn from(range: &Range, seq: &[u8]) -> Self {
        Self {
            range: range.clone(),
            seq: seq.to_owned(),
        }
    }
}

/// To string
///
/// ```
/// # use intspan::Range;
/// # use intspan::FasEntry;
/// let range = Range::from("I", 1, 10);
/// let seq = "ACAGCTGA-AA".as_bytes().to_vec();
/// let entry = FasEntry::from(&range, &seq);
/// assert_eq!(entry.to_string(), ">I:1-10\nACAGCTGA-AA\n");
/// ```
impl fmt::Display for FasEntry {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            ">{}\n{}\n",
            self.range(),
            str::from_utf8(self.seq()).unwrap()
        )?;
        Ok(())
    }
}

/// A Fas alignment block.
pub struct FasBlock {
    pub entries: Vec<FasEntry>,
    pub names: Vec<String>,
    pub headers: Vec<String>,
}

/// Get the next FasBlock out of the input.
pub fn next_fas_block<T: io::BufRead + ?Sized>(mut input: &mut T) -> Result<FasBlock, io::Error> {
    let mut header: Option<String> = None;
    {
        let lines = LinesRef { buf: &mut input };
        for line_res in lines {
            let line: String = line_res?;
            if line.trim().is_empty() {
                // Blank line
                continue;
            }
            if line.starts_with('#') {
                // Fas comment
                continue;
            } else if line.starts_with('>') {
                // Start of a block
                header = Some(line);
                break;
            } else {
                // Shouldn't see this.
                return Err(io::Error::new(io::ErrorKind::Other, "Unexpected line"));
            }
        }
    }
    let block = parse_fas_block(
        header.ok_or(io::Error::new(io::ErrorKind::Other, "EOF"))?,
        LinesRef { buf: &mut input },
    )?;
    Ok(block)
}

pub fn parse_fas_block(
    header: String,
    iter: impl Iterator<Item = Result<String, io::Error>>,
) -> Result<FasBlock, io::Error> {
    let mut block_lines: VecDeque<String> = VecDeque::new();
    block_lines.push_back(header);

    for line_res in iter {
        let line: String = line_res?;
        if line.is_empty() {
            // Blank lines terminate the "paragraph".
            break;
        }
        block_lines.push_back(line);
    }
    let mut block_entries: Vec<FasEntry> = vec![];
    let mut block_names: Vec<String> = vec![];
    let mut block_headers: Vec<String> = vec![];

    while let Some(h) = block_lines.pop_front() {
        let header = match h.starts_with('>') {
            true => &h[1..],
            false => h.as_str(),
        };
        let range = Range::from_str(header);
        let seq = block_lines.pop_front().unwrap().as_bytes().to_vec();

        let entry = FasEntry::from(&range, &seq);
        block_entries.push(entry);
        block_names.push(range.name().to_string());
        block_headers.push(header.to_string());
    }

    Ok(FasBlock {
        entries: block_entries,
        names: block_names,
        headers: block_headers,
    })
}

// Axt
// https://genome.ucsc.edu/goldenPath/help/axt.html

/// Get the next Axt block out of the input.
pub fn next_axt_block<T: io::BufRead + ?Sized>(
    mut input: &mut T,
    sizes: &BTreeMap<String, i32>,
    tname: &String,
    qname: &String,
) -> Result<FasBlock, io::Error> {
    let mut header: Option<String> = None;
    {
        let lines = LinesRef { buf: &mut input };
        for line_res in lines {
            let line: String = line_res?;
            if line.trim().is_empty() {
                // Blank line
                continue;
            }
            if line.starts_with('#') {
                // Axt comment
                continue;
            } else if line.chars().next().unwrap().is_numeric() {
                // Start of a block
                header = Some(line);
                break;
            } else {
                // Shouldn't see this.
                return Err(io::Error::new(io::ErrorKind::Other, "Unexpected line"));
            }
        }
    }
    let block = parse_axt_block(
        header.ok_or(io::Error::new(io::ErrorKind::Other, "EOF"))?,
        LinesRef { buf: &mut input },
        sizes,
        tname,
        qname,
    )?;
    Ok(block)
}

pub fn parse_axt_block(
    header: String,
    iter: impl Iterator<Item = Result<String, io::Error>>,
    sizes: &BTreeMap<String, i32>,
    tname: &String,
    qname: &String,
) -> Result<FasBlock, io::Error> {
    let mut block_lines: VecDeque<String> = VecDeque::new();
    block_lines.push_back(header);

    for line_res in iter {
        let line: String = line_res?;
        if line.is_empty() {
            // Blank lines terminate the "paragraph".
            break;
        }
        block_lines.push_back(line);
    }
    let mut block_entries: Vec<FasEntry> = vec![];
    let mut block_names: Vec<String> = vec![];
    let mut block_headers: Vec<String> = vec![];

    // Three lines
    // Summary line
    let fields = block_lines
        .pop_front()
        .unwrap()
        .split_whitespace()
        .map(|s| s.to_string())
        .collect::<Vec<_>>();
    if fields.len() != 9 {
        return Err(io::Error::new(
            io::ErrorKind::Other,
            "Errors in the Axt summary line",
        ));
    }

    // 0 - Alignment number
    let f_chr = fields.get(1).unwrap();
    let f_begin = fields.get(2).unwrap().parse::<i32>().unwrap();
    let f_end = fields.get(3).unwrap().parse::<i32>().unwrap();

    let g_chr = fields.get(4).unwrap();
    let mut g_begin = fields.get(5).unwrap().parse::<i32>().unwrap();
    let mut g_end = fields.get(6).unwrap().parse::<i32>().unwrap();

    let g_strand = fields.get(7).unwrap();
    // 8 - Blastz score

    if !sizes.contains_key(g_chr) {
        return Err(io::Error::new(
            io::ErrorKind::Other,
            ".sizes file doesn't contain the needed chr",
        ));
    }

    if g_strand == "-" {
        g_begin = sizes.get(g_chr).unwrap() - g_begin + 1;
        g_end = sizes.get(g_chr).unwrap() - g_end + 1;
        (g_begin, g_end) = (g_end, g_begin);
    }

    // Sequence lines
    let f_seq = block_lines.pop_front().unwrap().as_bytes().to_vec();
    let g_seq = block_lines.pop_front().unwrap().as_bytes().to_vec();

    // Build ranges
    let mut f_range = Range::from(f_chr, f_begin, f_end);
    *f_range.name_mut() = tname.to_string();
    *f_range.strand_mut() = "+".to_string();

    let mut g_range = Range::from(g_chr, g_begin, g_end);
    *g_range.name_mut() = qname.to_string();
    *g_range.strand_mut() = g_strand.to_string();

    // Build entries
    let f_entry = FasEntry::from(&f_range, &f_seq);
    block_entries.push(f_entry);
    block_names.push(f_range.name().to_string());
    block_headers.push(f_range.to_string());

    let g_entry = FasEntry::from(&g_range, &g_seq);
    block_entries.push(g_entry);
    block_names.push(g_range.name().to_string());
    block_headers.push(g_range.to_string());

    Ok(FasBlock {
        entries: block_entries,
        names: block_names,
        headers: block_headers,
    })
}

#[cfg(test)]
mod fas_tests {
    use super::*;
    use std::io::BufReader;

    #[test]
    fn parse_fas_block_range() {
        let str = ">S288c.I(+):13267-13287|species=S288c
TCGTCAGTTGGTTGACCATTA
>YJM789.gi_151941327(-):5668-5688|species=YJM789
TCGTCAGTTGGTTGACCATTA
>RM11.gi_61385832(-):5590-5610|species=RM11
TCGTCAGTTGGTTGACCATTA
>Spar.gi_29362400(+):2477-2497|species=Spar
TCATCAGTTGGCAAACCGTTA

>S288c.I(+):185273-185334|species=S288c
GCATATAATATGAACCAATATCTA-TTCATGAAGAGACTATGGTATACCCGGTACTATTTCTA
>YJM789.gi_151941327(+):156665-156726|species=YJM789
GCGTATAATATGAACCAGTATCTTTTTCATGAAG-GGCTATGGTATACTCCATATTACTTCTA
>RM11.gi_61385833(-):3668-3730|species=RM11
GCATATAATATGAACCAATATCTATTTCATGGAGAGACTATGATAT-CCCCGTACTATTTCTA
>Spar.gi_29362478(-):2102-2161|species=Spar
GC-TAAAATATGAA-CGATATTTA-CCTGTAGAGGGACTATGGGAT-CCCCATACTACTTT--
";
        let mut reader = BufReader::new(str.as_bytes());
        let block = next_fas_block(&mut reader).unwrap();
        assert_eq!(
            block.entries.get(0).unwrap().range.to_string(),
            "S288c.I(+):13267-13287".to_string()
        );
        assert_eq!(
            block.entries.get(2).unwrap().range.to_string(),
            "RM11.gi_61385832(-):5590-5610".to_string()
        );

        let block = next_fas_block(&mut reader).unwrap();
        assert_eq!(
            String::from_utf8(block.entries.get(1).unwrap().seq.clone()).unwrap(),
            "GCGTATAATATGAACCAGTATCTTTTTCATGAAG-GGCTATGGTATACTCCATATTACTTCTA".to_string()
        );
    }
}

// MAF
// https://genome.ucsc.edu/FAQ/FAQformat.html#format5
// https://github.com/joelarmstrong/maf_stream/blob/master/multiple_alignment_format/src/parser.rs

/// An alignment entry within a MAF block. Corresponds to the "s" line.
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct MafEntry {
    /// Actual sequence of bases/amino acids, including gaps.
    pub alignment: Vec<u8>,
    /// The sequence name.
    pub src: String,
    /// Start of the aligned region within this sequence.
    pub start: u64,
    /// Length of the aligned region (not including gaps).
    pub size: u64,
    /// The total length of this sequence (including regions outside
    /// this alignment).
    pub src_size: u64,
    /// Which strand the aligned sequence is on.
    pub strand: String,
}

impl MafEntry {
    /// create a range string from a MAF entry
    pub fn to_range(&self) -> String {
        let mut range = String::new();

        // adjust coordinates to be one-based inclusive
        let mut start = self.start + 1;
        let mut end = start + self.size - 1;

        // If the strand field is "-" then this is the start relative to the reverse-complemented source sequence
        if self.strand == *"-" {
            start = self.src_size - start + 1;
            end = self.src_size - end + 1;
            (start, end) = (end, start);
        }

        range += self.src.as_str();

        range += "(";
        range += self.strand.as_str();
        range += ")";
        range += ":";

        range += start.to_string().as_str();
        range += "-";
        range += end.to_string().as_str();

        range
    }
}

/// A MAF alignment block.
#[derive(Debug, PartialEq, Eq)]
pub struct MafBlock {
    pub entries: Vec<MafEntry>,
}

/// Get the next MafBlock out of the input.
pub fn next_maf_block<T: io::BufRead + ?Sized>(mut input: &mut T) -> Result<MafBlock, io::Error> {
    let mut header: Option<String> = None;
    {
        let lines = LinesRef { buf: &mut input };
        for line_res in lines {
            let line: String = line_res?;
            if line.trim().is_empty() {
                // Blank line
                continue;
            }
            if line.starts_with('#') {
                // MAF comment
                continue;
            } else if line.starts_with('a') {
                // Start of a block
                header = Some(line);
                break;
            } else {
                // Shouldn't see this.
                return Err(io::Error::new(io::ErrorKind::Other, "Unexpected line"));
            }
        }
    }
    let block = parse_maf_block(
        header.ok_or(io::Error::new(io::ErrorKind::Other, "EOF"))?,
        LinesRef { buf: &mut input },
    )?;
    Ok(block)
}

fn parse_s_line(
    fields: &mut Vec<&str>,
    block_entries: &mut Vec<MafEntry>,
) -> Result<(), io::Error> {
    let alignment = fields
        .pop()
        .ok_or(io::Error::new(io::ErrorKind::Other, "s line incomplete"))?;
    let src_size = fields
        .pop()
        .ok_or(io::Error::new(io::ErrorKind::Other, "s line incomplete"))
        .and_then(|s| {
            s.parse::<u64>()
                .map_err(|_| io::Error::new(io::ErrorKind::Other, "invalid sequence size"))
        })?;
    let strand = fields
        .pop()
        .ok_or(io::Error::new(io::ErrorKind::Other, "s line incomplete"))
        .and_then(parse_strand)?;
    let aligned_length = fields
        .pop()
        .ok_or(io::Error::new(io::ErrorKind::Other, "s line incomplete"))
        .and_then(|s| {
            s.parse::<u64>()
                .map_err(|_| io::Error::new(io::ErrorKind::Other, "invalid aligned length"))
        })?;
    let start = fields
        .pop()
        .ok_or(io::Error::new(io::ErrorKind::Other, "s line incomplete"))
        .and_then(|s| {
            s.parse::<u64>()
                .map_err(|_| io::Error::new(io::ErrorKind::Other, "invalid start"))
        })?;
    let src = fields
        .pop()
        .ok_or(io::Error::new(io::ErrorKind::Other, "s line incomplete"))?;
    block_entries.push(MafEntry {
        alignment: alignment.as_bytes().to_vec(),
        src: src.to_string(),
        start,
        size: aligned_length,
        src_size,
        strand,
    });
    Ok(())
}

pub fn parse_maf_block(
    header: String,
    iter: impl Iterator<Item = Result<String, io::Error>>,
) -> Result<MafBlock, io::Error> {
    let mut block_lines = vec![];
    block_lines.push(header);

    for line_res in iter {
        let line: String = line_res?;
        if line.is_empty() {
            // Blank lines terminate the "paragraph".
            break;
        }
        block_lines.push(line);
    }
    let mut block_entries: Vec<MafEntry> = vec![];

    for line in block_lines {
        let mut fields: Vec<_> = line.split_whitespace().collect();
        match fields[0] {
            "a" => (),
            "s" => parse_s_line(&mut fields, &mut block_entries)?,
            "i" => (),
            "e" => (),
            "q" => (),
            "track" => (),
            _ => return Err(io::Error::new(io::ErrorKind::Other, "BadLineType")),
        };
    }

    Ok(MafBlock {
        entries: block_entries,
    })
}

#[cfg(test)]
mod maf_tests {
    use super::*;
    use std::io::{BufRead, BufReader};

    #[test]
    fn parse_comment() {
        let str = "##maf version=1";
        let mut reader = BufReader::new(str.as_bytes());
        let res = next_maf_block(&mut reader);
        eprintln!("got error {:?}", res.as_ref().err());
        assert!(matches!(res.unwrap_err().kind(), io::ErrorKind::Other));
    }

    #[test]
    fn parse_blank_comment() {
        let str = "#";
        let mut reader = BufReader::new(str.as_bytes());
        let res = next_maf_block(&mut reader);
        assert!(matches!(res.unwrap_err().kind(), io::ErrorKind::Other));
    }

    #[test]
    fn parse_err_unexpected() {
        let str = "#\nUnexpected";
        let mut reader = BufReader::new(str.as_bytes());
        let res = next_maf_block(&mut reader);
        eprintln!("got error {:?}", res.as_ref().err());
        assert!(matches!(res.unwrap_err().kind(), io::ErrorKind::Other));
    }

    #[test]
    fn parse_err_s() {
        let str = "#\na\ns 123";
        let mut reader = BufReader::new(str.as_bytes());
        let res = next_maf_block(&mut reader);
        eprintln!("got error {:?}", res.as_ref().err());
        assert!(matches!(res.unwrap_err().kind(), io::ErrorKind::Other));
    }

    #[test]
    fn parse_block_a() {
        let str = "#\na score=23262.0 pass=2";
        let mut reader = BufReader::new(str.as_bytes());
        match next_maf_block(&mut reader) {
            Err(e) => assert!(false, "Got error {:?}", e),
            Ok(val) => assert_eq!(val, MafBlock { entries: vec![] }),
        }
    }

    #[test]
    fn parse_block_a_empty() {
        let str = "#\na";
        let mut reader = BufReader::new(str.as_bytes());
        match next_maf_block(&mut reader) {
            Err(e) => assert!(false, "Got error {:?}", e),
            Ok(val) => assert_eq!(val, MafBlock { entries: vec![] }),
        }
    }

    #[test]
    fn parse_block_s_lines() {
        let str = "a meta1=val1 meta2=val2
s hg16.chr7    27707221 13 + 158545518 gcagctgaaaaca
s baboon         249182 12 -   4622798 gcagctgaa-aca
i baboon       I 234 n 19
s mm4.chr6     53310102 12 + 151104725 ACAGCTGA-AATA

this line is a canary to ensure it stops after a 'paragraph'";
        let mut lines = BufReader::new(str.as_bytes()).lines();
        let header = lines.next().unwrap().unwrap();
        match parse_maf_block(header, lines) {
            Err(e) => assert!(false, "got error {:?}", e),
            Ok(val) => assert_eq!(
                val,
                MafBlock {
                    entries: vec![
                        MafEntry {
                            src: "hg16.chr7".to_owned(),
                            start: 27707221,
                            size: 13,
                            src_size: 158545518,
                            strand: "+".to_string(),
                            alignment: "gcagctgaaaaca".as_bytes().to_vec(),
                        },
                        MafEntry {
                            src: "baboon".to_owned(),
                            start: 249182,
                            size: 12,
                            src_size: 4622798,
                            strand: "-".to_string(),
                            alignment: "gcagctgaa-aca".as_bytes().to_vec(),
                        },
                        MafEntry {
                            src: "mm4.chr6".to_owned(),
                            start: 53310102,
                            size: 12,
                            src_size: 151104725,
                            strand: "+".to_string(),
                            alignment: "ACAGCTGA-AATA".as_bytes().to_vec(),
                        },
                    ],
                }
            ),
        }
    }

    #[test]
    fn parse_block_s_range() {
        let str = "##maf version=1 scoring=multiz
a score=514600.0
s S288c.VIII          13376 34 + 562643 TTACTCGTCTTGCGGCCAAAACTCGAAGAAAAAC
s RM11_1a.scaffold_12  3529 34 + 536628 TTACTCGTCTTGCGGCCAAAACTCGAAGAAAAAC
s EC1118.FN393072_1    8746 34 + 161280 TTACTCGTCTTGCGGCCAAAACTCGAAGAAAAAC
s Spar.gi_29362578      637 33 -  73522 TTACCCGTCTTGCGTCCAAAACTCGAA-AAAAAC

a score=36468.0
s S288c.VIII          193447  99 + 562643 CG--GCATAATTTTTTCCAGGCACTTTCCGCTGCAG---TTGTTGTGCTGACAATAGTCCCATCTAGGTCAAAAAGACAAAGATCTACTGAAAATTGTGGCAtt
s RM11_1a.scaffold_12 189216 101 + 536628 CGTAACACAACTTGGTCCATGC---TTTCTCTGCGGCCACTGTTGTACTCACTATGGTACCATCTAGGTCAAAAAGACATAGATCAGCTGAAAATTCTGCCATT
s EC1118.FN393073_1    25682  99 +  44323 CG--GCATAATTTTTTCCAGGCACTTTCCGCTGCAG---TTGTTGTGCTGACAATAGTCCCATCTAGGTCAAAAAGACAAAGATCTACTGAAAATTGTGGCAtt
s Spar.gi_29362604    100946  97 - 143114 CG--ACATAGTTTTTTCCAGGCACTTTCAGCTGCGG---TTGTTGTGCTAACAATGGTCCCATCTAGGTCAAAAAGGCAGAGATCTACTGAAAATTGTGGCA--
";
        let mut reader = BufReader::new(str.as_bytes());
        let block = next_maf_block(&mut reader).unwrap();
        assert_eq!(
            block.entries.get(0).unwrap().to_range(),
            "S288c.VIII(+):13377-13410".to_string()
        );
        assert_eq!(
            block.entries.get(3).unwrap().to_range(),
            "Spar.gi_29362578(-):72853-72885".to_string()
        );

        let block = next_maf_block(&mut reader).unwrap();
        assert_eq!(
            block.entries.get(1).unwrap().to_range(),
            "RM11_1a.scaffold_12(+):189217-189317".to_string()
        );
        assert_eq!(
            block.entries.get(3).unwrap().to_range(),
            "Spar.gi_29362604(-):42072-42168".to_string()
        );
    }
}