954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to read file using loopup table

Hi all, I'm having some problem with my codes. I have a output that is generated into a txt file. Now, I need to read the txt file and convert the output into something else.

This is the output that is store in a txt file:
VAL
LEU
SER
PRO
ALA
ASP
LYS
THR
ASN

They are all amino acid 3-letter abbreviation. I need to convert them into 1-letter abbreviation.

For example,
Val should be 'V'.
Leu should be 'L'.
Ser should be 'S'.
Pro should be 'P'.
Ala should be 'A'.
Asp should be 'D'.
Lys should be 'K'.
Thr should be 'T'.
Asn should be 'N'.

The final output should be only 1-letter abbreviation.

Like:
V
L
S
P
A
D
K
T
N

May I know how to do it?

Sunshineserene
Junior Poster
187 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 


First you have to read the file for that
Make a File object and read its contents using BufferedReaderObject.readLine();
this will return a string. with values VAL
LEU
SER
PRO
ALA
etc..

next is to convert this each valueinto corresponding letter by nested if conditions.

Continue this while(!feof())


+****************+
| new_programmer |
******************

new_programmer
Junior Poster in Training
53 posts since Jul 2010
Reputation Points: 10
Solved Threads: 6
 

HashMap (look it up in the API).
Add the 3 letter codes as keys and the 1 letter codes as values.
HashMap then does the lookup for you, value = map.get(key).

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

You can put the mapping in a text file and read from that file.
In this case, if you need to add new mapping, you don't have to change code.

HashMap (look it up in the API). Add the 3 letter codes as keys and the 1 letter codes as values. HashMap then does the lookup for you, value = map.get(key).
java_programmer
Junior Poster
124 posts since May 2006
Reputation Points: 10
Solved Threads: 17
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: