Hi,
Given a full string ($fseq) and its set of substrings (@$nsub).
And @$nsub always comes (extracted) from $fseq.Although they may or may not be the 'complete' substrings.
I wish to identify the overlapping region of the given set
of substrings and replace them with '-' (as shown with $result variable - the intended result). To be precise, I want to remove the overlapping region
of
two subsequent strings in the set (@$nsub).
I really have no idea how can I approach this problem.
I have aligned manually the substring set (@$nsub) to show
how they are overlapping, as well as the alignment of
the desired result after removing the overlapping area.
I hope the examples are clear.
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $fseq = 'CCCCGCGC';
my $nsub = ['CCCCG',
'CCCGC',
'CGCGC', ];
my $result =['C----', # this is not a parameter but
'----C', # intended result obtained with Dumper
'---GC' ];
my @result = remove_overlap($fseq,$nsub);
print Dumper \@result;
# I'm not so sure how to approach
# this problem with the subroutine below
sub remove_overlap
{
my ($fseq,$nsub) = @_;
my @result;
my $slen = length $nsub->[0];
foreach (@{$nsub})
{
# ????
my $pos = index($fseq,$_);
print "$pos\n";
}
return @result;
}
#---------- The other instances of the problem
#---------- with the intended $result
my $fseq2 = 'CGTGGCGC';
my $nsub2 = [ 'GTGGC',
'TGGCG'];
my $result2 =[ 'G----', # intended result
'----G'];
my $fseq3 = 'CCGCGCTC';
my $nsub3 = [ 'CCGCG',
'CGCGC',
'GCGCT',
'CGCTC'];
my $result3 = ['C----', # intended result
'----C',
'----T',
'----C'];
# No overlapping case
my $fseq4 = 'AAGCTATA';
my $nsub4 = [ 'AAGC',
'TATA'];
my $result4 = ['AAGC','TATA']; # intended result
Thanks so much beforehand.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.