union of 1 and 0 strings

A

avilella

Hi,

Question:

I have two strings:

DB<32> x $seqchoice
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 '
DB<33> x $outgroup
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 '

and I want to make the "union" of the "ones" in $outgroup to
$seqchoice, so that I end up with:

DB<32> x $seqchoice
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 0 '
DB<33> x $outgroup
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 '

notice the "1" in the penultimate position in $seqchoice.

Any ideas of a regexp that would do for me?
 
M

Michele Dondi

DB<32> x $seqchoice
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 '
DB<33> x $outgroup
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 '

and I want to make the "union" of the "ones" in $outgroup to
$seqchoice, so that I end up with:

DB<32> x $seqchoice
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 0 '
DB<33> x $outgroup
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 '

notice the "1" in the penultimate position in $seqchoice.

Many, many ways to do so. For one thing, spaces are kinda of a PITA.
You may want to get rid of them by splitting into arrays and process
them. Though, I would still go with strings, possibly getting rid of
spaces and using stringwise logical operators and then possibly
massaging back the resulting string:


#/usr/bin/perl

use strict;
use warnings;

my $seqchoice = '000000000000000011111111111111111100';
my $outgroup = '000000000000000000000000000000000010';

local $\="\n";
print for $seqchoice, $outgroup => $seqchoice | $outgroup;

__END__

000000000000000011111111111111111100
000000000000000000000000000000000010
000000000000000011111111111111111110


Michele
 
J

John W. Krahn

I have two strings:

DB<32> x $seqchoice
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 '
DB<33> x $outgroup
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 '

and I want to make the "union" of the "ones" in $outgroup to
$seqchoice, so that I end up with:

DB<32> x $seqchoice
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 0 '
DB<33> x $outgroup
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 '

notice the "1" in the penultimate position in $seqchoice.

Any ideas of a regexp that would do for me?

No need for a regexp:

$ perl -le'
$seqchoice = q[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 0 0 ];
$outgroup = q[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 ];
print $seqchoice | $outgroup;
'
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0


Is a string the best data structure for your needs?

perldoc -f vec



John
 

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
473,769
Messages
2,569,582
Members
45,068
Latest member
MakersCBDIngredients

Latest Threads

Top