I did a script in Perl that breaks several sequences of a multifasta file, but I need remove a part of string of header.
For example:
input file:
>gi|983431797|ref|NZ_LN868938.1| Nocardia farcinica genome assembly NCTC11134, chromosome : 1
CTGACTGGGAGTACGAAGGCCGCCTGCACAAGACAACGGGGCAGCGAACCTTCTTCTGCACCGGCACGGA
CGACGCCGAGATGCCTCGACCTGGAGAACCTCGGCCGCGGCGAACCGCTCGCCCATGTCCGCGCCGAGTT
Output file:
>Nocardia farcinica genome assembly NCTC11134, chromosome : 1
CTGACTGGGAGTACGAAGGCCGCCTGCACAAGACAACGGGGCAGCGAACCTTCTTCTGCACCGGCACGGA
CGACGCCGAGATGCCTCGACCTGGAGAACCTCGGCCGCGGCGAACCGCTCGCCCATGTCCGCGCCGAGTT
I've done everything, but I can't think of a solution to this.
Can someone help me?
My script:
#!/usr/bin/perl
use strict;
use warnings;
use IO::File;
my $file = "\nFILE: perl $0 <Fasta>"."\n";
print $file and exit unless($ARGV[0]);
my $input = IO::File->new("$ARGV[0]"), my $output;
while(my $line = $input->getline){
chomp($line);
if($line =~ /^>/){
$line =~ s/^>//;
$output = IO::File->new("> $line.fa");
print $output ">".$line."\n";
}else{
print $output $line."\n";
}
}
close($input);
close($output);
For example:
input file:
>gi|983431797|ref|NZ_LN868938.1| Nocardia farcinica genome assembly NCTC11134, chromosome : 1
CTGACTGGGAGTACGAAGGCCGCCTGCACAAGACAACGGGGCAGCGAACCTTCTTCTGCACCGGCACGGA
CGACGCCGAGATGCCTCGACCTGGAGAACCTCGGCCGCGGCGAACCGCTCGCCCATGTCCGCGCCGAGTT
Output file:
>Nocardia farcinica genome assembly NCTC11134, chromosome : 1
CTGACTGGGAGTACGAAGGCCGCCTGCACAAGACAACGGGGCAGCGAACCTTCTTCTGCACCGGCACGGA
CGACGCCGAGATGCCTCGACCTGGAGAACCTCGGCCGCGGCGAACCGCTCGCCCATGTCCGCGCCGAGTT
I've done everything, but I can't think of a solution to this.
Can someone help me?
My script:
#!/usr/bin/perl
use strict;
use warnings;
use IO::File;
my $file = "\nFILE: perl $0 <Fasta>"."\n";
print $file and exit unless($ARGV[0]);
my $input = IO::File->new("$ARGV[0]"), my $output;
while(my $line = $input->getline){
chomp($line);
if($line =~ /^>/){
$line =~ s/^>//;
$output = IO::File->new("> $line.fa");
print $output ">".$line."\n";
}else{
print $output $line."\n";
}
}
close($input);
close($output);
Comment