Skip to content

Commit d724aec

Browse files
committed
Need to propagate down also this bit of information. Since two parameters more may be less readable I changed strategy and configured parser class.
1 parent 4fd3fdb commit d724aec

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

biojava-core/src/main/java/org/biojava/nbio/core/sequence/io/GenbankSequenceParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ private String parse(BufferedReader bufferedReader) {
182182

183183
isCircularSequence = m.group(7).equalsIgnoreCase("circular");
184184

185+
// configure location parser with needed information
186+
locationParser.setSequenceLength(sequenceLength);
187+
locationParser.setSequenceCircular(isCircularSequence);
188+
185189
log.debug("compound type: {}", compoundType.getClass().getSimpleName());
186190

187191
} else {
@@ -284,7 +288,7 @@ private String parse(BufferedReader bufferedReader) {
284288
// new feature!
285289
gbFeature = new TextFeature(key, val, key, key);
286290
Location l =
287-
locationParser.parse(val, isCircularSequence);
291+
locationParser.parse(val);
288292
gbFeature.setLocation((AbstractLocation)l);
289293

290294
if (!featureCollection.containsKey(key)) {

biojava-core/src/main/java/org/biojava/nbio/core/sequence/location/InsdcParser.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.IOException;
3636
import java.io.Reader;
3737
import java.util.ArrayList;
38+
import java.util.Arrays;
3839
import java.util.List;
3940
import java.util.regex.Matcher;
4041
import java.util.regex.Pattern;
@@ -49,6 +50,9 @@
4950
*/
5051
public class InsdcParser <S extends AbstractSequence<C>, C extends Compound>{
5152

53+
private boolean isSequenceCircular;
54+
private long sequenceLength;
55+
5256
private final DataSource dataSource;
5357

5458
/**
@@ -80,7 +84,6 @@ public class InsdcParser <S extends AbstractSequence<C>, C extends Compound>{
8084
* Not really sure that they are not declared obsolete but they are still in
8185
* several files.
8286
*/
83-
//protected static final Pattern genbankSplitPattern = Pattern.compile("^\\s?(join|order|bond|complement|)\\(?([^\\)]+)\\)?");
8487
protected static final Pattern genbankSplitPattern = Pattern.compile("^\\s?(join|order|bond|complement|)\\(?(.+)\\)?");
8588
/**
8689
* designed to recursively split a location string in tokens. Valid tokens
@@ -126,7 +129,13 @@ public DataSource getDataSource() {
126129
return dataSource;
127130
}
128131

132+
public void setSequenceCircular(boolean sequenceCircular) {
133+
isSequenceCircular = sequenceCircular;
134+
}
129135

136+
public void setSequenceLength(long sequenceLength) {
137+
this.sequenceLength = sequenceLength;
138+
}
130139

131140
/**
132141
* Main method for parsing a location from a String instance
@@ -135,12 +144,12 @@ public DataSource getDataSource() {
135144
* @return The parsed location
136145
* @throws ParserException thrown in the event of any error during parsing
137146
*/
138-
public Location parse(String locationString, boolean isSequenceCircular) throws ParserException {
147+
public Location parse(String locationString) throws ParserException {
139148
featureGlobalStart = Integer.MAX_VALUE;
140149
featureGlobalEnd = 1;
141150

142151
Location l;
143-
List<Location> ll = parseLocationString(locationString, 1, isSequenceCircular);
152+
List<Location> ll = parseLocationString(locationString, 1);
144153

145154
if (ll.size() == 1) {
146155
l = ll.get(0);
@@ -155,10 +164,6 @@ public Location parse(String locationString, boolean isSequenceCircular) throws
155164
return l;
156165
}
157166

158-
public Location parse(String locationString) throws ParserException {
159-
return parse(locationString, false);
160-
}
161-
162167
/**
163168
* Reader based version of the parse methods.
164169
*
@@ -173,7 +178,7 @@ public List<AbstractLocation> parse(Reader reader) throws IOException, ParserExc
173178
return null;
174179
}
175180

176-
private List<Location> parseLocationString(String string, int versus, boolean isSequenceCircular) throws ParserException {
181+
private List<Location> parseLocationString(String string, int versus) throws ParserException {
177182
Matcher m;
178183
List<Location> boundedLocationsCollection = new ArrayList<Location>();
179184

@@ -192,7 +197,7 @@ private List<Location> parseLocationString(String string, int versus, boolean is
192197
//recursive case
193198
int localVersus = splitQualifier.equalsIgnoreCase("complement") ? -1 : 1;
194199
List<Location> subLocations = parseLocationString(
195-
splitString, versus * localVersus, isSequenceCircular);
200+
splitString, versus * localVersus);
196201

197202
switch (complexFeaturesAppendMode) {
198203
case FLATTEN:

0 commit comments

Comments
 (0)