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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.