-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_ATGC_content.pl
38 lines (33 loc) · 1.07 KB
/
get_ATGC_content.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
#perl calculate_base_content.pl 染色体.fasta
#
#!/usr/bin/perl
use strict;
use warnings;
# 获取FASTA文件路径
my $file = shift @ARGV;
die "未指定FASTA文件。请提供文件路径作为参数。\n" unless defined $file;
die "无法打开文件 '$file':$!\n" unless -e $file;
# 读取FASTA文件
open(my $fh, '<', $file) or die "无法打开文件 '$file':$!";
my $current_sequence = '';
while (my $line = <$fh>) {
chomp $line;
if ($line =~ /^>/) {
# 忽略注释行
next;
} else {
$current_sequence .= $line;
}
}
close $fh;
# 计算碱基含量
my $total_length = length($current_sequence);
my $a_count = ($current_sequence =~ tr/Aa//);
my $t_count = ($current_sequence =~ tr/Tt//);
my $c_count = ($current_sequence =~ tr/Cc//);
my $g_count = ($current_sequence =~ tr/Gg//);
# 输出结果
print "A含量: " . ($a_count / $total_length) * 100 . "%\n";
print "T含量: " . ($t_count / $total_length) * 100 . "%\n";
print "C含量: " . ($c_count / $total_length) * 100 . "%\n";
print "G含量: " . ($g_count / $total_length) * 100 . "%\n";