Question

how to apply a loaded properties class to a piece of text

Asked by: tigabalm

ok 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.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{
//    GetFile get = new GetFile();
//    get.openFile(inFile);

    //need to load in the properties class
    props.load(new FileInputStream("codes.properties"));
  }
  //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:

ATTGGCTCTTACCACTTGTCCCTCAAAACGACCACCCCATTGACTGGTGGCGATTGCGTCGACGGAGACG
GGGCAAAAGCAAGCTGAACCCGAAAAATAACAAACACTGGGGCTGAGGGGTGGAACTACGAGTGCGCAGA

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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-02-16 at 15:28:55ID21317767
Topics

Java Programming Language

,

Java Standard Edition

,

Delphi Components

Participating Experts
2
Points
250
Comments
82

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. IOException problem
    I have made a client/server application where the server listens for clients messages and receives as well as sends messages to it. The snippet pasted below is that of the client's actionListener for the button b1 which is the "Enter" button which is clicked for se...
  2. IOExceptions and Java Applet problem!
    I am new to Java programming and particularly Java applets. Can some please tell me why this code does not work? It works in a normal Java application because I can use the Throws IOExpection keywords. The error message I keep getting is shown below: a.java [42:1] unrepor...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

by: objectsPosted on 2005-02-16 at 15:32:16ID: 13330154

Heres some code to read from a file

http://www.javaalmanac.com/egs/java.io/ReadLinesFromFile.html

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);

 

by: CEHJPosted on 2005-02-16 at 15:35:12ID: 13330173

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 */  }
      }
}      


 

by: tigabalmPosted on 2005-02-16 at 15:36:04ID: 13330181

ok so i have the read file stuff already implemented in a different class, but wondering how to decode each line?

thanks

objects: are u on here 24/7? lol

peace

 

by: CEHJPosted on 2005-02-16 at 15:36:26ID: 13330182

(That is if i've got the right idea of

>>and i would like it to translate:

)

 

by: objectsPosted on 2005-02-16 at 15:38:26ID: 13330191

> objects: are u on here 24/7? lol

Its my job :)

> but wondering how to decode each line?

need to know the details of the format :)

 

by: tigabalmPosted on 2005-02-16 at 15:44:45ID: 13330226

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:

ATGGATTTATCTGCTCTTCGCGTTGAAGAAGTACAAAATGTCATTAATGCTATGCAGAAAATCTTAGAGT
GTCCCATCTGTCTGGAGTTGATCAAGGAACCTGTCTCCACAAAGTGTGACCACATATTTTGCAAATTTTG

-----

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

 

by: tigabalmPosted on 2005-02-16 at 15:46:31ID: 13330237

sorry off topic, but a friend wants to sign up for EE but doesnt want to sign up on a time basis, but rather the point system?

is there still any way to do that?

thanks

peace

 

by: CEHJPosted on 2005-02-16 at 15:50:09ID: 13330258

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 = "ATTGGCTCTTACCACTTGTCCCTCAAAACGACCACCCCATTGACTGGTGGCGATTGCGTCGACGGA";

                  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 */      }
      }
}

 

by: CEHJPosted on 2005-02-16 at 15:52:33ID: 13330276

>>i have a start and stop code/key as well

What is this?

 

by: tigabalmPosted on 2005-02-16 at 15:55:21ID: 13330289

looks like:


ATG=Start

TAA=Stop
TAG=Stop
TGA=Stop

peace

 

by: tigabalmPosted on 2005-02-16 at 16:00:01ID: 13330312

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

 

by: CEHJPosted on 2005-02-16 at 16:01:47ID: 13330325

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 = "ATTGGCTCTTACCACTTGTCCCTCAAAACGACCACCCCATTGACTGGTGGCGATTGCGTCGACGGATAG";

            TripletReader tr = new TripletReader(new StringReader(triplets));
            String code = null;
            while((code = tr.readNextCode()) != null) {
                  System.out.println(stopCodes.contains(code)? "(ignoring stop code)" : code);
            }
            tr.close();
            }
            catch(Exception e) {
                  e.printStackTrace();
            }
}

 

by: tigabalmPosted on 2005-02-16 at 16:07:39ID: 13330365

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 = "ATTGGCTCTTACCACTTGTCCCTCAAAACGACCACCCCATTGACTGGTGGCGATTGCGTCGACGGATAG";




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

 

by: tigabalmPosted on 2005-02-16 at 16:08:36ID: 13330378

oh and also its still not implementing the translation key

thanks

peace

 

by: objectsPosted on 2005-02-16 at 16:12:56ID: 13330404

> o can i just use a BufferedReader and use a JFileChooser to select a file and implement that instead of:

yes

 

by: tigabalmPosted on 2005-02-16 at 16:17:13ID: 13330425

if i do that though will i still be able to use a stringReader?

thanks

peace

 

by: objectsPosted on 2005-02-16 at 16:25:13ID: 13330473

no you would use code similiar to what I posted earlier and process the String directly, no need to create a StringReader

 

by: tigabalmPosted on 2005-02-16 at 16:27:04ID: 13330484

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 = "ATTGGCTCTTACCACTTGTCCCTCAAAACGACCACCCCATTGACTGGTGGCGATTGCGTCGACGGATAG";

          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

 

by: tigabalmPosted on 2005-02-16 at 16:27:50ID: 13330487

forgot to add that i have a GetFile class that basically is what u posted earlier

peace

 

by: CEHJPosted on 2005-02-16 at 16:33:28ID: 13330514

Well not sure what you're doing ...

 

by: objectsPosted on 2005-02-16 at 16:34:44ID: 13330519

Use you're BufferedReader to read the file line by line, and then use the substring() method in String to iterate thru the triplets.

 

by: CEHJPosted on 2005-02-16 at 16:37:26ID: 13330531

For a file, all you need to change is

TripletReader tr = new TripletReader(new FileReader(args[0])); // pass filename on command line

I saved that String several times to a file - it works just the same

 

by: tigabalmPosted on 2005-02-16 at 16:37:46ID: 13330533

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

 

by: tigabalmPosted on 2005-02-16 at 16:38:45ID: 13330541

command line?

peace

 

by: objectsPosted on 2005-02-16 at 16:39:20ID: 13330546

Use something like the following in a loop:

String triplet = line.substring(pos, pos+3);
pos += 3;

 

by: objectsPosted on 2005-02-16 at 16:40:54ID: 13330555

> I saved that String several times to a file - it works just the same

It will not necessarily work from a file.

 

by: CEHJPosted on 2005-02-16 at 16:41:21ID: 13330557

You don't need to use a BufferedReader. The class i posted handles that. This is the output (from file or String):


ATT
GGC
TCT
TAC
CAC
TTG
TCC
CTC
AAA
ACG
ACC
ACC
CCA
TTG
ACT
GGT
GGC
GAT
TGC
GTC
GAC
GGA
(ignoring stop code)

 

by: tigabalmPosted on 2005-02-16 at 16:42:55ID: 13330567

right i implemented that but where do i input the file?

thanks

peace

 

by: CEHJPosted on 2005-02-16 at 16:45:05ID: 13330580

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 = "ATTGGCTCTTACCACTTGTCCCTCAAAACGACCACCCCATTGACTGGTGGCGATTGCGTCGACGGATAG";

            //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(stopCodes.contains(code)? "(ignoring stop code)" : code);
            }
            tr.close();
            }
            catch(Exception e) {
                  e.printStackTrace();
            }
}

Pass it on the command line

 

by: objectsPosted on 2005-02-16 at 16:45:55ID: 13330585

> The class i posted handles that.

It doesn't handle it, it only supports single lines.

 

by: tigabalmPosted on 2005-02-16 at 16:46:47ID: 13330590

sorry i'm having a programming block... by command line do u mean the interactions pane?

or in the actual program?

thanks

peace

 

by: CEHJPosted on 2005-02-16 at 16:48:41ID: 13330598

>>It doesn't handle it, it only supports single lines.

Why do you need lines in a file of codes? You don't - they just waste space


>>by command line do u mean the interactions pane?

java YourProgram yourcodefile.txt

 

by: CEHJPosted on 2005-02-16 at 16:50:01ID: 13330606

>>do u mean the interactions pane?

If you are using some kind of IDE, you'll need to find out how to pass command line parameters. This is essential in a general sense too

 

by: objectsPosted on 2005-02-16 at 16:50:11ID: 13330608

> Why do you need lines in a file of codes? You don't - they just waste space

Cause thats the requirement ?????

 

by: objectsPosted on 2005-02-16 at 16:51:24ID: 13330611

> > Why do you need lines in a file of codes? You don't - they just waste space

So basically your saying first translate the file into one line, and then parse it.
A lot easier to just do one translation, instead of two.

 

by: CEHJPosted on 2005-02-16 at 16:54:38ID: 13330630

1. Either the codes are in a file of their own
use FileReader

or

2. they're a line in a properties file

use StringReader

Which is it?

 

by: tigabalmPosted on 2005-02-16 at 16:54:51ID: 13330632

yeah that didnt work... got a filenotfound exception... it is in the same folder as the program folder....

thanks

peace

 

by: objectsPosted on 2005-02-16 at 16:56:41ID: 13330641

Use your BufferedReader code, and substring() to iterate thu the tokens.
Let me know if you need more details.

 

by: CEHJPosted on 2005-02-16 at 16:57:01ID: 13330645

Can you clarify where exactly you want those code Strings?

 

by: tigabalmPosted on 2005-02-16 at 16:58:03ID: 13330648

well the DNA code is in a file that looks like this:

>ABC-1 [organism=Saccharomyces cerevisiae][strain=ABC][clone=1]
ATTGCGTTATGGAAATTCGAAACTGCCAAATACTATGTCACCATCATTGA
TGCACCTGGACACAGAGATTTCATCAAGAACATGATCACTGGTACTT
>ABC-2 [organism=Saccharomyces cerevisiae][strain=ABC][clone=2]
GATATTGCTTTATGGAAATTCGAAACTGCCAAATACTATGTCACCATCAT
TGATGCACCTGGACACAGAAATTTCATCAAGAACATGATCACTGGTACTT
>ABC-3 [organism=Saccharomyces cerevisiae][strain=ABC][clone=3]
ATTGCTTTATGGAAATTCGAAACTGCCAAATACTATGTTATGATGCACCT
GGACACAGAGATTTCATCAAAAACATGATCACTGGTACTT
>Xlae28S [organism=Xenopus laevis]
GGCTCGTGCGTCGATGAAGAACGCAGCAC

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

 

by: tigabalmPosted on 2005-02-16 at 17:01:02ID: 13330665

objects: yeah some more clarification would be nice, implementation wise

CEHJ:well basically i want to pass in the DNA code strings and have it translated through the tanslation table...

thanks

peace

 

by: objectsPosted on 2005-02-16 at 17:05:36ID: 13330687

> objects: yeah some more clarification would be nice, implementation wise

Let me know when you decide you need to use a BufferedReader and I'll walk u thru it.

 

by: CEHJPosted on 2005-02-16 at 17:05:48ID: 13330688

I was under the impression that you just had the codes. It does work if the file only contains code triplets. You'd have to change the approach for that kind of file

 

by: tigabalmPosted on 2005-02-16 at 17:09:50ID: 13330712

ok... any ideas as to how i should change my approach?  ;)

thanks

peace

 

by: objectsPosted on 2005-02-16 at 17:10:29ID: 13330718

>  It does work if the file only contains code triplets.

It won't even work on the example file given (except of course if you edit it as you are suggesting)

 

by: objectsPosted on 2005-02-16 at 17:11:15ID: 13330724

> ok... any ideas as to how i should change my approach?  ;)

yes, use the approach I've been suggesting all thread ;)

 

by: tigabalmPosted on 2005-02-16 at 17:18:12ID: 13330767

ok if i HAVE to!  heheh j/k

umm still dont fully understand objects' method though (you are talking about the links u posted in the beginning right?)

i mean where should i put the buffered reader etc?

thanks

peace

 

by: CEHJPosted on 2005-02-16 at 17:18:52ID: 13330770

If that's the file you have, then you should use a BufferedReader

 

by: tigabalmPosted on 2005-02-16 at 17:22:38ID: 13330790

yeah i am usings BufferedReader, but where should I put the BufferedReader?

and how should i parse the code file into the translated form?

thanks

peace

 

by: objectsPosted on 2005-02-16 at 17:28:57ID: 13330818

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/egs/java.io/ReadLinesFromFile.html
http://www.javaalmanac.com/egs/java.util/Props.html
http://www.javaalmanac.com/egs/java.util/GetSetProps.html

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.

 

by: tigabalmPosted on 2005-02-16 at 17:33:37ID: 13330834

ok so basically i have to get rid of CEHJ's above posted TripletReader and instead implement the loop?

where should i place the loop?

thanks

peace

 

by: tigabalmPosted on 2005-02-16 at 17:36:58ID: 13330846

also what are pos? IE what type?

thanks

peace

 

by: objectsPosted on 2005-02-16 at 17:37:37ID: 13330850

> i have to get rid of CEHJ's above posted TripletReader and instead implement the loop?

Yes its only good for handling single lines

> where should i place the loop?

inside the loop that is reading lines from file
ie. read a line from file and process it if it contains triplets

 

by: objectsPosted on 2005-02-16 at 17:38:15ID: 13330854

 

by: tigabalmPosted on 2005-02-16 at 17:39:28ID: 13330861

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

 

by: objectsPosted on 2005-02-16 at 17:50:27ID: 13330903

you need a loop to read each line, not just the first line (see the example I posted earlier)
As a 1st step get it jusrt reading each line, then we can work on parsiung the lines read.

 

by: tigabalmPosted on 2005-02-16 at 17:52:01ID: 13330915

sorry which example you posted earlier?

thanks

peace

 

by: tigabalmPosted on 2005-02-16 at 18:27:12ID: 13331041

btw, thanks to everyone who contributed!

still not quite sure what to do though....

thanks

peace

 

by: tigabalmPosted on 2005-02-16 at 18:34:25ID: 13331062

oh also for when i parse through the DNA code file... is there a way that i can start at a specified code...

IE: @ ATG start the loop

thanks

peace

 

by: objectsPosted on 2005-02-16 at 18:42:49ID: 13331097

 

by: tigabalmPosted on 2005-02-16 at 18:46:03ID: 13331113

well what should i implement in place of  "process" in the while loop?

thanks

peace

 

by: objectsPosted on 2005-02-16 at 19:51:48ID: 13331402

a loop to parse the line that was read.

 

by: tigabalmPosted on 2005-02-16 at 19:55:09ID: 13331417

ic but i dont really know how to do this...

any "tips" on how i can go about doing this?

thanks

peace

 

by: objectsPosted on 2005-02-16 at 19:59:47ID: 13331438

be something like:

int pos = 0;
while (pos<line.length()-3)
{
   String triplet = line.substring(pos, pos+3);
   System.out.println(triplet);
}

 

by: tigabalmPosted on 2005-02-16 at 20:03:13ID: 13331447

ok so then this goes in here:

  public void separate(File inFile){
    int pos = 0;
    while (pos<line.length()-3)
    {
      String triplet = line.substring(pos, pos+3);
      System.out.println(triplet);
    }
    //line = reader.readLine();
  }
--------
right?

thanks man!  ur a life saver!

peace

 

by: objectsPosted on 2005-02-16 at 20:08:54ID: 13331471

no it goes inside you loop that is reading file
ie. that loop is applied to each line (that contains triplets) read from file

 

by: tigabalmPosted on 2005-02-16 at 20:09:25ID: 13331476

it works but its only reading the first 2 characters and then printing that over and over again

peace

 

by: objectsPosted on 2005-02-16 at 20:09:36ID: 13331477

I'd suggest first getting the code to read the file line by line working.
then once that is done worry about parsing each line

 

by: tigabalmPosted on 2005-02-16 at 20:12:44ID: 13331489

YES!!  thank you so much!  now it parsing everything fine!

just need to figure out how to get it to read the properties object

thanks again!!

peace

 

by: objectsPosted on 2005-02-16 at 20:19:26ID: 13331516

 

by: tigabalmPosted on 2005-02-16 at 20:28:25ID: 13331562

is there any way that instead of "a.b" i can have it set to key.value or something?

thanks

peace

 

by: objectsPosted on 2005-02-16 at 20:33:30ID: 13331591

"a.b" is the key, it can be whatever you like

 

by: objectsPosted on 2005-02-16 at 20:33:56ID: 13331594

In your case its the triplet (from memory)

 

by: tigabalmPosted on 2005-02-16 at 20:35:41ID: 13331605

but i mean that is the general form right?

how can i set it so that a = AGT, ATC, etc and b = A,T,R etc

and then "new value" = A,T,R etc

thank you!

peace

 

by: objectsPosted on 2005-02-16 at 20:50:30ID: 13331676

Sorry, not following what you mean

What does your properties file look like, and what do you want to get from it?

 

by: tigabalmPosted on 2005-02-17 at 00:01:38ID: 13332489

properties file looks like:
GCT=A
GCC=A
GCA=A
GCG=A

CGT=R
CGC=R
CGA=R
-----------

and i would like to have it so that the input file (my DNA code file, which is parsed into triplets) can be "decoded" according to the properties file:

ie: dna code: GCTGCCGCAGCGCGT -> AAAAR

thanks

peace

 

by: objectsPosted on 2005-02-17 at 00:08:22ID: 13332530

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);
}

 

by: tigabalmPosted on 2005-02-23 at 13:56:57ID: 13387588

sorry been gone for a while...

objects: what is the variable line?  and where should i declare it?

thanks

peace

 

by: objectsPosted on 2005-02-23 at 13:59:52ID: 13387616

line is a String variable containing the last line read from file

 

by: tigabalmPosted on 2005-02-23 at 14:00:56ID: 13387624

so should i in the class decalre:

private String line;

?

thanks

 

by: objectsPosted on 2005-02-23 at 14:08:07ID: 13387695

it can just be a local variable

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...