• Post Reply Bookmark Topic Watch Topic
  • New Topic

reading two files and extracting the info re from other file

 
sina sinchen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another question.
I have a file whose content is like:
RP00676
RP00675
RP00674
RP00671
RP00669
RP00666
RP00665
I have to read this file for each number say RP00671 and look for this ID in another file and extract some data from the other file.The other file looks like :
UNIQUE-ID - RP00676
TYPES - RNA-Polymerase-Binding-Reactions
ACTIVATORS - (PD00196 . BS00793)
OFFICIAL-EC? - T
REACTANTS - RNAP70-CPLX
REACTANTS - PM00676
//
UNIQUE-ID - RP00675
TYPES - RNA-Polymerase-Binding-Reactions
ACTIVATORS - (PD00196 . BS00791)
OFFICIAL-EC? - T
REACTANTS - RNAP70-CPLX
REACTANTS - PM00675
//
UNIQUE-ID - RP00674
TYPES - RNA-Polymerase-Binding-Reactions
ACTIVATORS - (PD00196 . BS00788)
OFFICIAL-EC? - T
REACTANTS - RNAP70-CPLX
REACTANTS - PM00674
//
UNIQUE-ID - RP00671
TYPES - RNA-Polymerase-Binding-Reactions
ACTIVATORS - (PD00196 . BS00785)
OFFICIAL-EC? - T
REACTANTS - RNAP70-CPLX
REACTANTS - PM00671
//
UNIQUE-ID - RP00669
TYPES - RNA-Polymerase-Binding-Reactions
ACTIVATORS - (PD00196 . BS00783)
OFFICIAL-EC? - T
REACTANTS - RNAP70-CPLX
REACTANTS - PM00669.

So whenever the program finds unique ID RP00671 or RP00669 it has to extract the corresponding reactants(lastline which represents PM00671 or PM00669)

I have written the code but its so confusing to me when it comes to reading the two files and extacting the data.I want to know the exact approach and structure of the program.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the code is very confusing, it's probably because you've written one or a few very large methods. Write short methods, and call them from other methods.

How you structure the program matters a lot, too. For example, if you try to search through the big data file for each entry in the little file, you'll have a fairly confusing program, not to mention a non-object-oriented one.

A better approach would be to define a little class to hold all the data for a single reaction. Then read the entire data file, create a bunch of these objects, and put them into HashMap using the unique-id as the key. Then when you read the other file, looking up the reactants is as simple as calling HashMap.get().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!