FASTA { static void read(SBOLDocument doc,String stringBuffer,String URIprefix,String displayId,String version,URI encoding) throws SBOLValidationException, IOException { nextLine = null; String strLine; StringBuilder sbSequence = new StringBuilder(); String elements = null; String description = ""; boolean sequenceMode = false; BufferedReader br = new BufferedReader(new StringReader(stringBuffer)); while ((strLine = readFASTALine(br)) != null) { strLine = strLine.trim(); if (strLine.startsWith(">")) { if (sequenceMode) { sequenceMode = false; if (displayId == null || displayId.equals("")) { if (description.contains(":")) { displayId = description.substring(0, description.indexOf(":")).trim(); description = description.substring(description.indexOf(":")+1).trim(); } else { displayId = description; } } displayId = URIcompliance.fixDisplayId(displayId); Sequence sequence = createSequence(doc,URIprefix,displayId,version,sbSequence.toString(),encoding); sequence.setDescription(description); displayId = ""; description = ""; sbSequence = new StringBuilder(); } description += strLine.replaceFirst(">", "").trim(); } else if (strLine.startsWith(";")) { if (sequenceMode) { sequenceMode = false; if (displayId == null || displayId.equals("")) { if (description.contains(":")) { displayId = description.substring(0, description.indexOf(":")).trim(); description = description.substring(description.indexOf(":")+1).trim(); } else { displayId = description; } } displayId = URIcompliance.fixDisplayId(displayId); Sequence sequence = createSequence(doc,URIprefix,displayId,version,sbSequence.toString(),encoding); sequence.setDescription(description); displayId = ""; description = ""; sbSequence = new StringBuilder(); } description += strLine.replaceFirst(";", "").trim(); } else { sequenceMode = true; if(elements == null) { elements = new String(""); } String[] strSplit = strLine.split(" "); for (int i = 0; i < strSplit.length; i++) { sbSequence.append(strSplit[i]); } } } if (description.contains(":")) { if (displayId == null || displayId.equals("")) { displayId = description.substring(0, description.indexOf(":")).trim(); } description = description.substring(description.indexOf(":")+1).trim(); } else { if (displayId == null || displayId.equals("")) { displayId = description; } } displayId = URIcompliance.fixDisplayId(displayId); Sequence sequence = createSequence(doc,URIprefix,displayId,version,sbSequence.toString(),encoding); sequence.setDescription(description); br.close(); }    }
@Test public void testReadInputStreamStringStringStringURI() { String URIprefix = "http: String version = "1.0"; String fasta = ">test" + SBOLTestUtils.NEWLINE + "acgt"; try ( ByteArrayInputStream bais = new ByteArrayInputStream(fasta.getBytes()); ) { SBOLReader.setVersion(version); SBOLReader.setURIPrefix(URIprefix); SBOLDocument doc = SBOLReader.read(bais); assertTrue(doc.getSequences().size() == 1); assertTrue(URIprefix.equals(doc.getDefaultURIprefix())); assertTrue(null != doc.getSequence("test", version)); } catch(Exception e) { assertTrue(false); } fasta = ">test1" + SBOLTestUtils.NEWLINE + "acgt" + SBOLTestUtils.NEWLINE + ">test2" + SBOLTestUtils.NEWLINE + "cgta"; try ( ByteArrayInputStream bais = new ByteArrayInputStream(fasta.getBytes()); ) { SBOLReader.setURIPrefix(URIprefix); SBOLReader.setVersion(version); SBOLDocument doc = SBOLReader.read(bais); assertTrue(doc.getSequences().size() == 2); assertTrue(null != doc.getSequence("test1", version)); assertTrue(null != doc.getSequence("test2", version)); } catch(Exception e) { assertTrue(false); } fasta = ">test1" + SBOLTestUtils.NEWLINE + "acgt" + SBOLTestUtils.NEWLINE + "acgt" + SBOLTestUtils.NEWLINE; try ( ByteArrayInputStream bais = new ByteArrayInputStream(fasta.getBytes()); ) { SBOLReader.setURIPrefix(URIprefix); SBOLDocument doc = SBOLReader.read(bais); assertTrue(doc.getSequences().size() == 1); assertTrue(null != doc.getSequence("test1", version)); Sequence seq = doc.getSequence("test1", version); assertTrue("acgtacgt".equals(seq.getElements())); } catch(Exception e) { assertTrue(false); } }