its me again objects (the guy with the DNA translation program)
trying to figure out how to apply the properties to the DNA code file
peace
Main Topics
Browse All Topicsok so i have a properties class and an inputStream
wondering how to sort/parse/translate the inputStream according to the loaded properties object?
i'd appreciate all the help i can get!
thanks
peace
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
well my translate class is:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
//This class holds the genome/protein conversion through the use of a properties map.
public class Translate{
//Instance of a properties class which holds the key for the translation tbale
private Properties props = new Properties();
private File inFile;
//this method loads the key and then our read/write class can call this to translate the input file
//@param InputStream the properties file that holds the translation table
public void load(InputStream in) throws IOException{
//need to load in the properties class
props.load(new FileInputStream("codes.pro
}
//This method actually translates the separated file though the use of a while loop that parses through the file
//@param inFile the file that is separated
//@param in the properties object which holds the translation table
public void translate(File inFile, InputStream in){
Separate sep = new Separate();
//sep.separate(inFile) = separated;
//loop that translates the code
try {
BufferedReader inReader = new BufferedReader(new FileReader("infilename"));
String str;
while ((str = inReader.readLine()) != null) {
}
inReader.close();
}
catch (IOException e) {
}
}
//the method that gets a Protein code
//@param code the protein code that we are looking for
public String getProtein(String code){
return (String) props.get(code);
}
}
------------------------
and my separate class is:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
//This is the class the parses the DNA code into bits of three so it can be translated using the translation table
public class Separate {
private static File inFile;
private String line;
private int pos;
public Separate(){
}
//This method parses the DNA code into parts of three beginning at the first start code
public void separate(File inFile){
String triplet = line.substring(pos, pos+3);
pos += 3;
//line = reader.readLine();
}
public static void main(String[] args) {
GetFile g = new GetFile();
g.openFile(inFile);
}
its pretty ugly in both of those, but i was basically going through some trial and error...
thanks
peace
oh and sorry my getfile class is:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class GetFile{
//private JButton openButton;
private FileInputStream input;
private String sourceFilename;
private File inFile;
private String line;
private int pos;
private Separate s;
public GetFile(){
openFile(inFile);
//inFile.close();
}
public static void main(String[] args){
new GetFile();
Separate s = new Separate();
}
public void openFile(File inFile){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelecti
int result = fileChooser.showOpenDialog
if (result == JFileChooser.CANCEL_OPTION
return;
inFile = fileChooser.getSelectedFil
try{
input = new FileInputStream(inFile);
}
catch (IOException ioException){
JOptionPane.showMessageDia
}
try{
BufferedReader reader = new BufferedReader(new FileReader(inFile));
line = reader.readLine();
//System.out.println("The line : \"" +line+ "\"");
while(line!=null){
System.out.println("The next line is " +line);
// String triplet = line.substring(pos, pos+3);
// pos += 3;
// line = reader.readLine();
// System.out.println("The next line is \"" +line+ "\"");
// line = reader.readLine();
}
}
catch
(IOException exception) {
System.out.println("readLi
}
}
}
thanks
peace
your reading loop should look something like:
BufferedReader reader = new BufferedReader(new FileReader(inFile));
StringBuffer result = new StringBuffer();
while((line=in.readLine()!
System.out.println("The next line is " +line);
if (!line.startsWith(">"))
{
int pos = 0;
while (pos<line.length()-3)
{
String triplet = line.substring(pos, pos+3);
String symbol = properties.getProperty(sym
result.append(symbol);
pos += 3;
}
}
}
its still a "little" messy but should all be there:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
//This class holds the genome/protein conversion through the use of a properties map.
public class Translate{
//Instance of a properties class which holds the key for the translation tbale
private Properties props = new Properties();
private File input;
private File inFile;
private InputStream in;
private String line;
private String symbol;
//this method loads the key and then our read/write class can call this to translate the input file
//@param InputStream the properties file that holds the translation table
public void load(InputStream in) throws IOException{
//need to load in the properties class
props.load(new FileInputStream("codes.pro
}
//This method actually translates the separated file
//@param inFile the file that is separated
//@param in the properties object which holds the translation table
public void translate(File inFile, InputStream in){
Separate sep = new Separate();
sep.separate(input);
// String string = props.getProperty("triplet
// props.setProperty("triplet
try{
BufferedReader reader = new BufferedReader(new FileReader(inFile));
StringBuffer resultFile = new StringBuffer();
while((line=reader.readLin
System.out.println("The next line is " +line);
if (!line.startsWith(">"))
{
int pos = 0;
while (pos<line.length()-3)
{
String triplet = line.substring(pos, pos+3);
String symbol = props.getProperty(symbol);
resultFile.append(symbol);
pos += 3;
}
}
}
}
catch (IOException exception) {
System.out.println("readLi
}
}
//the method that gets a Protein code
//@param code the protein code that we are looking for
public String getProtein(String code){
return (String) props.get(code);
}
thanks
peace
sorry mang... just had two midterms and brain is working so well....
but getting a null pointer exception at runtime...
can u just take a look at my two classes and see if you can find what is throwing it?
getFile class:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class GetFile{
//private JButton openButton;
private FileInputStream input;
private FileInputStream inFile;
private String sourceFilename;
private File codes;
private String line;
private int pos;
private Separate s;
private File resultFile;
public GetFile(){
//openFile(inFile);
//inFile.close();
}
public static void main(String[] args){
new GetFile();
Separate s = new Separate();
}
public void openFile(File inFile){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelecti
int result = fileChooser.showOpenDialog
if (result == JFileChooser.CANCEL_OPTION
return;
inFile = fileChooser.getSelectedFil
try{
input = new FileInputStream(inFile);
}
catch (IOException ioException){
JOptionPane.showMessageDia
}
__________________________
translate class:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
//This class holds the genome/protein conversion through the use of a properties map.
public class Translate{
//Instance of a properties class which holds the key for the translation tbale
private Properties props = new Properties();
private File input;
private File inFile;
private InputStream in;
private String line;
private String symbol;
//this method loads the key and then our read/write class can call this to translate the input file
//@param InputStream the properties file that holds the translation table
public void load(InputStream in) throws IOException{
//need to load in the properties class
props.load(new FileInputStream("codes.pro
}
//This method actually translates the separated file
//@param inFile the file that is separated
//@param in the properties object which holds the translation table
public void translate(File inFile, InputStream in){
Separate sep = new Separate();
sep.separate(input);
// String string = props.getProperty("triplet
// props.setProperty("triplet
try{
BufferedReader reader = new BufferedReader(new FileReader(inFile));
StringBuffer resultFile = new StringBuffer();
while((line=reader.readLin
System.out.println("The next line is " +line);
if (!line.startsWith(">"))
{
int pos = 0;
while (pos<line.length()-3)
{
String triplet = line.substring(pos, pos+3);
String symbol = props.getProperty(triplet)
resultFile.append(symbol);
pos += 3;
}
}
}
}
catch (IOException exception) {
System.out.println("readLi
}
}
//the method that gets a Protein code
//@param code the protein code that we are looking for
public String getProtein(String code){
return (String) props.get(code);
}
}
thanks
peace
and then i am calling it like this:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
//This class stores the gene information and translated information
public class Store{
private static File inFile;
private static Separate sep;
private static Translate t;
private static InputStream in;
private static File inputFile;
private static String translated;
public static void main(String[] args) {
try{
GetFile g = new GetFile();
g.openFile(inFile);
t.load(in);
t.translate(inputFile,in);
}
catch
(IOException exception) {
System.out.println("readLi
}
}
}
________________________
i think it is because the t.translate isnt getting anything... so how do i connect the FileInputStream from getFile to the inputFile in translate?
thanks a bunch man!
peace
man... now i get a null pointerexception... it gets past t.load(in)... but i dont htink its getting anything from the "inputFile"
i was looking through my code... and i dont think the file from getFile is linked to the inputFile in separate... therefore when translate runs... its not getting anything to translate...
thanks
peace
sorry would prolly help if i posted the Separate class:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
//This is the class the parses the DNA code into bits of three so it can be translated using the translation table
public class Separate {
private static File inFile;
private String line;
private int pos;
public Separate(){
}
//This method parses the DNA code into parts of three beginning at the first start code
public void separate(File inFile){
GetFile get = new GetFile();
get.openFile(inFile);
int pos = 0;
while (pos<line.length()-3)
{
String triplet = line.substring(pos, pos+3);
System.out.println(triplet
}
//line = reader.readLine();
}
// public static void main(String[] args) {
// GetFile g = new GetFile();
// g.openFile(inFile);
//String triplets = "ATTGGCTCTTACCACTTGTCCCTCA
// TripletReader tr = new TripletReader(new FileReader(inFile));
// String code = null;
// while((code = tr.readNextCode()) != null) {
// System.out.println(code);
// }
// tr.close();
// }
// catch(Exception e) {
// e.printStackTrace();
// }
}
//}
//class TripletReader {
//
// private Reader in;
// private char[] codeBuffer;
//
// public TripletReader(Reader in) {
// this.in = in;
// codeBuffer = new char[3];
// }
//
// public String readNextCode() throws IOException {
// String code = null;
// int charsRead = in.read(codeBuffer);
// if (charsRead == 3) {
// code = new String(codeBuffer);
// }
// else if (charsRead < 0) {
// in.close();
// }
// else if (charsRead < 3) {
// throw new EOFException("Incorrect number of characters in source file");
// }
// return code;
//
// }
//
// public void close() {
// try { in.close(); } catch(IOException e) { /* ignore */ }
// }
//}
--------------------------
thanks
peace
thats exactly what i just thought...
what i wanted it to do was to separate an input file... then the translate class would take the separated file and apply codes.properties to the separated strings and then translate...
now i am thinking... either i combine separate() and translate()
or i have separate() save the separated file and then translate() will read the new file...
which would u suggest?
thanks
peace
public static void main(String[] args) {
try{
GetFile g = new GetFile();
g.openFile(inFile);
t = new Translate();
t.load(in);
System.out.println("got here");
t.translate(inFile,in);
System.out.println("got here");
----------
it prints "got here" and then throws the error... so i am assuming it the "t.translate(inFile,in);" since it doesnt print the second print statement
thanks
peace
no because ytou pass it to the translate method, you need to pass a valid File to translate.
Also in is not used so you can get rid of it.
translate will then look like:
public void translate(File inFile){
and you'll call it using something like:
File inFile = new File("xyz.properties");
t.translate(inFile);
you can also get rid of the following line
private File inFile;
ok so this is what my translate() method looks like now:
public void translate(File inFile, InputStream in){
// String string = props.getProperty("triplet
// props.setProperty("triplet
try{
GetFile g = new GetFile();
g.openFile(inFile);
System.out.println("going to translate");
BufferedReader reader = new BufferedReader(new FileReader(inFile));
StringBuffer resultFile = new StringBuffer();
System.out.println("readin
while((line=reader.readLin
System.out.println("The next line is " +line);
if (!line.startsWith(">"))
{
int pos = 0;
while (pos<line.length()-3)
{
String triplet = line.substring(pos, pos+3);
String symbol = props.getProperty(triplet)
resultFile.append(symbol);
pos += 3;
}
}
------------
i deleted inFile from the class so what should the "inFile" be in:
g.open(inFile);
and
BufferedReader reader = new BufferedReader(new FileReader(inFile));
thanks
peace
i'm finishing up about now sorry, may be back online tomorrow
otherwise monday
change GetFile to
public InputStream openFile() throws IOException {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelecti
int result = fileChooser.showOpenDialog
if (result == JFileChooser.CANCEL_OPTION
return;
File inFile = fileChooser.getSelectedFil
input = new FileInputStream(inFile);
return input;
}
transtale to:
public void translate(InputStream in){
try{
System.out.println("going to translate");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuffer resultFile = new StringBuffer();
System.out.println("readin
while((line=reader.readLin
System.out.println("The next line is " +line);
if (!line.startsWith(">"))
{
int pos = 0;
while (pos<line.length()-3)
{
String triplet = line.substring(pos, pos+3);
String symbol = props.getProperty(triplet)
resultFile.append(symbol);
pos += 3;
}
}
and main to:
public static void main(String[] args) {
try{
GetFile g = new GetFile();
InputStream in = g.openFile();
t = new Translate();
t.load(in);
System.out.println("got here");
t.translate(g.openFile());
System.out.println("got here");
funny cause thats what i ended up doing... guess i am learning this stuff lol...
i'm so happy that i works!! one thing tho... when i run java Store... it opens two jfilechoosers... so that i'll select one file, and then instantly anothner filechooser window opens... and then afteri choose the 2nd one it starts translating...
but the other funny thing is that it just keeps running forever.... i let it run for like 5 minutes and it just kept spitting out the same translation over and over again....
do i need to close the file stream or something?
also could u help me with hamming distances? i opened up a new question...
thanks so much!!
peace
Business Accounts
Answer for Membership
by: objectsPosted on 2005-02-16 at 18:43:39ID: 13331103
Whats in your stream?