-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrenamefasta.pl
executable file
·46 lines (39 loc) · 1.14 KB
/
renamefasta.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/perl
####################
# renamefasta.pl - given command line arg of sequence file in format id tab sequence
# outputs in fasta format, renaming the annotation lines.
# By Madelaine Gogol
# 6/2007
####################
use strict;
my ($new_annotation,$filename,$contents,@lines,$label,$id,$sequence);
$filename = $ARGV[0];
$new_annotation = $ARGV[1];
$contents = get_file_data($filename);
@lines = split(/\n/,$contents);
$label = 1;
foreach my $line (@lines)
{
($id,$sequence) = split(/\t/,$line);
print ">$new_annotation".$label."\n$sequence\n";
$label = $label+1;
}
######################################################
# subroutine get_file_data
# arguments: filename
# purpose: gets data from file given filename;
# returns file contents
######################################################
sub get_file_data
{
my($filename) = @_;
my @filedata = ();
unless( open(GET_FILE_DATA, $filename))
{
print STDERR "Cannot open file \"$filename\": $!\n\n";
exit;
}
@filedata = <GET_FILE_DATA>;
close GET_FILE_DATA;
return join('',@filedata);
}