aspose file tools*
The moose likes Beginning Java and the fly likes I want to check my thought process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I want to check my thought process" Watch "I want to check my thought process" New topic
Author

I want to check my thought process

Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
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?

}


I hope you know your paying me for this!
Barry Higgins
Ranch Hand

Joined: Jun 05, 2003
Posts: 89
Can you elaborate more on what the watson-crick compliment is?
Corbin Blake
Greenhorn

Joined: Nov 10, 2004
Posts: 22
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

Joined: Feb 07, 2002
Posts: 154
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

Joined: Oct 27, 2004
Posts: 158
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

Joined: Aug 31, 2004
Posts: 11343

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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I want to check my thought process