Main Topics
Browse All Topicsok so i finished my translate class:
//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 FileInputStream inStream = new FileInputStream("codes.pro
// 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{
// GetFile get = new GetFile();
// get.openFile(inFile);
//need to load in the properties class
props.load(new FileInputStream("codes.pro
}
//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);
}
}
---------
now i would like to have props be applied to an input file so that it could translate it,
what would be the best way to go about doing this?
IE: my loaded proprs looks like:
GCT=A
GCC=A
GCA=A
GCG=A
----------
and i would like it to translate:
ATTGGCTCTTACCACTTGTCCCTCAA
GGGCAAAAGCAAGCTGAACCCGAAAA
i'd appreciate any help!
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.
Read each triplet then get the map value using the read triplet as the key:
class TripletReader {
private FileReader in;
public TripletReader(String fileName) {
in = new FileReader(fileName);
}
public String readNextCode() throws IOException {
int charsRead = in.read(codeBuffer);
if (charsRead == 3) {
return new String(codeBuffer);
}
else if (charsRead < 3) {
throw new EOFException("Incorrect number of characters in source file");
}
else {
in.close();
return null;
}
}
public void close() {
try { in.close(); } catch(IOException e) { /* ignore */ }
}
}
well i think CHEJ might have it, but still not quite sure...
there are a couple complications:
each DNA string is not set to triplets, although each key is set to three chars.
for example
say i have a DNA strand like:
ATGGATTTATCTGCTCTTCGCGTTGA
GTCCCATCTGTCTGGAGTTGATCAAG
-----
i have a start and stop code/key as well so at a certain triplet it should print start, and then go through and for every three it should print the corresponding protein value, and then when it reaches a stop codon, it should print stop, then look for the start codon again and repeat...
thanks
peace
Is this the sort of thing? (Compile and run as Triplets.java)
import java.io.*;
public class Triplets {
public static void main(String[] args) {
try {
String triplets = "ATTGGCTCTTACCACTTGTCCCTCA
TripletReader tr = new TripletReader(new StringReader(triplets));
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 */ }
}
}
CHEJ you are awesome!
couple more things though, how can i have that applied to the properties class?
i'm on Dr.Java right now and in the interactions pane i did" java Triplets"
and it separated that string into triplets and printed it out, and now i am just wondering how to set those triplets to the key i(we[you, objects, and zzynnx) made last night...
thanks
peace
OK, you could use the following. I've put a stop code at the end:
public static void main(String[] args) {
try {
java.util.Set stopCodes = new java.util.HashSet();
stopCodes.add("TAA");
stopCodes.add("TGA");
stopCodes.add("TAG");
String triplets = "ATTGGCTCTTACCACTTGTCCCTCA
TripletReader tr = new TripletReader(new StringReader(triplets));
String code = null;
while((code = tr.readNextCode()) != null) {
System.out.println(stopCod
}
tr.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
ummm nothing really changed....
also need it to read the string from a file rather than the above posted string... so can i just use a BufferedReader and use a JFileChooser to select a file and implement that instead of:
String triplets = "ATTGGCTCTTACCACTTGTCCCTCA
also I really appreciate the help, but maybe post only some of the code, i dont want my professor to think that i just ripped off someone's code (which i am) but would also like to learn as well...please dont take any offense to this...
thanks
peace
yeah thats what i ended up doing:
public class Separate {
private static File inFile;
public static void main(String[] args) {
try {
java.util.Set stopCodes = new java.util.HashSet();
stopCodes.add("TAA");
stopCodes.add("TGA");
stopCodes.add("TAG");
GetFile g = new GetFile();
g.openFile(inFile);
//String triplets = "ATTGGCTCTTACCACTTGTCCCTCA
TripletReader tr = new TripletReader(new FileReader(inFile));
....
--------------------
and it compiles and when i try to run "java Separate"
it just hangs there... doesnt do anything....
thanks
peace
sorry was trying to figure some things out...
here is what i did: i have the above posted code with GetFile, and in my GetFile class i have an openFile() method: which looks like:
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+ "\"");
line = reader.readLine();
}
}
now when it prints, it doesnt print into triplets, like when i was using the string reader, but instead prints the while loop.... is there any way to bypass this and have it go to CEHJ's triplet reader class?
thanks
peace
public static void main(String[] args) {
try {
java.util.Set stopCodes = new java.util.HashSet();
stopCodes.add("TAA");
stopCodes.add("TGA");
stopCodes.add("TAG");
String triplets = "ATTGGCTCTTACCACTTGTCCCTCA
//TripletReader tr = new TripletReader(new StringReader(triplets));
TripletReader tr = new TripletReader(new FileReader(args[0]));
String code = null;
while((code = tr.readNextCode()) != null) {
System.out.println(stopCod
}
tr.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
Pass it on the command line
well the DNA code is in a file that looks like this:
>ABC-1 [organism=Saccharomyces cerevisiae][strain=ABC][cl
ATTGCGTTATGGAAATTCGAAACTGC
TGCACCTGGACACAGAGATTTCATCA
>ABC-2 [organism=Saccharomyces cerevisiae][strain=ABC][cl
GATATTGCTTTATGGAAATTCGAAAC
TGATGCACCTGGACACAGAAATTTCA
>ABC-3 [organism=Saccharomyces cerevisiae][strain=ABC][cl
ATTGCTTTATGGAAATTCGAAACTGC
GGACACAGAGATTTCATCAAAAACAT
>Xlae28S [organism=Xenopus laevis]
GGCTCGTGCGTCGATGAAGAACGCAG
which didnt work so i tried copying just the strings into a separate txt file and it still didnt work...
i have a properties object but that is holding my translation table
AGT=A, etc
please hang in there with me, almost done with this project :)
thanks
peace
Now that CEHJ has finally understood that his suggestion would not work, heres a summary of the relavant pieces I've mentioned:
http://www.javaalmanac.com
http://www.javaalmanac.com
http://www.javaalmanac.com
Use something like the following in a loop to parse each line:
String triplet = line.substring(pos, pos+3);
pos += 3;
The startsWith() method of the String class will also be useful for determine which lines do and don't contain triplets.
> also what are pos? IE what type?
an int
http://java.sun.com/j2se/1
ok so i tried that and it looks like this:
try{
BufferedReader reader = new BufferedReader(new FileReader(inFile));
line = reader.readLine();
//System.out.println("The line : \"" +line+ "\"");
while(line!=null){
String triplet = line.substring(pos, pos+3);
pos += 3;
but when i try running it, i get a string index outofbounds error (at runtime)
thanks
peace
ok, so for each line you need to extract the triplets and lookup the symbol, something like:
StringBuffer result = new StringBuffer();
int pos = 0;
while (pos<line.length()-3)
{
// get next triplet
String triplet = line.substring(pos, pos+3);
System.out.println(triplet
// lookup code in properties
String code = props.getProperty(triplet)
// append code to result string
result.append(code);
}
Business Accounts
Answer for Membership
by: objectsPosted on 2005-02-16 at 15:32:16ID: 13330154
Heres some code to read from a file
/egs/java. io/ ReadLin esFromFile .html
http://www.javaalmanac.com
You then need to decode each line and add the mappings to an empty Properties instance
Once done save that properties file to disk
props.save(out);