perl语言——length.pl脚本(统计fasta文件序列长度)

Perl脚本------stat.pl(统计fasta文件序列长度)

相比Perl语言,现在python用的多。但是perl依旧是生信学习的一门课程,还是有人在写,所以你至少要会读。

perl 复制代码
#!/use/bin/perl			#perl解析器

$inputFile = $ARGV[0];       #输入文件:fasta
$outputDir = $ARGV[1];       #输出目录

if (@ARGV<2) {
	print "inputfile and outputdir are required!\n";
	exit 1;
}

open(DATA,"$inputFile") or die("Could not open file!!!");
#获取fasta文件名
@input = split(/\//,$inputFile); @fastaname = split(/\./,$input[-1]);
#生成输出文件名
$outputFile = join ("/", $outputDir, join("_", $fastaname[0], "length.txt"));
open(RESULT,">$outputFile");

my%hash,$read;
foreach $line (<DATA>) {
	chomp($line);
	if($line =~ /^>/){  #判断是序列名称行
		$read = $line;
		$hash{$read} = 0;
	}else{
		$hash{$read} += length($line);
	}
}

my$Total_read = 0,$Total_length = 0;
foreach $k(keys %hash){
	$Total_length = $Total_length+$hash{$k};
	$Total_read = $Total_read+1;
}
print "Total_read:\t$Total_read\nTotal_length:\t$Total_length\n";
print RESULT "Total_read:\t$Total_read\nTotal_length:\t$Total_length\n";
close(DATA);close(RESULT);

上面是我经常书写的perl文件的格式,当然有些不标准,仅供参阅。

perl执行问题总结

问题一

Can't locate Cegma.pm in @INC (you may need to install the Cegma module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at ./cegma line 34.

这是perl模块没有在系统配置中,用perl -V查看。如果是下载的软件,这个文件会在lib/目录下,配置环境变量即可

对于perl模块问题,另一篇博文https://blog.csdn.net/weixin_44616693/article/details/125160834,可以查看

  1. List item
相关推荐
软件开发技术局29 分钟前
撕碎QT面具(8):对控件采用自动增加函数(转到槽)的方式,发现函数不能被调用的解决方案
开发语言·qt
csbDD1 小时前
2025年网络安全(黑客技术)三个月自学手册
linux·网络·python·安全·web安全
周杰伦fans2 小时前
C#中修饰符
开发语言·c#
yngsqq2 小时前
c# —— StringBuilder 类
java·开发语言
赔罪2 小时前
Python 高级特性-切片
开发语言·python
Natsuagin3 小时前
轻松美化双系统启动界面与同步时间设置(Windows + Ubuntu)
linux·windows·ubuntu·grub
易基因科技3 小时前
易基因: ChIP-seq+DRIP-seq揭示AMPK通过调控H3K4me3沉积和R-loop形成以维持基因组稳定性和生殖细胞完整性|NAR
经验分享·数据挖掘·生物学·生物信息学
子豪-中国机器人3 小时前
2月17日c语言框架
c语言·开发语言
我们的五年3 小时前
【Linux网络编程】应用层协议HTTP(请求方法,状态码,重定向,cookie,session)
linux·网络·http
夏天的阳光吖3 小时前
C++蓝桥杯基础篇(四)
开发语言·c++·蓝桥杯