Reading FASTA with BioJava 4.0.0
2
0
Entering edit mode
9.6 years ago
priess1991 • 0

Hi!

I searched for possible solutions but did not find anything helpful. I'm trying to use the Gen Ontology sequence database in order to test an algorithm my professor gave to me on this huge set of data. I thought the easiest way would be to read out the FASTA-file via BioJava.

It is the first time for me to work with BioJava. I downloaded BioJava 4.0.0 via Manual Download an imported the external jars into my Eclipse project.

I simply tried to read the FASTA-file for now:

package controle;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map.Entry;

import org.biojava.nbio.core.sequence.ProteinSequence;
import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet;
import org.biojava.nbio.core.sequence.io.FastaReader;
import org.biojava.nbio.core.sequence.io.FastaReaderHelper;
import org.biojava.nbio.core.sequence.io.GenericFastaHeaderParser;
import org.biojava.nbio.core.sequence.io.ProteinSequenceCreator;

public class ReadFasta {

    public static void readFasta() throws IOException {

        //Try with the FastaReaderHelper
        LinkedHashMap<String, ProteinSequence> a;
        try {
            File file = new File("C:\\Users\\Patrick\\workspace\\Bachelor\\src\\go_20150425-seqdb.fasta");
            a = FastaReaderHelper.readFastaProteinSequence(file);
            for (  Entry<String, ProteinSequence> entry : a.entrySet() ) {
                System.out.println( entry.getValue().getOriginalHeader() + "=" + entry.getValue().getSequenceAsString() );
            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

When I try to call my method readFasta() in main I get the following error code:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.biojava.nbio.core.sequence.io.FastaReader.<clinit>(FastaReader.java:46)
    at org.biojava.nbio.core.sequence.io.FastaReaderHelper.readFastaProteinSequence(FastaReaderHelper.java:97)
    at org.biojava.nbio.core.sequence.io.FastaReaderHelper.readFastaProteinSequence(FastaReaderHelper.java:82)
    at controle.ReadFasta.readFasta(ReadFasta.java:32)
    at controle.Main.main(Main.java:13)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more

I'm not totally sure if I have "installed" BioJava correctly or why this Problem occurs. Like I said I'm new to this and it would be nice if someone knows an solution or an easier way to deal with FASTA-files.

Greetings,
Patrick

RNA-Seq software-error • 3.6k views
ADD COMMENT
0
Entering edit mode

Tagging the BioJava expert Pierre Lindenbaum

ADD REPLY
2
Entering edit mode
ADD COMMENT
1
Entering edit mode
9.5 years ago

As Pierre says it is an issue with a missing dependency in your class path (log4j 2). You can get the jar manually and then point your eclipse project to it. However it is a lot easier and much more powerful to use maven to deal with the dependencies automatically.

BioJava is all set up already to use maven. In eclipse you simply need the m2e (maven 2 eclipse) plugin. Once you have it, then maven should start working and do the dependencies automatically for you.

ADD COMMENT

Login before adding your answer.

Traffic: 1984 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6