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

On Jan 10, 2:38 pm, Li Chen [email protected] 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 –

On 10/01/2008, Li Chen [email protected] 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 A.

yermej wrote:

On Jan 10, 2:38?pm, Li Chen [email protected] 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

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

yermej wrote:

On Jan 10, 2:38?pm, Li Chen [email protected] 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

Sebastian H. 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

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’”

“5’-AAAAAAAA CCCCCCCC TTT GGGGG GGGG-3’”.delete("^ACTG")

James Edward G. II

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