File: AlignmentPot.hh

package info (click to toggle)
last-align 1651-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,688 kB
  • sloc: cpp: 44,419; python: 5,217; ansic: 1,938; sh: 710; makefile: 457
file content (65 lines) | stat: -rw-r--r-- 2,169 bytes parent folder | download
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
// Copyright 2008 Martin C. Frith

// This struct holds alignments, and includes a procedure to
// non-redundantize alignments that share endpoints.

#ifndef ALIGNMENTPOT_HH
#define ALIGNMENTPOT_HH
#include "Alignment.hh"
#include <algorithm>  // sort
#include <vector>

namespace cbrc{

struct AlignmentPot{
  typedef std::vector<Alignment>::iterator iterator;

  // add an alignment to the pot
  void add( const Alignment& aln ) { items.push_back(aln); }

  // the number of alignments in the pot
  size_t size() const { return items.size(); }

  // if several alignments share an endpoint, erase all but one
  // highest-scoring alignment
  void eraseSuboptimal();

  // sort the alignments in ascending order of score
  void sort() { std::sort(items.begin(), items.end(), lessScore); }

  // data:
  std::vector<Alignment> items;

  static bool lessScore(const Alignment &x, const Alignment &y) {
    // Try to break ties, so that alignments come in a consistent
    // order.  This makes it easier to compare different results.
    return x.score != y.score ? x.score < y.score : !lessBeg(x, y);
  }

  static bool lessBeg( const Alignment& x, const Alignment& y ){
    if( x.beg1() != y.beg1() ) return x.beg1() < y.beg1();
    if( x.beg2() != y.beg2() ) return x.beg2() < y.beg2();
    if( x.score  != y.score  ) return x.score  > y.score;
    // arbitrary (but systematic) order:
    const SegmentPair& a = x.seed;
    const SegmentPair& b = y.seed;
    return a.beg1() != b.beg1() ? a.beg1() < b.beg1() : a.beg2() < b.beg2();
  }

  static bool lessEnd( const Alignment& x, const Alignment& y ){
    if( x.end1() != y.end1() ) return x.end1() < y.end1();
    if( x.end2() != y.end2() ) return x.end2() < y.end2();
    if( x.score  != y.score  ) return x.score  > y.score;
    // arbitrary (but systematic) order:
    const SegmentPair& a = x.seed;
    const SegmentPair& b = y.seed;
    return a.beg1() != b.beg1() ? a.beg1() < b.beg1() : a.beg2() < b.beg2();
  }

  static void mark( Alignment& a ) { a.blocks[0].score = -1; }

  static bool isMarked( Alignment& a ) { return a.blocks[0].score == -1; }
};

}  // end namespace cbrc
#endif  // ALIGNMENTPOT_HH