001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021package demo; 022 023import org.biojava.nbio.core.sequence.ProteinSequence; 024import org.biojava.nbio.core.sequence.compound.AminoAcidCompound; 025import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet; 026import org.biojava.nbio.core.sequence.loader.UniprotProxySequenceReader; 027import org.biojava.nbio.ws.hmmer.HmmerDomain; 028import org.biojava.nbio.ws.hmmer.HmmerResult; 029import org.biojava.nbio.ws.hmmer.RemoteHmmerScan; 030 031import java.util.SortedSet; 032 033/** The cookbook recipe for how to request Pfam annotations for a protein sequence using the Hmmer3 service 034 * 035 * @author Andreas Prlic 036 * @since 3.0.3 037 */ 038public class HmmerDemo { 039 040 public static void main(String[] args){ 041 042 try { 043 // first we get a UniProt sequence 044 String uniProtID = "P08487"; 045 ProteinSequence seq = getUniprot(uniProtID); 046 047 048 // now we submit this sequence to the Hmmer web site 049 RemoteHmmerScan hmmer = new RemoteHmmerScan(); 050 051 SortedSet<HmmerResult> results = hmmer.scan(seq); 052 053 // and now let's print out the obtained annotations 054 055 System.out.println(String.format("#\t%15s\t%10s\t%s\t%s\t%8s\t%s", 056 "Domain","ACC", "Start","End","eValue","Description")); 057 058 int counter = 0; 059 for (HmmerResult hmmerResult : results) { 060 //System.out.println(hmmerResult); 061 062 for ( HmmerDomain domain : hmmerResult.getDomains()) { 063 counter++; 064 System.out.println(String.format("%d\t%15s\t%10s\t%5d\t%5d\t%.2e\t%s", 065 counter, 066 hmmerResult.getName(), domain.getHmmAcc(), 067 domain.getSqFrom(),domain.getSqTo(), 068 domain.getEvalue(), hmmerResult.getDesc() 069 )); 070 071 } 072 073 } 074 075 } catch (Exception e) { 076 // TODO Auto-generated catch block 077 e.printStackTrace(); 078 } 079 } 080 081 /** Fetch a protein sequence from the UniProt web site 082 * 083 * @param uniProtID 084 * @return a Protein Sequence 085 * @throws Exception 086 */ 087 private static ProteinSequence getUniprot(String uniProtID) throws Exception { 088 089 AminoAcidCompoundSet set = AminoAcidCompoundSet.getAminoAcidCompoundSet(); 090 UniprotProxySequenceReader<AminoAcidCompound> uniprotSequence = new UniprotProxySequenceReader<AminoAcidCompound>(uniProtID,set); 091 092 ProteinSequence seq = new ProteinSequence(uniprotSequence); 093 094 return seq; 095 } 096}