String extraction

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

···

--
Posted via http://www.ruby-forum.com/.

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]/, '')

···

On Jan 10, 2:38 pm, Li Chen <chen_...@yahoo.com> wrote:

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
--
Posted viahttp://www.ruby-forum.com/.

Hi --

···

On 10/01/2008, Li Chen <chen_li3@yahoo.com> wrote:

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

Li Chen wrote:

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

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

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

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

HTH,
Sebastian

···

--
Jabber: sepp2k@jabber.org
ICQ: 205544826

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

James Edward Gray II

···

On Jan 10, 2008, at 2:38 PM, Li Chen wrote:

Hi all,

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

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

yermej wrote:

···

On Jan 10, 2:38?pm, Li Chen <chen_...@yahoo.com> wrote:

--
Posted viahttp://www.ruby-forum.com/.

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
--
Posted via http://www.ruby-forum.com/\.

yermej wrote:

--
Posted viahttp://www.ruby-forum.com/.

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

···

On Jan 10, 2:38?pm, Li Chen <chen_...@yahoo.com> wrote:

--
Posted via http://www.ruby-forum.com/\.

Li Chen wrote:

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")

···

--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Sebastian Hungerecker wrote:

Li Chen wrote:

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")

Thank you very much,

Li

···

--
Posted via http://www.ruby-forum.com/\.