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

Hello monks, please give me the script for this problem. How can i find the old substrings from file 1 in file 2 and how can i store the new beginnings and endings of the new substrings in file2.. Say you have one file that contains a sequence of letters, eg :
SGFEFHGYARSGVIMNDSGASTKSGAYITPAGETGGAIGRLGNQADTYVEMNLEHKQTLDN [file 1]
the same sequence is also in the [file 2], but, with "." and "-" in it, like:
...---SGFEF....HG-.--YARSGVI---MNDSGAS..--TKSGAY--....--ITPAG--ETGGAI. +.GRLGN--Q..AD---TY--V..EMNL--EHKQTLDN [file 2]
Let's say I want to check how two substrings (namely SGASTK and GNQADT) have become in file 2 compared to what they were in file1. I see that SGASTK, that was substring 19-24 in file1 is now SGAS..--TK and substring 36-41. GNQADT which was substring 42-48 in file1 is now GN--Q..AD---T and substring 76-82. I guess the answer is to turn the substrings you are looking for into regular expressions that accommodate the presence of '-' and '.' between the letters. For example,
#!/usr/local/bin/perl $str = "a-\.*?b-\.*?c"; $str2 = "zzzza---..bcddd +dd"; $str2 =~ /($str)/; print $1,"\n";
The use of the grouped regexp between /.../ allows you to remember the substring that matched the regexp. But i'm not sure with that,can you please give some idea or give me your script if it's possible.

Dec 18, 2025 at 09:15 UTC McDarren Added code tags

Replies are listed 'Best First'.
Re: find the substring
by igelkott (Priest) on Feb 20, 2008 at 16:40 UTC
    Just a guess but if these are protein sequences, you might check BioPerl for a number of handy tools specifically designed for this application.
Re: find the substring
by cdarke (Prior) on Feb 20, 2008 at 16:31 UTC
    Welcome to perlmonks! If you show us the code you have written so far we might be able to help with a specific problem. You can remove hyphens and periods from a string using:
    s/-\.//g;
    and then compare strings using 'eq'.
      I guess the answer is to turn the substrings you are looking for into regular expressions that accommodate the presence of '-' and '.' between the letters. For example,
      #!/usr/local/bin/perl $str = "a[-\.]*?b[-\.]*?c"; $str2 = "zzzza---..bcddddd"; $str2 =~ /($str)/; print $1,"\n";
      The use of the grouped regexp between /.../ allows you to remember the substring that matched the regexp.

      But i'm not sure with that,can you please give some idea or give me your script if it's possible.