ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/PrimerMatch/pattern_match.h
Revision: 1.1.1.1 (vendor branch)
Committed: Wed Dec 22 21:37:18 2004 UTC (11 years, 4 months ago) by nje01
Branch: MAIN
CVS Tags: HEAD, RELEASE-20041222, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
Initial primer_match import

Line File contents
1 /**************************************************************************
2 * This code is part of the supporting infrastructure for ATA Mapper.
3 * Copyright (C) 2002,2003,2004 Applera Corporation. All rights reserved.
4 * Author: Nathan Edwards
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received (LICENSE.txt) a copy of the GNU General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *************************************************************************/
20
21
22 #ifndef _IBPEP_pattern_match_h
23 #define _IBPEP_pattern_match_h
24
25 #include <list>
26 #include <iostream>
27 #include <iomanip>
28 // #include <ios>
29 #include "char_io.h"
30 #include "types.h"
31 #include "tinylist.t"
32 #include "sortedvector.t"
33 #include "pattern_alignment.h"
34
35 #if !defined(NO_STD_NAMESPACE)
36 using namespace std;
37 #endif
38
39 class pattern_list_element {
40 private:
41 std::string pattern_;
42 unsigned long length_;
43 unsigned long id_;
44 int exact_start_bases_;
45 int exact_end_bases_;
46 public:
47 pattern_list_element() : pattern_(""), length_(0), id_(0),
48 exact_start_bases_(0), exact_end_bases_(0) {}
49 pattern_list_element(std::string const & p, unsigned long const & i,
50 int esb=0, int eeb=0)
51 : pattern_(p), length_(0), id_(i), exact_start_bases_(esb), exact_end_bases_(eeb) {
52 length_ = pattern_.length();
53 }
54 ~pattern_list_element() {}
55 std::string const & pattern() const {
56 return pattern_;
57 }
58 void pattern(std::string const & p) {
59 pattern_ = p;
60 length_ = p.length();
61 }
62 unsigned long int const & id() const {
63 return id_;
64 }
65 void id(unsigned long int i) {
66 id_ = i;
67 }
68 unsigned long int const & length() const {
69 return length_;
70 }
71 int exact_start_bases() const {
72 return exact_start_bases_;
73 }
74 int exact_end_bases() const {
75 return exact_end_bases_;
76 }
77 void exact_start_bases(int esb) {
78 exact_start_bases_ = esb;
79 }
80 void exact_end_bases(int eeb) {
81 exact_end_bases_ = eeb;
82 }
83 void read(istream & is) {
84 is >> id_ >> pattern_;
85 }
86 void write(ostream & os) const {
87 os << id_ << " " << pattern_;
88 }
89 };
90
91 ostream & operator<<(ostream & os, pattern_list_element const & ple);
92 istream & operator>>(ostream & is, pattern_list_element & ple);
93
94 typedef tinylist<pattern_list_element> pattern_list;
95
96 class pattern_hit;
97
98 typedef sortedvector<FILE_POSITION_TYPE,pattern_list::const_iterator> pattern_hit_vector;
99
100 class PatternMatch {
101 private:
102 long unsigned int next_pattern_id_;
103 pattern_list patterns_;
104 pattern_list::iterator pit_;
105 float pint_;
106 float pcur_;
107 protected:
108 pattern_list::const_iterator
109 add_pattern_(std::string const & pat, long unsigned int & id,
110 int esb=0, int eeb=0) {
111 if (id == 0) {
112 id= ++next_pattern_id_;
113 }
114 if (pit_ == patterns_.end()) {
115 pit_ = patterns_.push_front(pattern_list_element(pat,id,esb,eeb));
116 } else {
117 pit_ = patterns_.insert_after(pit_,pattern_list_element(pat,id,esb,eeb));
118 }
119 return pit_;
120 }
121 pattern_list const & patterns() const {
122 return patterns_;
123 }
124 public:
125 PatternMatch() {
126 next_pattern_id_=0;
127 pit_ = patterns_.end();
128 pcur_=0.0;
129 pint_=-1.0;
130 };
131 virtual ~PatternMatch();
132 virtual long unsigned int add_pattern(std::string const & pat,
133 unsigned long id=0,
134 int exact_start_bases=0,
135 int exact_end_bases=0)=0;
136 virtual void init(CharacterProducer & cp)=0;
137 virtual bool find_patterns(CharacterProducer & cp,
138 pattern_hit_vector & pas,
139 long unsigned minka=1)=0;
140 virtual void reset()=0;
141 virtual void progress_interval(CharacterProducer & cp, float p=1.0) {
142 if (p >= 0.0 && p <= 100) {
143 pcur_ = cp.progress();
144 pint_ = p/100;
145 } else {
146 pcur_ = 0.0;
147 pint_ = -1.0;
148 }
149 }
150 void report_progress(CharacterProducer const & cp) {
151 if (pint_ >= 0 && cp.progress() > pcur_) {
152 ostrstream ss;
153 ss.setf(ios::fixed);
154 ss << "Progress:";
155 ss << setprecision(1) << setw(5) << cp.progress()*100;
156 ss << "%" << ends;
157 std::string v(ss.str());
158 timestamp(v.c_str());
159 pcur_ = cp.progress() + pint_;
160 }
161 }
162 };
163
164 #endif