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/** 034 * The cookbook recipe for how to request Pfam annotations for a protein sequence using the Hmmer3 service 035 * 036 * @author Andreas Prlic 037 * @since 3.0.3 038 */ 039public class HmmerDemo { 040 041 public static void main(String[] args) throws Exception { 042 043 044 // first we get a UniProt sequence 045 String uniProtID = "P08487"; 046 ProteinSequence seq = getUniprot(uniProtID); 047 048 049 // now we submit this sequence to the Hmmer web site 050 RemoteHmmerScan hmmer = new RemoteHmmerScan(); 051 052 SortedSet<HmmerResult> results = hmmer.scan(seq); 053 054 // and now let's print out the obtained annotations 055 056 System.out.println(String.format("#\t%15s\t%10s\t%s\t%s\t%8s\t%s", 057 "Domain","ACC", "Start","End","eValue","Description")); 058 059 int counter = 0; 060 for (HmmerResult hmmerResult : results) { 061 //System.out.println(hmmerResult); 062 063 for ( HmmerDomain domain : hmmerResult.getDomains()) { 064 counter++; 065 System.out.println(String.format("%d\t%15s\t%10s\t%5d\t%5d\t%.2e\t%s", 066 counter, 067 hmmerResult.getName(), domain.getHmmAcc(), 068 domain.getSqFrom(),domain.getSqTo(), 069 domain.getEvalue(), hmmerResult.getDesc() 070 )); 071 072 } 073 074 } 075 076 077 } 078 079 /** 080 * Fetch a protein sequence from the UniProt web site 081 * 082 * @param uniProtID 083 * @return a Protein Sequence 084 * @throws Exception 085 */ 086 private static ProteinSequence getUniprot(String uniProtID) throws Exception { 087 088 AminoAcidCompoundSet set = AminoAcidCompoundSet.getAminoAcidCompoundSet(); 089 UniprotProxySequenceReader<AminoAcidCompound> uniprotSequence = new UniprotProxySequenceReader<AminoAcidCompound>(uniProtID,set); 090 091 ProteinSequence seq = new ProteinSequence(uniprotSequence); 092 093 return seq; 094 } 095}