string extraction

L

Li Chen

Hi all,

What is the Ruby way to extract a string like this?

old_string="5'-AAAAAAAA CCCCCCCC TTT GGGGG GGGG-3'"
new_string="AAAAAAAACCCCCCCCTTTGGGGGGGGG"


Thank you very much,

Li
 
Y

yermej

Hi all,

What is the Ruby way to extract a string like this?

old_string="5'-AAAAAAAA    CCCCCCCC  TTT   GGGGG    GGGG-3'"
new_string="AAAAAAAACCCCCCCCTTTGGGGGGGGG"

Thank you very much,

Li

new_string = old_string.gsub(/[^A-Z]/, '')

That substitutes '' (empty string) for any character that is not (^) a
capital letter (A-Z).

To do the same thing in place: old_string.gsub!(/^A-Z]/, '')
 
T

Thomas Adam

Hi --

Hi all,

What is the Ruby way to extract a string like this?

old_string="5'-AAAAAAAA CCCCCCCC TTT GGGGG GGGG-3'"
new_string="AAAAAAAACCCCCCCCTTTGGGGGGGGG"

old_string="5'-AAAAAAAA CCCCCCCC TTT GGGGG GGGG-3'".scan(/[A-Z]+/).to_s

And variations thereof.

-- Thomas Adam
 
L

Li Chen

yermej said:
new_string = old_string.gsub(/[^A-Z]/, '')

That substitutes '' (empty string) for any character that is not (^) a
capital letter (A-Z).

To do the same thing in place: old_string.gsub!(/^A-Z]/, '')

Thank you so much.

Li
 
S

Sebastian Hungerecker

Li said:
What is the Ruby way to extract a string like this?

old_string=3D"5'-AAAAAAAA =C2=A0 =C2=A0CCCCCCCC =C2=A0TTT =C2=A0 GGGGG = =C2=A0 =C2=A0GGGG-3'"
new_string=3D"AAAAAAAACCCCCCCCTTTGGGGGGGGG"

new_string =3D old_string.gsub(/[^ACTG]/i,"")

This removes anything that is not an A, C, T or G (case insensitively. If y=
ou=20
want lower case chars acgt to be removed, too, remove the i from the regex).


HTH,
Sebastian
=2D-=20
Jabber: (e-mail address removed)
ICQ: 205544826
 
L

Li Chen

yermej said:
new_string = old_string.gsub(/[^A-Z]/, '')

That substitutes '' (empty string) for any character that is not (^) a
capital letter (A-Z).

To do the same thing in place: old_string.gsub!(/^A-Z]/, '')

Hi yermej,

One more question: How do I change all the As into T and all the Ts into
A in the old sttring?

old_s="AAATTAA"
new_s="TTTAATT"

thanks,

Li
 
S

Sebastian Hungerecker

Li said:
How do I change all the As into T and all the Ts into
A in the old sttring?

old_s="AAATTAA"
new_s="TTTAATT"

new_s = old_s.tr("AT", "TA")
or if you also want GC
new_s = old_s.tr("ATGC", "TACG")
 
J

James Gray

Hi all,

What is the Ruby way to extract a string like this?

old_string="5'-AAAAAAAA CCCCCCCC TTT GGGGG GGGG-3'"

"5'-AAAAAAAA CCCCCCCC TTT GGGGG GGGG-3'".delete("^ACTG")

James Edward Gray II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,275
Messages
2,571,382
Members
48,072
Latest member
FaustoBust

Latest Threads

Top