Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I want to check my thought process

 
Corbin Blake
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still working on my DNA sequencing project (i am further along thank goodness) but now, i want to check my thought process.

Okay, i have to write a new method public void addEdge(int i, int k)
that creates an edge sequence between vertex j and k.

What these need to do is take the watson-crick compliment of the last half of j concatenated with the watson-crick of the first half of k. So it looks kind of like this:
sequence
ATTATAAACCA
watson-crick edge compliment
TGGTTTATAAT

here is my thought process
1. take the initial sequence array and divide it by 2
2. then go through the first half and change the compliments
3. then do the same with the second half and concantenate them together

so it would look like
[code]
for(int i = 0; i < seqArray.length/2; i++){
base = rand.nextInt(4);
if(base==0)
tube+="T";
else if(base==1)
tube+="A";
else if(base==2)
tube+="C";
else if(base==3)
tube+="G";
for(int j = seqArray.length/2; j < seqArray.length; j++){
base = rand.nextInt(4);
if(base==0)
tube+="T";
else if(base==1)
tube+="A";
else if(base==2)
tube+="C";
else if(base==3)
tube+="G";
}
new Sequence(tube)= seqArray[i] + seqArray[j];

What do you think? am i on the right track?

}
 
Barry Higgins
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you elaborate more on what the watson-crick compliment is?
 
Corbin Blake
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Watson-Crick is a DNA base compliment, basically, i have to convert a dna sequence:

such as: ATTAGACAT
then change the A's with T's and the G's with C's
such as: TAATCTGTA <---this is the watson-crick compliment of the first Sequence

after that, i have to take the first half of the sequence and switch it with the second half.

such as: CTGTATAAT or i guess, print it in reverse

but i can't figure out how to get started on that part.
 
Elouise Kivineva
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would create a string and use the replace method to change the 'A' and 'G's. String substring methods would also be useful here.

You can always convert from a string to a char array and back again.
 
Matt Fielder
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Elouise Kivineva:
I would create a string and use the replace method to change the 'A' and 'G's. String substring methods would also be useful here.

You can always convert from a string to a char array and back again.


replace would be dangerous though. if you change 'A' to 'G' you now have to change the original 'G' to 'A'. you would end up with only 2 of the original 4 variables.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a switch statement might be best...



In the above code, the method watsonCrickComp takes a String argument and returns the compliment String. It does this by examining one char at a time in the input String, making the exchange by calling the compliment method (which is just the switch statement), then appending the result to a StringBuffer.

(If you're using a char Array instead of a String, then so much the better: Just apply the compliment method to each element of the Array.)

Note that integer division always truncates, so if you have an odd number of elements, then you need to consider which half you want the "odd" element in when using something like "String.length()/2".
[ November 19, 2004: Message edited by: marc weber ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps a HashMap with the compliment pairs would be helpful. You can use a protein as a key and its compliment as the coresponding value. If you do this, then a for loop with a single assignment would do the trick:

As you can see, there are several approaches to this problem. In deciding which solution to use, you should weigh the advantages and disadvantages. In this case, the advantage, imho, is very concise and elegant code. The disadvantage is the price of initializing the HashMap as well as the time cost of getValue(). I believe the later is O(1), or in otherwords, no matter how big the HashMap grows, it can look up a value in the same amount of time. However, you should check the HashMap javadocs to be certain of this.

Layne
 
Elouise Kivineva
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

replace would be dangerous though. if you change 'A' to 'G' you now have to change the original 'G' to 'A'. you would end up with only 2 of the original 4 variables.


By changing 'A' s and 'G's I mean that the 'A' in string1 are replaced by 'T's in string 2 and the 'G's in string 1 are replaced by 'C's in string 2.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic