Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Identifying Overlapping Area in a Set of Strings by monkfan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-18 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found