@@ -156,43 +156,47 @@ find_offset_for_msite(const std::string &chr,
156156}
157157
158158
159-
160159bool
161- is_msite_file (const string &file) {
162- ifstream in (file);
163- if (!in)
164- throw runtime_error (" cannot open file: " + file);
165-
166- string line;
167- if (!getline (in, line)) return false ;
160+ is_msite_line (const string &line) {
168161
169162 std::istringstream iss (line);
170163
171164 string chrom;
172165 if (!(iss >> chrom)) return false ;
173-
166+
174167 long int pos = 0 ;
175168 if (!(iss >> pos)) return false ;
176169
177170 string strand;
178- if (!(iss >> strand) ||
179- (strand.size () != 1 ) ||
180- ((strand != " +" ) && (strand != " -" )) )
171+ if (!(iss >> strand) ||
172+ (strand.size () != 1 ) ||
173+ ((strand != " +" ) && (strand != " -" )) )
181174 return false ;
182175
183176 string context;
184177 std::regex pattern (" ^C[pHWX][GH]$" );
185178 if (!(iss >> context) || !regex_match (context, pattern)) return false ;
186179
187180 double level = 0.0 ;
188- if (!(iss >> level) || level < 0 || level > 1 ) return false ;
181+ if (!(iss >> level) || level < 0.0 || level > 1.0 ) return false ;
189182
190183 long int n_reads = 0 ;
191- if (!(iss >> n_reads)) return false ;
184+ if (!(iss >> n_reads) || n_reads < 0 ) return false ;
192185
193186 string temp;
194187 if (iss >> temp) return false ;
195188 else return true ;
196189
197190}
198191
192+ bool
193+ is_msite_file (const string &file) {
194+ bamxx::bgzf_file in (file, " r" );
195+ if (!in)
196+ throw runtime_error (" cannot open file: " + file);
197+
198+ string line;
199+ if (!getline (in, line)) return false ;
200+
201+ return is_msite_line (line);
202+ }
0 commit comments