anyone help me solve my assignment ?
Hi everyone , i'm newbie of JAVA so , i have a lot of thing wanna ask , please help me . this is my assignment :
[size=large]Question 2—Nucleotides[/size]
DNA can be considered the source code of life1. It contains the instructions for (most of the) life on
Earth. Unlike digital computers that use binary to encode information and instructions in 1s and 0s, DNA
has four possible nucleotides: Adenine, Cytosine, Guanine, and Thymine, represented by A, C, G and T,
respectively.
Bioinformatics is field of study that applies concepts from computer science and statistics to study
molecular biology using computer software and hardware.
Biologists and bioinformaticians typically store genetic databases of DNA in a text‐based file format
called FASTA2. The FASTA file format is relatively simple:
• Each FASTA‐formatted file starts with a header line. The first character on a header line is
always the greater‐than character (‘>’),
• The header line is followed by lines of sequence data (As, Cs, Gs, and Ts), with 80 (or fewer)
characters per line.
Example3:
Code:
>gi|21071042|ref|NM_000193.2| Homo sapiens sonic hedgehog (SHH), mRNA
GCGAGGCAGCCAGCGAGGGAGAGAGCGAGCGGGCGAGCCGGAGCGAGGAAGGGAAAGCGCAAGAGAGAGC
GCACACGCACACACCCGCCGCGCGCACTCGCGCACGGACCCGCACGGGGACAGCTCGGAAGTCATCAGTT
CCATGGGCGAGATGCTGCTGCTGGCGAGATGTCTGCTGCTAGTCCTCGTCTCCTCGCTGCTGGTATGCTC
GGGACTGGCGTGCGGACCGGGCAGGTTCGGGAAGAGGAGGCACCCCAAGCTGACCCCTTTAGCC
TACAAGCAGTTTATCCCCAATGTGGCCGAGAAGACCCTAGGCGCCAGCGGAAGGTATGAAGGGAAGATCT
CCAGAAACTCCGAGCGATTTAAGGAACTCACCAATTACAACCCCGACATCATATTTAAG
Write a program that will
• read a file containing one FASTA formatted sequence record,
• count the number of each of the four nucleotides (A,C,G and T) per sequence in the record, and
• print a histogram displaying the genetic make‐up of the sequence record.
Input: Use JFileChooser to prompt the user to select a FASTA formatted file, and use Scanner to read
the file selected by the user. The FASTA formatted file selected by the user will contain at least one
sequence record, but may contain more than one. Assume that the file chosen by the user will meet the
standard FASTA file format described above, and that the sequence data will be all upper case
characters.
Code:
[b]File input with JFileChooser and Scanner[/b]
So far in the course you’ve used Scanner to get input from the user with the keyboard. In some
situations, getting input from the keyboard is cumbersome (entering 1000 bases, for example).
To use [b]JFileChooser[/b] your program must add a couple of import statements to the regular import
statements:
Code:
import java.io.File;
import java.io.FileNotFoundException;
import javax.swing.JFileChooser;
You’ll also need to insert and use the following static method:
/**
* Prompt the user to select a file using JFileChooser and return
* the File object that the user selected.
*
* @return the file selected by the user
*/
public static File getFile() {
JFileChooser chooser = new JFileChooser();
File fastaFile = null;
int returnValue;
// show the open file dialog
returnValue = chooser.showOpenDialog(null);
// check to see that the user clicked the OK button
if (returnValue == JFileChooser.APPROVE_OPTION) {
// get the selected file
fastaFile = chooser.getSelectedFile();
}
return fastaFile;
}
So far we’ve been using Scanner by passing System.in to get input from the keyboard:
Scanner keyboard = new Scanner(System.in);
Scanner can also be used to read the contents of a file. Simply replace System.in with an
instance of a File variable (like the one returned by getFile()):
Scanner fileReader = new Scanner(aFile);
Finally, you must surround any code using a fileReader instance of Scanner using a try/catch
block. Try/catch blocks are used in Java to deal with possible runtime exceptions. In the case of
reading files using Scanner, we have to deal with a possible FileNotFoundException – an
exception that may occur if the user typed in a file name that did not exist.
Example:
try {
Scanner fileReader = new Scanner(aFile);
// your code working with fileReader goes here
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Methods: In addition to the getFile() method, your program must implement and use the following
static methods:
Code:
public static void main(String[] args)
Your main method should prompt the user to select a FASTA file using the getFile() method.
Then, the main method should pass the file to getHeader() and getSequence() to get the header and
sequence from the FASTA file. Next, the main method should call countBase() for each of the four
different types of bases and determine the percentage of the entire sequence that each base
represents. The percentage should be rounded to the nearest whole number. Finally, the main method
should call printDNAHistogram() to print out the histogram representing the statistics of the file.
Code:
public static String getHeader(File fastaFile)
Using Scanner, the getHeader method should read the first line contained in fastaFile
(which is the header line of the record). This method should remove the leading ‘>’ character before
returning the header line.
Code:
public static String getSequence(File fastaFile)
Using Scanner, the getSequence method should skip the first line contained in fastaFile
(which is the header line of the record) and store any subsequent lines (the sequence data) until the
Scanner has no more lines left. The getSequence method should use the hasNextLine() and
nextLine() methods from the Scanner class to read the sequence from the file. Once the Scanner
has no more lines remaining, the getSequence method should return all of the data that it stored.
Code:
public static int countBase(String sequence, char base)
The countBase method accepts sequence data (a String containing only As, Cs, Gs, and Ts),
and a specific base character to count. The countBase method should return the number of times
that base occurred in sequence.
Code:
public static void printDNAHistogram(String header, int aPct, int
cPct, int gPct, int tPct)
The printDNAHistogram method should print out the histogram for the result calculated by
other methods. The printDNAHistogram method should first print out header, and then it should
call the printBar method (described below) for each of aPct, cPct, gPct, and tPct.
Code:
public static void printBar(String label, int percent, char barSymbol)
The printBar method should print out a single bar for a histogram. The printBar method
should first print out label. Then, the method should print out percent copies of the symbol
barSymbol. Finally, the method should print out the actual percentage that the bar displays. All of
this information should be on the same line.
For example, the call
Code:
printBar("A",25,'=');
would print out the following line:
Code:
A: ========================= (25%)
Output: Use System.out for all output. For the sequence record in the file, print:
1. The header line (without the leading ‘>’), and
2. A histogram showing the percentage of As, the percentage of Cs, the percentage of Gs, and the
percentage of Ts.
Using the example sequence from above, an execution of your program would look like this:
Code:
gi|21071042|ref|NM_000193.2| Homo sapiens sonic hedgehog (SHH), mRNA
A: ========================= (25%)
G: ================================= (33%)
C: ============================= (29%)
T: ============== (14%)
Programmed by [your name here].
End of processing.
Hand‐in: Save your file using the naming conventions described in the beginning of the assignment.
Upload your file using the web‐based hand‐in tool. Also, submit the output for the two FASTA files
provided on the course web page.
PDF file : Code:
http://www.mediafire.com/?trgt46rb81n1g8h
I get stuck at this point when filling out at (while loop) ,any one help me
Code:
import java.io.File;
import java.io.FileNotFoundException;
import javax.swing.JFileChooser;
import java.util.Scanner;
// name of class.
public class QuangNguyenA3Q2 {
public static void main (String[]args) {
try {
Scanner fileReader = new Scanner(getFile());
// code working with fileReader goes here
int A;
int C;
int G;
int T;
char x;
while () {
if( x == 'A') A++;
if( x == 'C') C++;
if( x == 'G') G++;
if( x == 'T') T++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public static File getFile() {
JFileChooser chooser = new JFileChooser();
File fastaFile = null;
int returnValue;
// show the open file dialog
returnValue = chooser.showOpenDialog(null);
// check to see that the user clicked the OK button
if (returnValue == JFileChooser.APPROVE_OPTION) {
// get the selected file
fastaFile = chooser.getSelectedFile();
}
return fastaFile;
}
}