AW: [Biojava-l] BLAST Parser for extracting all BLAST data?

Sébastien PETIT great_fred at yahoo.com
Tue Jun 28 08:59:30 EDT 2005


Thank you for JDOM and the code...
But, it generates a ton of exceptions and error because it doesn't find
a DTD file (NCBI_BlastOutput.dtd) that I don't have...

So, I don't know how to do...

Sebastien

--- "BIBIS, Garnier, Christophe" <cgarnier at ttz-Bremerhaven.de> a écrit
:

> 
> if you don't find what you need through biojava, you can always write
> a
> small xml parser with for example jdom.
> 
> 1 - download jdom.jar
> 2 - use the following code to find <Hsp_midline>:
> 3 - replace the path of the xml file in the main method
> 4 - it prints out every found Element
> 
> 
> I hope it helps you
> 
> Best,
> Christophe
> 
> +++++++++++++++++++++++++++++++++++++
> 
> import java.io.File;
> import java.io.IOException;
> import java.util.Iterator;
> import java.util.List;
> 
> import org.jdom.Document;
> import org.jdom.Element;
> import org.jdom.JDOMException;
> import org.jdom.input.SAXBuilder;
> 
> public class JDomParser
> {
> 
> 	private static void parseResults(Element iterations)
> 	{
> 		System.out.println("*** parseResults ***") ;
> 		
> 		Element it = iterations.getChild("Iteration") ;
> 		
> 		List elts = it.getChildren();
> 		
> 		Iterator iterator = elts.iterator();
> 		
> 		while (iterator.hasNext())
> 		{
> 			Element child = (Element) iterator.next();
> 
> 			System.out.println(child + " - " + child.getText() +
> " - "
> 					+ child.getName());
> 
> 			if ( child.getName().equals("Iteration_hits"))
> 			{
> 				parseHits(child) ;
> 			}
> 			
> 			if ( child.getName().equals("Iteration_stat"))
> 			{
> 				parseStatistics(child) ;
> 			}
> 			
> 		
> 		}
> 	}
> 
> 	private static void parseHits(Element element)
> 	{
> 		List elts = element.getChildren();
> 		
> 		Iterator iterator = elts.iterator();
> 		
> 		while (iterator.hasNext())
> 		{
> 			Element child = (Element) iterator.next();
> 
> 			printElt(child) ;
> 			
> 			parseHit(child) ;
> 			
> 		}
> 	}
> 	
> 	private static void parseHspHit(Element element)
> 	{
> 		Element hsp = element.getChild("Hsp") ;
> 
> 		List hsps = hsp.getChildren();
> 		
> 		Iterator iterator = hsps.iterator();
> 		
> 		while (iterator.hasNext())
> 		{
> 			Element child = (Element) iterator.next();
> 
> 			printElt(child) ;
> 		}
> 	}
> 	
> 	private static void printElt(Element elt)
> 	{
> 		System.out.println("Element: [" + elt.getName() + "] -
> text:" + elt.getText() ) ;
> 	}
> 	
> 	private static void parseHit(Element element)
> 	{
> 		List elts = element.getChildren();
> 		
> 		Iterator iterator = elts.iterator();
> 		
> 		while (iterator.hasNext())
> 		{
> 			Element child = (Element) iterator.next();
> 
> 			printElt(child) ;
> 			
> 			if (child.getName().equals("Hit_hsps"))
> 					{
> 					parseHspHit(child) ;
> 					}
> 			
> 		}
> 	}
> 	
> 	
> 	private static void parseStatistics(Element element)
> 	{
> 		Element stat = element.getChild("Statistics") ;
> 		
> 		List elts = stat.getChildren();
> 		
> 		Iterator iterator = elts.iterator();
> 		
> 		while (iterator.hasNext())
> 		{
> 			Element child = (Element) iterator.next();
> 
> 			printElt(child) ;
> 			
> 		}
> 		
> 	}
> 	
> 	
> 	public static void parseFile(File file) throws JDOMException,
> IOException
> 	{
> 		SAXBuilder parser = new SAXBuilder();
> 		Document doc = parser.build(file);
> 
> 		Element root = doc.getRootElement();
> 
> 		List elts = root.getChildren();
> 		Iterator iterator = elts.iterator();
> 
> 		int index = 0;
> 		while (iterator.hasNext())
> 		{
> 
> 			Element child = (Element) iterator.next();
> 
> 			printElt(child) ;
> 
> 			if
> (child.getName().equals("BlastOutput_iterations"))
> 				parseResults(child);
> 
> 		}
> 
> 	}
> 
> 	/**
>     * @param args
>     */
> 	public static void main(String[] args)
> 	{
> 		File f = new File("E:/result.xml");
> 
> 		try
> 		{
> 			parseFile(f);
> 		}
> 		catch (JDOMException e)
> 		{
> 			e.printStackTrace();
> 		}
> 		catch (IOException e)
> 		{
> 			e.printStackTrace();
> 		}
> 	}
> 
> }
> 
> 
> 
> 
> 
> +++++++++++++++++++++++++++++++++++++
> 
> 
> 
> 
> 
=== message truncated ===



	

	
		
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com


More information about the Biojava-l mailing list