-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretrieve_sequence_names.pl
53 lines (38 loc) · 1006 Bytes
/
retrieve_sequence_names.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
47
48
49
50
51
52
53
#!/usr/bin/env perl
# Retrieves sequence names from fasta file.
# Usage:
# perl retrieve_sequence_names.pl [fasta file path]
# Prints to console. To print to file, use
# perl retrieve_sequence_names.pl [fasta file path] > [output file path]
use strict;
use warnings;
my $fasta_file = $ARGV[0];
my $NEWLINE = "\n";
# verifies that fasta file exists and is non-empty
if(!$fasta_file)
{
print STDERR "Error: no input fasta file provided. Exiting.\n";
die;
}
if(!-e $fasta_file)
{
print STDERR "Error: input fasta file does not exist:\n\t".$fasta_file."\nExiting.\n";
die;
}
if(-z $fasta_file)
{
print STDERR "Error: input fasta file is empty:\n\t".$fasta_file."\nExiting.\n";
die;
}
# reads in fasta file and retrieves sequence names
open FASTA_FILE, "<$fasta_file" || die "Could not open $fasta_file to read; terminating =(\n";
while(<FASTA_FILE>) # for each line in the file
{
chomp;
if($_ =~ /^>(.*)$/) # header line
{
print $1.$NEWLINE;
}
}
close FASTA_FILE;
# February 3, 2025