[Biojava-l] An exception is being thrown while using the code related to phylogeny from BioJava cookbook

Andreas Prlic andreas at sdsc.edu
Tue May 10 00:13:01 UTC 2011


Hi Muhammad,

did you see the Cookbook pages?

Best to start with a simple example like
http://biojava.org/wiki/BioJava:CookBook3:MSA

I suspect there is something going wrong with your input file.  Try to get
the file parsing right first. E.g.:
http://biojava.org/wiki/BioJava:CookBook:Core:FastaReadWrite

Andreas


On Sun, May 8, 2011 at 10:20 PM, Muhammad Tariq Pervez <tariq_cp at hotmail.com
> wrote:

>  Dear concerns,
> I want to develop an application for phylogenetic analysis. To get started,
> I took some lines of code from BioJava cookbook, modified them as per my
> requirement and have been trying to get the results for a few days but in
> vain. The code is as follows.
>
>
> package biojavademo;
>
>
> import java.io.File;
> import java.util.ArrayList;
> import java.util.LinkedHashMap;
> import java.util.List;
> import java.util.Map.Entry;
>
> import org.biojava3.alignment.template.Profile;
> import org.biojava3.alignment.Alignments;
> import org.biojava3.alignment.template.AlignedSequence;
> import org.biojava3.core.sequence.MultipleSequenceAlignment;
> import org.biojava3.core.sequence.ProteinSequence;
> import org.biojava3.core.sequence.compound.AminoAcidCompound;
> import org.biojava3.core.sequence.io.FastaReaderHelper;
> import org.biojava3.core.sequence.template.Compound;
> import org.biojava3.core.sequence.template.Sequence;
> import org.biojava3.core.util.ConcurrencyTools;
> import org.biojava3.phylo.ProgessListenerStub;
> import org.biojava3.phylo.TreeConstructionAlgorithm;
> import org.biojava3.phylo.TreeConstructor;
> import org.biojava3.phylo.TreeType;
>
> public class MSA {
>
>
>     MSA(){
>               multipleSequenceAlignment = new MultipleSequenceAlignment
> <ProteinSequence, AminoAcidCompound>();
> }
>     public void multipleSequenceAlignment(List<String> ids) throws
> Exception {
>         List<ProteinSequence> lst = new ArrayList<ProteinSequence>();
>
>         for (String id : ids) {
>             lst.add(getSequenceForId(id));
>
>         }
>
>         profile = Alignments.getMultipleSequenceAlignment(lst);
>         System.out.println("Compound == "+ profile.getCompoundSet());
>         seq=new
> ProteinSequence(profile.toString(),profile.getCompoundSet());
>         multipleSequenceAlignment.addAlignedSequence(seq);
>         TreeConstructor<ProteinSequence, AminoAcidCompound> treeConstructor
> = new TreeConstructor<ProteinSequence,
> AminoAcidCompound>(multipleSequenceAlignment,  TreeType.NJ,
> TreeConstructionAlgorithm.PID, new ProgessListenerStub());
>            treeConstructor.process();
>            String newick = treeConstructor.getNewickString(true, true);
>         System.out.println("Clustalw:\n Multisequence Alignment\n"+
> profile.toString(Profile.StringFormat.CLUSTALW));
>        System.out.println("Tree === "+ newick);
>               ConcurrencyTools.shutdown();
>     }
>
>       private static ProteinSequence getSequenceForId(String fileName)
> throws Exception {
>
>         LinkedHashMap<String, ProteinSequence> a =
> FastaReaderHelper.readFastaProteinSequence(new File(fileName));
>
>                 String seqStr;
>                 ProteinSequence seq=null;
>         for (  Entry<String, ProteinSequence> entry : a.entrySet() ) {
>                         seqStr=entry.getValue().getSequenceAsString();
>                         seq=new ProteinSequence(seqStr);//entry.getValue();
>
>         }
>         return seq;
>     }
>     public Profile<ProteinSequence, AminoAcidCompound> getMSAProfile(){
>         return profile;
>     }
>
> Profile<ProteinSequence, AminoAcidCompound> profile;
> MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound>
> multipleSequenceAlignment;
>  ProteinSequence seq=null;
> }
>
> When I run this code the following exception is thrown
>
> Exception in thread "AWT-EventQueue-0"
> org.biojava3.core.exceptions.CompoundNotFoundError: Compound not found for:
> Cannot find compound for:
>         at
> org.biojava3.core.sequence.storage.ArrayListSequenceReader.setContents(ArrayListSequenceReader.java:196)
>         at
> org.biojava3.core.sequence.template.AbstractSequence.<init>(AbstractSequence.java:88)
>         at
> org.biojava3.core.sequence.ProteinSequence.<init>(ProteinSequence.java:52)
>         at biojavademo.MSA.multipleSequenceAlignment(MSA.java:41)
>         at
> biojavademo.MSAJFrame.jButton2ActionPerformed(MSAJFrame.java:160)
>         at biojavademo.MSAJFrame.access$100(MSAJFrame.java:27)
>         at biojavademo.MSAJFrame$2.actionPerformed(MSAJFrame.java:72)
>         at
> javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
>         at
> javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
>         at
> javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
>         at
> javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
>         at
> javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
>         at java.awt.Component.processMouseEvent(Component.java:6038)
>         at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
>         at java.awt.Component.processEvent(Component.java:5803)
>         at java.awt.Container.processEvent(Container.java:2058)
>         at java.awt.Component.dispatchEventImpl(Component.java:4410)
>         at java.awt.Container.dispatchEventImpl(Container.java:2116)
>         at java.awt.Component.dispatchEvent(Component.java:4240)
>         at
> java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
>         at
> java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
>         at
> java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
>         at java.awt.Container.dispatchEventImpl(Container.java:2102)
>         at java.awt.Window.dispatchEventImpl(Window.java:2429)
>         at java.awt.Component.dispatchEvent(Component.java:4240)
>         at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
>         at
> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
>         at
> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
>         at
> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
>         at
> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
>         at
> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
>         at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
>
> Actually I don't know how to construct the multiple sequence alignment
> object which is given as a parameter while constructing the
> 'TreeConstructor' object.
>
> Kindly guide/help me to resolve this issue.
>
>
> Muhammad Tariq Pervez
> Ph.D (Scholar) - Bioinformatics,
> University of Veterinary and Animal Science, Lahore, Pakistan
>
>
>
>
>



More information about the Biojava-l mailing list