Hello,
I am working with Biojava and I am trying to run CookbookMSA. I have all requested jars, but I get an error
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.biojava3.core.sequence.location.SimpleLocation
at org.biojava3.alignment.SimpleAlignedSequence.setLocation(SimpleAlignedSequence.java:351)
at org.biojava3.alignment.SimpleAlignedSequence.<init>(SimpleAlignedSequence.java:88)
at org.biojava3.alignment.SimpleProfile.<init>(SimpleProfile.java:119)
at org.biojava3.alignment.SimpleSequencePair.<init>(SimpleSequencePair.java:86)
at org.biojava3.alignment.SimpleSequencePair.<init>(SimpleSequencePair.java:69)
at org.biojava3.alignment.routines.AnchoredPairwiseSequenceAligner.setProfile(AnchoredPairwiseSequenceAligner.java:137)
at org.biojava3.alignment.template.AbstractMatrixAligner.align(AbstractMatrixAligner.java:344)
at org.biojava3.alignment.template.AbstractPairwiseSequenceAligner.getPair(AbstractPairwiseSequenceAligner.java:112)
at org.biojava3.alignment.FractionalIdentityScorer.align(FractionalIdentityScorer.java:112)
at org.biojava3.alignment.FractionalIdentityScorer.getMaxScore(FractionalIdentityScorer.java:92)
at org.biojava3.alignment.template.AbstractScorer.getDistance(AbstractScorer.java:40)
at org.biojava3.alignment.template.AbstractScorer.getDistance(AbstractScorer.java:35)
at org.biojava3.alignment.GuideTree.<init>(GuideTree.java:82)
at org.biojava3.alignment.Alignments.getMultipleSequenceAlignment(Alignments.java:183)
at Alignment.multipleSequenceAlignment(Alignment.java:29)
at Alignment.main(Alignment.java:18)
I am woking on latest version of Eclipse Luna, Windows System. My code is:
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.biojava3.alignment.Alignments;
import org.biojava3.alignment.template.Profile;
import org.biojava3.core.sequence.ProteinSequence;
import org.biojava3.core.sequence.compound.AminoAcidCompound;
import org.biojava3.core.sequence.io.FastaReaderHelper;
import org.biojava3.core.util.ConcurrencyTools;
public class Alignment {
public static void main(String[] args) {
String[] ids = new String[] {"Q21691", "O48771"};
try {
multipleSequenceAlignment(ids);
} catch (Exception e){
e.printStackTrace();
}
}
private static void multipleSequenceAlignment(String[] ids) throws Exception {
List<ProteinSequence> lst = new ArrayList<ProteinSequence>();
for (String id : ids) {
lst.add(getSequenceForId(id));
}
Profile<ProteinSequence, AminoAcidCompound> profile = Alignments.getMultipleSequenceAlignment(lst);
System.out.printf("Clustalw:%n%s%n", profile);
ConcurrencyTools.shutdown();
}
private static ProteinSequence getSequenceForId(String uniProtId) throws Exception {
URL uniprotFasta = new URL(String.format("http://www.uniprot.org/uniprot/%s.fasta", uniProtId));
ProteinSequence seq = FastaReaderHelper.readFastaProteinSequence(uniprotFasta.openStream()).get(uniProtId);
System.out.printf("id : %s %s%n%s%n", uniProtId, seq, seq.getOriginalHeader());
return seq;
}
}
What might be a problem?
2 answers
I am woking on latest version of Eclipse Luna, Windows System
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.biojava3.alignment.Alignments;
import org.biojava3.alignment.template.Profile;
import org.biojava3.core.sequence.ProteinSequence;
import org.biojava3.core.sequence.compound.AminoAcidCompound;
import org.biojava3.core.sequence.io.FastaReaderHelper;
import org.biojava3.core.util.ConcurrencyTools;
public class Alignment {
public static void main(String[] args) {
String[] ids = new String[] {"Q21691", "O48771"};
try {
multipleSequenceAlignment(ids);
} catch (Exception e){
e.printStackTrace();
}
}
private static void multipleSequenceAlignment(String[] ids) throws Exception {
List<ProteinSequence> lst = new ArrayList<ProteinSequence>();
for (String id : ids) {
lst.add(getSequenceForId(id));
}
Profile<ProteinSequence, AminoAcidCompound> profile = Alignments.getMultipleSequenceAlignment(lst);
System.out.printf("Clustalw:%n%s%n", profile);
ConcurrencyTools.shutdown();
}
private static ProteinSequence getSequenceForId(String uniProtId) throws Exception {
URL uniprotFasta = new URL(String.format("http://www.uniprot.org/uniprot/%s.fasta", uniProtId));
ProteinSequence seq = FastaReaderHelper.readFastaProteinSequence(uniprotFasta.openStream()).get(uniProtId);
System.out.printf("id : %s %s%n%s%n", uniProtId, seq, seq.getOriginalHeader());
return seq;
}
}
This is a bit old, but anyway I've just seen it and maybe it can still help: NoClassDefFoundError indicates there's something wrong in your classpath, i.e. the jar files that you need for your code to link to biojava at runtime.
How are you getting the jar files? Manually? With maven?
If you are working in eclipse with manual downloading of jars, you need to make sure that the classpath is correctly set: right click on project root, select "Build Path", then "Configure Build Path..." and then the "Libraries" tab. There you have to refer to all the jars needed for Biojava (one per module) and eventually any other dependencies needed by Biojava itself.
Setting it up manually might be a bit tedious, that's why it is recommended to use maven, check the readme in here for how to set maven up to work with biojava.
Log in to answer this question.
Hi, a bit of your code and info on the platform and OS would help a lot. Thank you!
I have added code