()
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public synchronized String[] nextWithName() throws FileFormatException { |
| 108 | if (!itr.hasNext()) { |
| 109 | return null; |
| 110 | } |
| 111 | |
| 112 | if (header == null) { |
| 113 | header = itr.next().trim(); |
| 114 | } |
| 115 | |
| 116 | if (header.isEmpty()) { |
| 117 | return null; //throw new FileFormatException("Empty FASTA header"); |
| 118 | } |
| 119 | |
| 120 | String name = null; |
| 121 | Matcher m = RECORD_NAME_COMMENT_PATTERN.matcher(header); |
| 122 | if (m.matches()) { |
| 123 | name = m.group(1); |
| 124 | if (removeNameSuffix) { |
| 125 | Matcher m2 = RECORD_NAME_PATTERN.matcher(name); |
| 126 | if (m2.matches()) { |
| 127 | name = m2.group(1); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | else { |
| 132 | throw new FileFormatException("Incorrect FASTA header format"); |
| 133 | } |
| 134 | |
| 135 | StringBuilder builder = new StringBuilder(); |
| 136 | while (itr.hasNext()) { |
| 137 | String line = itr.next().trim(); |
| 138 | if (line.isEmpty()) { |
| 139 | header = null; |
| 140 | break; |
| 141 | } |
| 142 | else if (line.charAt(0) == '>') { |
| 143 | header = line; |
| 144 | break; |
| 145 | } |
| 146 | else { |
| 147 | builder.append(line); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return new String[]{name, builder.toString()}; |
| 152 | } |
| 153 | |
| 154 | public synchronized void nextWithName(FastaRecord fr) throws FileFormatException { |
| 155 | if (!itr.hasNext()) { |
no test coverage detected