@@ -47,36 +47,41 @@ Command line usage example:
4747<nowiki >xjc -d <output directory > -p <package name > -dtd http://www.ncbi.nlm.nih.gov/dtd/NCBI_BlastOutput.dtd </nowiki >
4848`
4949
50- Maven plugin config example: <xml > <plugin >
51-
52- ` ` <groupId >` org.jvnet.jaxb2.maven2 ` </groupId >
53- ` ` <artifactId >` maven-jaxb2-plugin ` </artifactId >
54- ` ` <version >` 0.8.0 ` </version >
55- ` ` <executions >
56- ` ` <execution >
57- ` ` <goals >
58- ` ` <goal >` generate ` </goal >
59- ` ` </goals >
60- ` ` <configuration >
61- ` ` <generatePackage >` ncbi.blast.result.generated ` </generatePackage >
62- ` ` <generateDirectory >` ${basedir}/src/main/java ` </generateDirectory >
63- ` ` <schemaLanguage >` dtd ` </schemaLanguage >
64- ` ` <schemaIncludes >
65- ` `
66- ` ` <value >` schemaFolder/NCBI_BlastOutput.dtd ` </value >
67- ` ` </schemaIncludes >
68- ` ` </configuration >
69- ` ` </execution >
70- ` ` </executions >
71- ` ` <dependencies >
72- ` ` <dependency >
73- ` ` <groupId >` org.jvnet.jaxb2-commons ` </groupId >
74- ` ` <artifactId >` property-listener-injector ` </artifactId >
75- ` ` <version >` 1.0 ` </version >
76- ` ` </dependency >
77- ` ` </dependencies >
78-
79- </plugin > </xml >
50+ Maven plugin config example:
51+
52+ ``` xml
53+
54+ <plugin >
55+
56+ >groupId>org.jvnet.jaxb2.maven2>/groupId>
57+ >artifactId>maven-jaxb2-plugin>/artifactId>
58+ >version>`0.8.0>/version>
59+ >executions>
60+ >execution>
61+ >goals>
62+ >goal>`generate>/goal>
63+ >/goals>
64+ >configuration>
65+ >generatePackage>ncbi.blast.result.generated>/generatePackage>
66+ >generateDirectory>${basedir}/src/main/java>/generateDirectory>
67+ >schemaLanguage>dtd>/schemaLanguage>
68+ >schemaIncludes>
69+
70+ >value>schemaFolder/NCBI_BlastOutput.dtd>/value>
71+ >/schemaIncludes>
72+ >/configuration>
73+ >/execution>
74+ >/executions>
75+ >dependencies>
76+ >dependency>
77+ >groupId>org.jvnet.jaxb2-commons>/groupId>
78+ >artifactId>property-listener-injector>/artifactId>
79+ >version>1.0>/version>
80+ >/dependency>
81+ >/dependencies>
82+
83+ </plugin >
84+ ```
8085
8186### Create Java objects from Blast results XML
8287
@@ -92,52 +97,65 @@ File("blast-xml-output.xml")); ```
9297
9398As a workaround, place the 3 schema files in the same folder where the
9499generated classes are located and use the following code, which will
95- then use those files: ```java JAXBContext jc =
96- JAXBContext.newInstance(BlastOutput.class); Unmarshaller u =
97- jc.createUnmarshaller();
100+ then use those files:
101+
102+ ``` java
103+
104+ JAXBContext jc = JAXBContext . newInstance(BlastOutput . class);
105+ Unmarshaller u = jc. createUnmarshaller();
98106
99107XMLReader xmlreader = XMLReaderFactory . createXMLReader();
100108xmlreader. setFeature(" <http://xml.org/sax/features/namespaces>" , true );
101109xmlreader. setFeature(" <http://xml.org/sax/features/namespace-prefixes>" ,
102110true ); xmlreader. setEntityResolver(new EntityResolver () {
103111
104- ` public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { `
105- ` String file = null; `
106- ` if (systemId.contains("NCBI_BlastOutput.dtd")) { `
107- ` file = "NCBI_BlastOutput.dtd"; `
108- ` } `
109- ` if (systemId.contains("NCBI_Entity.mod.dtd")) { `
110- ` file = "NCBI_Entity.mod.dtd"; `
111- ` } `
112- ` if (systemId.contains("NCBI_BlastOutput.mod.dtd")) { `
113- ` file = "NCBI_BlastOutput.mod.dtd"; `
114- ` } `
115- ` return new InputSource(BlastOutput.class.getResourceAsStream(file)); `
116- ` } `
117-
118- }); InputSource input = new InputSource(new FileReader(new
119- File("blast-xml-output.xml"))); Source source = new SAXSource(xmlreader,
120- input); return (BlastOutput) u.unmarshal(source); ```
112+ public InputSource resolveEntity (String publicId , String systemId ) throws SAXException , IOException {
113+ String file = null `
114+ if (systemId. contains(" NCBI_BlastOutput.dtd" )) {
115+ file = " NCBI_BlastOutput.dtd" `
116+
117+ if (systemId. contains(" NCBI_Entity.mod.dtd" )) {
118+ file = " NCBI_Entity.mod.dtd" `
119+
120+ if (systemId. contains(" NCBI_BlastOutput.mod.dtd" )) {
121+ file = " NCBI_BlastOutput.mod.dtd" `
122+
123+ return new InputSource (BlastOutput . class. getResourceAsStream(file));
124+
125+
126+ });
127+
128+ InputSource input = new InputSource (new FileReader (new File (" blast-xml-output.xml" ))); Source source = new SAXSource (xmlreader, input);
129+
130+ return (BlastOutput ) u. unmarshal(source);
131+
132+ ```
121133
122134### Use the created BlastOutput object
123135
124136Finally , BlastOutput object, created in the previous step, can be used
125137like any other Java object.
126138
127139For example, you can get the matrix used for given Blast search like
128- this: ```java BlastOutput blastOutput; // assign BlastOutput object,
140+ this :
141+
142+ ```java BlastOutput blastOutput; // assign BlastOutput object,
129143returned by Unmarshaller (see previous step) String matrix =
130144blastOutput. getBlastOutputParam(). getParameters(). getParametersMatrix();
131- ``` Note that this corresponds to the XML structure: <xml>
145+ ``` Note that this corresponds to the XML structure:
146+
147+ ```xml
132148< BlastOutput >
133149
134- ` ...`
135- ` `<BlastOutput_param>
136- ` `<Parameters>
137- ` `<Parameters_matrix>`BLOSUM62`</Parameters_matrix>
138- ` ...`
139- ` `</Parameters>
140- ` `</BlastOutput_param>
141- ` ...`
150+ ...
151+ > BlastOutput_param >
152+ > Parameters >
153+ > Parameters_matrix > `BLOSUM62 > / Parameters_matrix >
154+ ...
155+ > / Parameters >
156+ > / BlastOutput_param >
157+ ...
158+
159+ < / BlastOutput >
142160
143- </BlastOutput> </xml>
161+ ```
0 commit comments