/* Copyright (c) 2009 Peter Troshin * * Jalview Web Services @version: 2.0 * * This library is free software; you can redistribute it and/or modify it under the terms of the * Apache License version 2 as published by the Apache Software Foundation * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache * License for more details. * * A copy of the license is in apache_license.txt. It is also available here: * @see: http://www.apache.org/licenses/LICENSE-2.0.txt * * Any republication or derived work distributed in source code form * must include this copyright and license notice. */ package compbio.pipeline._jpred; import java.io.*; import java.util.*; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; public class BlastParser { static class Psiseq { String id; String seq; } /** * args[0] is assumed to be the name of a Blast output file * @throws XMLStreamException * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException, XMLStreamException { XMLInputFactory f = XMLInputFactory.newInstance(); XMLStreamReader r = f.createXMLStreamReader( new BufferedInputStream(new FileInputStream(new File(args[0])))); List pl = new ArrayList(); Psiseq psi = null; while(r.hasNext()) { int idx = r.next(); //System.out.println(idx); if(r.isStartElement()) { String name = r.getLocalName(); if(name.equals("Hit") ) { psi = new Psiseq(); } if(name.equals("Hit_id") ) { //System.out.println(r.getElementText()); psi.id = r.getElementText(); System.out.println(psi.id); } if(name.equals("Hsp_hseq")) { psi.seq = r.getElementText(); System.out.println(psi.seq); } } if(r.isEndElement()) { String name = r.getLocalName(); if(name.equals("Hit") ) { pl.add(psi); psi = null; } } } } }