View Single Post
Old 09-26-2013, 09:47 PM   #2
Location: CA

Join Date: Jul 2013
Posts: 74

Here's one way using Perl. Save the text in a file named (or whatever). Usage would be:

perl --in file_to_change.fasta --out revised_file.fasta


use strict;
use warnings;
use Getopt::Long;

my $inFile;
my $outFile;

GetOptions  ("in=s"      => \$inFile,
             "out=s"      => \$outFile);

if (!$inFile or !$outFile) {
    die "Must supply both infile and outfile as command line arguments.\n";

open(my $inFH, "<", $inFile) or die "couldn't open infile for reading.\n";
if (-e $outFile) {
    die "Output file $outFile already exists--aborting so you don't overwrite.\n";
open(my $outFH, ">", $outFile) or die "couldn't open outfile for writing.\n";
my $counter = 1;
while (my $line = <$inFH>) {
    chomp $line;
    if ($line =~ /^(>.*)/) {
        print $outFH $1 . "_$counter\n";
    } else {
        print $outFH "$line\n";

Last edited by atcghelix; 09-26-2013 at 09:57 PM. Reason: Edited to move $counter++ so that you didn't just get odd-numbered sequences
atcghelix is offline   Reply With Quote