I'm trying to read in a list of strings of characters A, C, G,and T (ignoring case), and to ignore the rest of the string if it contains any other character.
how do I code this? do I use indexOf?
V new to Java yes. Not trolling just need help quickly.
Name:
Anonymous2013-04-27 0:46
Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?
Mail me at jeremiahgoldstein@hotmail.com
25$ a pop
Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?
Mail me at jeremiahgoldstein@hotmail.com
25$ a pop
Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?
Alright, so you need to filter out from the list those strings which have characters other than TGAC? What you do to see if a string is 'good' is to iterate over the indexes of its characters, and see with charAt if one isn't equal any of those characters. In other words
boolean isGood(String str) {
for (int i = 0; i < str.length(); i++) {
if ("CGAT".indexOf(str.charAt(i)) < 0) { // look up the return values of indexOf
return false;
}
}
return true;
}
That just tells you if the string is acceptable, the rest is up to you.
Name:
Anonymous2013-04-27 1:45
>>3
Horrible. That code is kind of like your mom. Slow and ugly.
def ACGTread(str: String) : String = {
val p = Pattern.compile("[aAcCgGtT]")
val m = p.matcher(str)
var s = ""
while(m.find()) s += m.group()
return s
}
Otherwise, as in "stop cold on the first non-ACGT character" then substitute filter with take-while. Feeding this code to Java is an exercise for the reader.
Name:
Anonymous2013-04-27 6:46
>>1
That post is written by something that is so stupid, if I took its tiny brain and rolled it down the edge of a razor blade, it would be like a lone car going down a six lane highway. Clearly, you spend way too much time in darkened rooms in front of your seven-year-old computer turning a whiter shade of pale. Go outside once in a while and breathe, before your brain starts to rot from all that festering stagnation and cognitive dysfunction.
Here's a tip: no one will ever know that you've had a lobotomy if you wear a wig to hide to the scars; stop posting your drivel on message boards, and learn to control the slobbering. I understand what you are trying to say, even though you obviously don't. Have you ever noticed that whenever you sit behind a keyboard, some idiot starts typing? To quote Martin Luther King, Jr.: "Nothing in the world is more dangerous than a sincere ignorance and conscientious stupidity."
You have that certain nothing. Truly, you are about as interesting as watching a slug move slowly across a large rock. You are nastier than a five-dollar whore getting a shit enema. You're a waste of time, space, air, flesh, and the rectum you were born from, retard. Maybe you wouldn't come across as such a jellyfish-sucking mental midget if you weren't an 'idiot savant' without the 'savant' part; if your weren't so fat that when you run, you make the CD player skip at the radio station, or if you didn't have a face so ugly that Peeping Toms break into your house and close the blinds. Who am I kidding? You would.
Please try to have some small idea of what in the hell you're talking about before you try to post again.
Don't you prog-ramers realize that the original poster (OP) wrote as follows:
"I'm trying to read in a list of strings of characters A, C, G,and T"
Duh! Could it be that he (or she) OP is referring to:
A -- Adenine;
C -- Cytosine;
G -- Guanine;
T -- Thymine? As in http://en.wikipedia.org/wiki/ACGT
which describes the amino-acid building-blocks of DNA?
>>8
Eh? The op is already starting to get brain damage by being subjected Java. Adding an additional boolean test only hastens the brain damage. Seriously. With that, here is what I came up with...
>>22
Depends what he means by "ignore the rest of the string". Could be that there's a comment at the end of line.
Name:
Anonymous2013-04-27 12:06
Here OP, all you have to do is convert to equivalent Java code:
int valid(char *str) {
for(; *str; *str++) {
switch(*str) {
case 'a': case 'A':
case 'c': case 'C':
case 'g': case 'G':
case 't': case 'T':
break;
default:
return(0);
}
}
>>1
Use a switch statement and a StringBuilder to build the result string -- it's faster. public class YouSuck {
public static String readACGT(String in) {
StringBuilder out = new StringBuilder();
for (int i=0; i < in.length(); i++) {
char chr = in.charAt(i);
switch (chr) {
case 'a': case 'A':
case 'c': case 'C':
case 'g': case 'G':
case 't': case 'T':
out.append(chr);
}
}
return out.toString();
}
>>26
I just had something similar for my class so I knew the answer XD
Name:
Anonymous2013-04-27 17:02
>>26
Well because any Java programming question basically reduces down to some remedial programming problem. Yup, just add some objects and classes to a simple problem, and watch the newbie programmer get confused!
Name:
Anonymous2013-04-27 17:05
And whoever on here said that having some Java Programming experience doesn't count as real programming experience is 100% correct!