Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8327657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:11:19+00:00 2026-06-09T01:11:19+00:00

In a perl script, I need to replace several strings. At the moment, I

  • 0

In a perl script, I need to replace several strings. At the moment, I use:

$fasta =~ s/\>[^_]+_([^\/]+)[^\n]+/\>$1/g;

The aim is to format in a FASTA file every sequence name. It works well in my case so I don’t need to touch this part. However, it happens that a sequence name appears several times in the file. I must not have at the end twice – or more – the same sequence name. I thus need to have for instance:

seqName1
seqName2
etc.

(instead of seqName, seqName, etc.)

Is this possible to somehow process differently every occurrence automatically? I don’t know how many sequence there are, if there are similar names, etc. An idea would be to concatenate a random string at every occurrence for instance, hence my question.

Many thanks.


John perfectly solved it and chepner helped with the smart idea to avoid conflicts, here is the final result:

$fasta =~ s/\>[^_]+_([^\/]+)[^\n]+/
    sub {
        return '>'.$1.$i++;
    }->();
/eg;

Many many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:11:22+00:00Added an answer on June 9, 2026 at 1:11 am

    I was actually trying to do something like this the other day, here’s what I came up with

    $fasta =~ s/\>[^_]+_([^\/]+)[^\n]+/
    
        sub {
    
            # return random string
    
        }->();
    
    /eg;
    

    the \e modifier interprets the substitution as code, not text. I use an anonymous code ref so that I can return at any point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a Perl script to spawn itself with an arbitrary name, i.e. so
I am writing a script in perl where I use forking and I need
I need to construct a file path inside a Perl script. Which path separator
I need a perl/shell script which will replace all the occurences of below HTML
I need to call a Perl script from a PHP file, and I've gotten
I need to run Perl script by cron periodically (~every 3-5 minutes). I want
I need to write a Perl script to read in a file, and delete
I need to write a Perl script that pipes input into a Java program.
I need to test a perl script in a remote server. I tried running
I want to (need to) start a sub-process from a perl script that checks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.