Can anybody help me with this java code
I am doing Ms bioinformatics in U.K. I have just started with java. Can anybody help me with the following code.
In this exercise the task is to write a alignment class. This will allow two strings to be aligned.
The alignment is a simplification to the general alignment and works in the following way:
Given two strings S1 and S2 and a character c, the alignment will insert padding symbols in to S1 and S2 such that when writing the padded string under each other the occurrences of the character c are aligned.
Example:
S1: aabaababbba.
S2: acadadaadaddaaba
When we align them by/for the character 揳?
The output should be:
a_aba_ababbba
acadada_ad__addaaba
here _(underscore) is the padding symbol.
We are using LINUX(SUSE).
Here we use the Xe mac editor to write codes.
We are being asked to use the following methods:
Class Alignment
java.lang.Object
Alignment
public class Alignment
extends java.lang.Object
Alignment.java Created: Mon Mar 7 08:27:36 2005
Constructor Summary
Alignment()
Default constructor.
Alignment(java.lang.String s1, java.lang.String s2)
Constructor The first and second string are given by the parameter.
Method Summary
void
align(char c)
Aligns the first and second string, such that all occurrences of the given character are aligned.
java.lang.String
getColumn(int i)
Return a string with the symbols of the i'th row in the alignment.
char
getPadSymbol()
Return the current padding symbol
void
setFirstString(java.lang.String s)
Set the first string to the given parameter.
void
setPadSymbol(char c)
Set the padding symbol to the given parameter.
void
setSecondString(java.lang.String s)
Set the second string to the given parameter.
char[][]
toArray()
Return a two-dimensional array of the alignment.
java.lang.String
toString()
Returns the Alignment as String The format is that each column of the alignment is given in a new row.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Constructor Detail
Alignment
public Alignment()
Default constructor. The first and second string are set to be empty. The default pad symbol is '-'.
Alignment
public Alignment(java.lang.String s1,
java.lang.String s2)
Constructor The first and second string are given by the parameter. The default pad symbol is '-'.
Parameters:
s1 - the first string
s2 - the first string
Method Detail
setFirstString
public void setFirstString(java.lang.String s)
Set the first string to the given parameter.
Parameters:
s - the new first string
setSecondString
public void setSecondString(java.lang.String s)
Set the second string to the given parameter.
Parameters:
s - the new second string
setPadSymbol
public void setPadSymbol(char c)
Set the padding symbol to the given parameter.
Parameters:
c - the new padding symbol
getPadSymbol
public char getPadSymbol()
Return the current padding symbol
Returns:
the current padding symbol
getColumn
public java.lang.String getColumn(int i)
Return a string with the symbols of the i'th row in the alignment.
Parameters:
i - the number of the column
Returns:
the string representing the i'th column of the alignment
align
public void align(char c)
Aligns the first and second string, such that all occurrences of the given character are aligned. Lets call this character c. If one string contains more occurrences of c then the first occurrences will be aligned. See examples
Parameters:
c - the character that will be aligned.
toArray
public char[][] toArray()
Return a two-dimensional array of the alignment. The first row correspond to the first string aligned and the second row to the second string.
toString
public java.lang.String toString()
Returns the Alignment as String The format is that each column of the alignment is given in a new row.
If the class is writted correctly the following test program should compile and work:
If the above class is written correctly the test program below should work;
**
* AlignmentTest.java
*
*
* Created: Mon Mar 7 08:51:09 2005
*
* @author <a href="mailto:">M. Hoffmann</a>
* @version 1.0
*/
public class AlignmentTest{
public static void main(String[] args) {
Alignment ali= new Alignment("aababababcabac","ahasababababasdab");
System.out.println(ali.toString());
ali.align('a');
System.out.println(ali.toString());
char[][] answer = ali.toArray();
for (int i=0; i<answer[0].length; ++i) {
System.out.print("--");
}
System.out.println("-");
for (int i=0; i><answer[0].length; ++i) {
System.out.print("|"+answer[0]);
}
System.out.println("|");
for (int i=0; i><answer[0].length; ++i) {
System.out.print("--");
}
System.out.println("-");
for (int i=0; i><answer[0].length; ++i) {
System.out.print("|"+answer[1]);
}
System.out.println("|");
for (int i=0; i><answer[0].length; ++i) {
System.out.print("--");
}
System.out.println("-");
}
} // AlignmentTest
Please help me out>

