Skip to content

Commit e8ac28e

Browse files
committed
Support for SnapGene Server
Added read/write/detectFeatures for SnapGene server Support default displayId's for conversion Update some javadocs File type for dna/json/turtle determined now by file suffix Added support to read/write SnapGene DNA files Added options for SnapGene output to validate
1 parent 0b4cf64 commit e8ac28e

15 files changed

Lines changed: 670 additions & 246 deletions

File tree

core2/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
<artifactId>guava</artifactId>
9797
<version>19.0</version>
9898
</dependency>
99+
<dependency>
100+
<groupId>org.apache.commons</groupId>
101+
<artifactId>commons-lang3</artifactId>
102+
<version>3.7</version>
103+
</dependency>
99104
</dependencies>
100105

101106
<repositories>

core2/src/main/java/org/sbolstandard/core2/FASTA.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private static Sequence createSequence(SBOLDocument doc,String URIprefix,String
134134
* @throws SBOLValidationException if an SBOL validation rule was violated in {@link #createSequence(SBOLDocument, String, String, String, String, URI)}.
135135
* @throws IOException
136136
*/
137-
static void read(SBOLDocument doc,String stringBuffer,String URIprefix,String version,URI encoding) throws SBOLValidationException, IOException
137+
static void read(SBOLDocument doc,String stringBuffer,String URIprefix,String displayId,String version,URI encoding) throws SBOLValidationException, IOException
138138
{
139139
// reset the global static variables needed for parsing
140140
nextLine = null;
@@ -145,7 +145,6 @@ static void read(SBOLDocument doc,String stringBuffer,String URIprefix,String ve
145145
String elements = null;
146146
String description = "";
147147
boolean sequenceMode = false;
148-
String displayId;
149148
BufferedReader br = new BufferedReader(new StringReader(stringBuffer));
150149

151150
while ((strLine = readFASTALine(br)) != null) {
@@ -154,31 +153,37 @@ static void read(SBOLDocument doc,String stringBuffer,String URIprefix,String ve
154153
if (strLine.startsWith(">")) {
155154
if (sequenceMode) {
156155
sequenceMode = false;
157-
if (description.contains(":")) {
158-
displayId = description.substring(0, description.indexOf(":")).trim();
159-
description = description.substring(description.indexOf(":")+1).trim();
160-
} else {
161-
displayId = description;
156+
if (displayId == null || displayId.equals("")) {
157+
if (description.contains(":")) {
158+
displayId = description.substring(0, description.indexOf(":")).trim();
159+
description = description.substring(description.indexOf(":")+1).trim();
160+
} else {
161+
displayId = description;
162+
}
162163
}
163164
displayId = URIcompliance.fixDisplayId(displayId);
164165
Sequence sequence = createSequence(doc,URIprefix,displayId,version,sbSequence.toString(),encoding);
165166
sequence.setDescription(description);
167+
displayId = "";
166168
description = "";
167169
sbSequence = new StringBuilder();
168170
}
169171
description += strLine.replaceFirst(">", "").trim();
170172
} else if (strLine.startsWith(";")) {
171173
if (sequenceMode) {
172174
sequenceMode = false;
173-
if (description.contains(":")) {
174-
displayId = description.substring(0, description.indexOf(":")).trim();
175-
description = description.substring(description.indexOf(":")+1).trim();
176-
} else {
177-
displayId = description;
175+
if (displayId == null || displayId.equals("")) {
176+
if (description.contains(":")) {
177+
displayId = description.substring(0, description.indexOf(":")).trim();
178+
description = description.substring(description.indexOf(":")+1).trim();
179+
} else {
180+
displayId = description;
181+
}
178182
}
179183
displayId = URIcompliance.fixDisplayId(displayId);
180184
Sequence sequence = createSequence(doc,URIprefix,displayId,version,sbSequence.toString(),encoding);
181185
sequence.setDescription(description);
186+
displayId = "";
182187
description = "";
183188
sbSequence = new StringBuilder();
184189
}

core2/src/main/java/org/sbolstandard/core2/GenBank.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ private static String fixTag(String tag) {
873873
* <li>{@link #createSubComponentDefinitions(SBOLDocument, ComponentDefinition, URI, String, String)}.</li>
874874
* </ul>
875875
*/
876-
static void read(SBOLDocument doc,String stringBuffer,String URIPrefix,String defaultVersion) throws IOException, SBOLConversionException, SBOLValidationException {
876+
static void read(SBOLDocument doc,String stringBuffer,String URIPrefix,String displayId,String defaultVersion) throws IOException, SBOLConversionException, SBOLValidationException {
877877
so = new SequenceOntology();
878878

879879
// reset the global static variables needed for parsing
@@ -890,7 +890,7 @@ static void read(SBOLDocument doc,String stringBuffer,String URIPrefix,String de
890890
URI lastRole = null;
891891
while (true) {
892892
boolean cont = false;
893-
String id = "";
893+
String id = displayId;
894894
String accession = "";
895895
String version = defaultVersion;
896896
featureMode = false;
@@ -914,14 +914,16 @@ static void read(SBOLDocument doc,String stringBuffer,String URIPrefix,String de
914914
//String[] strSplit = strLine.split("\\s+");
915915

916916
// ID of the sequence
917-
if (strLine.length() > 28) {
918-
id = strLine.substring(12, 28).trim();
919-
annotation = new Annotation(new QName(GBNAMESPACE, LOCUS, GBPREFIX), id);
920-
id = URIcompliance.fixDisplayId(id);
921-
annotations.add(annotation);
922-
} else {
923-
// TODO: Exception?
924-
id = "id_is_missing";
917+
if (id == null || id.equals("")) {
918+
if (strLine.length() > 28) {
919+
id = strLine.substring(12, 28).trim();
920+
annotation = new Annotation(new QName(GBNAMESPACE, LOCUS, GBPREFIX), id);
921+
id = URIcompliance.fixDisplayId(id);
922+
annotations.add(annotation);
923+
} else {
924+
// TODO: Exception?
925+
id = "id_is_missing";
926+
}
925927
}
926928

927929
// Base count of the sequence

core2/src/main/java/org/sbolstandard/core2/SBOLDocument.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ public class SBOLDocument {
9090
* Constant representing GenBank file format
9191
*/
9292
public static final String GENBANK = "GENBANK";
93+
/**
94+
* Constant representing SnapGene file format
95+
*/
96+
public static final String SNAPGENE = "SNAPGENE";
9397

9498
/**
9599
* Creates a new SBOLDocument instance with one empty list for the namespaces

0 commit comments

Comments
 (0)