Top: Index Previous: Assessment and Examples Up: BioJava Next: In Anger

CSC8311 -- Advanced Object-Orientated Programming

Deliverables

For each code snippet in the tutorial, you need to do two things. First, you need to write a complete class, which compiles and runs and demonstrates the snippet. Second, you need to write a modified class which changes the first class to do something new biologically. Even a small change is allowable, but it must change the function of the class from a biological perspective; changing the layout of the output, for example, would not be acceptable.

Each snippet will be marked out of 3. One mark will be given for the working example, one for the working modified example. The final mark will be awarded for particularly good work; so, good documentation and commentary, a nicely modified biological use would all tend to attract the extra mark.

Examples

The first implementable code snippet in the Symbol tutorial looks like this:

FiniteAlphabet dna = DNATools.getDNA();
Iterator dnaSymbols = dna.iterator();
while (dnaSymbols.hasNext()) {
    Symbol s = (Symbol) dnaSymbols.next();
    System.out.println(s.getName());
}

By itself, this will not compile and run. In this next example, I have created a class in the symbols package, added import statements, a class declaration and a main method. The following would be a good example of a working class.

package symbols;

import java.util.Iterator;
import org.biojava.bio.seq.DNATools;
import org.biojava.bio.symbol.FiniteAlphabet;
import org.biojava.bio.symbol.Symbol;

public class TrialSymbol {

    public static void main(String[] args) {
        FiniteAlphabet dna = DNATools.getDNA();
        Iterator dnaSymbols = dna.iterator();
        while (dnaSymbols.hasNext()) {
            Symbol s = (Symbol) dnaSymbols.next();
            System.out.println(s.getName());
        }
    }
}

You might modify this to print out the symbols from RNA rather than DNA, like this:

package symbols;

import java.util.Iterator;
import org.biojava.bio.seq.RNATools;
import org.biojava.bio.symbol.FiniteAlphabet;
import org.biojava.bio.symbol.Symbol;

public class TrialSymbolModified {

    public static void main(String[] args) {
        FiniteAlphabet rna = RNATools.getRNA();
        Iterator rnaSymbols = rna.iterator();
        while (rnaSymbols.hasNext()) {
            Symbol s = (Symbol) rnaSymbols.next();
            System.out.println(s.getName());
        }
    }
}

On the other hand, this would be a modification to the structure of the program; while it's probably a good modification, it would not gain a mark as it does not change the biological function of the code.

package symbols;

import java.util.Iterator;
import org.biojava.bio.BioException;
import org.biojava.bio.seq.DNATools;
import org.biojava.bio.symbol.FiniteAlphabet;
import org.biojava.bio.symbol.Symbol;

public class TrialSymbolModifiedWrong {
    public static void main(String[] args) throws BioException {
        TrialSymbolModifiedWrong t = new TrialSymbolModifiedWrong();
        t.trial();
    }

   public void trial() {

        FiniteAlphabet dna = DNATools.getDNA();
        Iterator dnaSymbols = dna.iterator();
        while (dnaSymbols.hasNext()) {
            Symbol s = (Symbol) dnaSymbols.next();
            System.out.println(s.getName());
        }
    }
}

For all of these examples, they are borderline for attracting a third mark; while they are nicely laid out, use a non-default package, and have appropriate use of privacy and variables, they have no documentation or commentary at all.

You should be aware that not all modifications are as straight-forward as this. For example, the next code snippet calls a getSomeSequence() method which is not defined, so you would have to supply one. The code sample after this shows you one way of doing so.

package symbols;

import org.biojava.bio.BioException;
import org.biojava.bio.seq.DNATools;
import org.biojava.bio.seq.io.SymbolTokenization;
import org.biojava.bio.symbol.Alphabet;
import org.biojava.bio.symbol.SimpleSymbolList;
import org.biojava.bio.symbol.SymbolList;

public class TrialSymbolList {

    public static void main(String[] args) throws BioException {
        String seqString = "GATTACA";
        Alphabet dna = DNATools.getDNA();
        SymbolTokenization dnaToke = dna.getTokenization("token");
        SymbolList seq = new SimpleSymbolList( dnaToke, seqString );
        System.out.println("Alphabet = " + seq.getAlphabet().getName());
        System.out.println("Length = " + seq.length());
        System.out.println("First symbol = " + seq.symbolAt(1).getName() );


    }
}

Exercises

Please work through the following sections of the tutorial


Top: Index Previous: Assessment and Examples Up: BioJava Next: In Anger