Skip to content

Commit 32d6d7d

Browse files
committed
Add all Genbank qualifiers to attributes.
1 parent fb159c1 commit 32d6d7d

3 files changed

Lines changed: 67 additions & 3 deletions

File tree

src/main/java/org/biojava/nbio/adam/convert/DnaSequenceToFeatures.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
package org.biojava.nbio.adam.convert;
2525

2626
import java.util.ArrayList;
27+
import java.util.HashMap;
28+
import java.util.Iterator;
2729
import java.util.List;
30+
import java.util.Map;
2831

2932
import javax.annotation.concurrent.Immutable;
3033

@@ -39,6 +42,7 @@
3942
import org.biojava.nbio.core.sequence.DNASequence;
4043

4144
import org.biojava.nbio.core.sequence.features.FeatureInterface;
45+
import org.biojava.nbio.core.sequence.features.Qualifier;
4246

4347
import org.biojava.nbio.core.sequence.location.template.AbstractLocation;
4448
import org.biojava.nbio.core.sequence.location.template.Point;
@@ -135,10 +139,28 @@ else if (feature.getDescription() != null) {
135139
fb.clearName();
136140
}
137141

138-
// todo: dbxref, ontology term, attributes
142+
Map<String, String> attributes = new HashMap<String, String>();
143+
Map<String, List<Qualifier>> qualifiers = feature.getQualifiers();
144+
for (Map.Entry<String, List<Qualifier>> entry : qualifiers.entrySet()) {
145+
String key = entry.getKey();
146+
List<Qualifier> value = entry.getValue();
147+
StringBuilder sb = new StringBuilder();
148+
for (Iterator<Qualifier> i = value.iterator(); i.hasNext(); ) {
149+
sb.append(i.next().getValue());
150+
if (i.hasNext()) {
151+
sb.append(",");
152+
}
153+
}
154+
attributes.put(key, sb.toString());
155+
}
156+
if (!attributes.isEmpty()) {
157+
fb.setAttributes(attributes);
158+
}
159+
139160
features.add(fb.build());
140161
}
141162

142163
return features;
143164
}
165+
144166
}

src/main/java/org/biojava/nbio/adam/convert/ProteinSequenceToFeatures.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
package org.biojava.nbio.adam.convert;
2525

2626
import java.util.ArrayList;
27+
import java.util.HashMap;
28+
import java.util.Iterator;
2729
import java.util.List;
30+
import java.util.Map;
2831

2932
import javax.annotation.concurrent.Immutable;
3033

@@ -39,6 +42,7 @@
3942
import org.biojava.nbio.core.sequence.ProteinSequence;
4043

4144
import org.biojava.nbio.core.sequence.features.FeatureInterface;
45+
import org.biojava.nbio.core.sequence.features.Qualifier;
4246

4347
import org.biojava.nbio.core.sequence.location.template.AbstractLocation;
4448
import org.biojava.nbio.core.sequence.location.template.Point;
@@ -135,7 +139,24 @@ else if (feature.getDescription() != null) {
135139
fb.clearName();
136140
}
137141

138-
// todo: dbxref, ontology term, attributes
142+
Map<String, String> attributes = new HashMap<String, String>();
143+
Map<String, List<Qualifier>> qualifiers = feature.getQualifiers();
144+
for (Map.Entry<String, List<Qualifier>> entry : qualifiers.entrySet()) {
145+
String key = entry.getKey();
146+
List<Qualifier> value = entry.getValue();
147+
StringBuilder sb = new StringBuilder();
148+
for (Iterator<Qualifier> i = value.iterator(); i.hasNext(); ) {
149+
sb.append(i.next().getValue());
150+
if (i.hasNext()) {
151+
sb.append(",");
152+
}
153+
}
154+
attributes.put(key, sb.toString());
155+
}
156+
if (!attributes.isEmpty()) {
157+
fb.setAttributes(attributes);
158+
}
159+
139160
features.add(fb.build());
140161
}
141162

src/main/java/org/biojava/nbio/adam/convert/RnaSequenceToFeatures.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
package org.biojava.nbio.adam.convert;
2525

2626
import java.util.ArrayList;
27+
import java.util.HashMap;
28+
import java.util.Iterator;
2729
import java.util.List;
30+
import java.util.Map;
2831

2932
import javax.annotation.concurrent.Immutable;
3033

@@ -39,6 +42,7 @@
3942
import org.biojava.nbio.core.sequence.RNASequence;
4043

4144
import org.biojava.nbio.core.sequence.features.FeatureInterface;
45+
import org.biojava.nbio.core.sequence.features.Qualifier;
4246

4347
import org.biojava.nbio.core.sequence.location.template.AbstractLocation;
4448
import org.biojava.nbio.core.sequence.location.template.Point;
@@ -135,7 +139,24 @@ else if (feature.getDescription() != null) {
135139
fb.clearName();
136140
}
137141

138-
// todo: dbxref, ontology term, attributes
142+
Map<String, String> attributes = new HashMap<String, String>();
143+
Map<String, List<Qualifier>> qualifiers = feature.getQualifiers();
144+
for (Map.Entry<String, List<Qualifier>> entry : qualifiers.entrySet()) {
145+
String key = entry.getKey();
146+
List<Qualifier> value = entry.getValue();
147+
StringBuilder sb = new StringBuilder();
148+
for (Iterator<Qualifier> i = value.iterator(); i.hasNext(); ) {
149+
sb.append(i.next().getValue());
150+
if (i.hasNext()) {
151+
sb.append(",");
152+
}
153+
}
154+
attributes.put(key, sb.toString());
155+
}
156+
if (!attributes.isEmpty()) {
157+
fb.setAttributes(attributes);
158+
}
159+
139160
features.add(fb.build());
140161
}
141162

0 commit comments

Comments
 (0)