()
| 203 | } |
| 204 | |
| 205 | public synchronized String[] nextWithComment() throws FileFormatException { |
| 206 | if (!itr.hasNext()) { |
| 207 | return null; |
| 208 | } |
| 209 | |
| 210 | if (header == null) { |
| 211 | header = itr.next().trim(); |
| 212 | } |
| 213 | |
| 214 | if (header.isEmpty()) { |
| 215 | return null; //throw new FileFormatException("Empty FASTA header"); |
| 216 | } |
| 217 | |
| 218 | String name, comment = null; |
| 219 | Matcher m = RECORD_NAME_COMMENT_PATTERN.matcher(header); |
| 220 | if (m.matches()) { |
| 221 | name = m.group(1); |
| 222 | comment = m.group(2); |
| 223 | if (removeNameSuffix) { |
| 224 | Matcher m2 = RECORD_NAME_PATTERN.matcher(name); |
| 225 | if (m2.matches()) { |
| 226 | name = m2.group(1); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | else { |
| 231 | throw new FileFormatException("Incorrect FASTA header format"); |
| 232 | } |
| 233 | |
| 234 | StringBuilder builder = new StringBuilder(); |
| 235 | while (itr.hasNext()) { |
| 236 | String line = itr.next().trim(); |
| 237 | if (line.isEmpty()) { |
| 238 | header = null; |
| 239 | break; |
| 240 | } |
| 241 | else if (line.charAt(0) == '>') { |
| 242 | header = line; |
| 243 | break; |
| 244 | } |
| 245 | else { |
| 246 | builder.append(line); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | return new String[]{name, comment, builder.toString()}; |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void close() throws IOException { |
no test coverage detected