http://qs1969.pair.com?node_id=479296

monkfan has asked for the wisdom of the Perl Monks concerning the following question:

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.
Regards,
Edward