jeudi 12 février 2015

Want to add random string to identifier line in fasta file

I want to add random string to existing identifier line in fasta file. So I get:



MMETSP0259|AmphidiniumcarteCMP1314aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa


Then the sequence on the next lines as normal. I am have problem with i think in the format output. This is what I get:



MMETSP0259|AmphidiniumCMP1314aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
CTTCATCGCACATGGATAACTGTGTACCTGACTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab
TCTGGGAAAGGTTGCTATCATGAGTCATAGAATaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac


It's added to every line. (I altered length to fit here.) I want just to add to the identifier line.


This is what i have so far:



use strict;
use warnings;
my $currentId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

my $header_line;
my $seq;
my $uniqueID;

open (my $fh,"$ARGV[0]") or die "Failed to open file: $!\n";
open (my $out_fh, ">$ARGV[0]_longer_ID_MMETSP.fasta");

while( <$fh> ){
if ($_ =~ m/^(\S+)\s+(.*)/) {
$header_line = $1;
$seq = $2;
$uniqueID = $currentId++;
print $out_fh "$header_line$uniqueID\n$seq";
} # if
} # while

close $fh;
close $out_fh;


Thanks very much, any ideas will be greatly appreciated.





Aucun commentaire:

Enregistrer un commentaire