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
相关推荐
夜听莺儿鸣10 分钟前
502-002_Linux驱动开发模块化编程
linux·驱动开发·模块化编程
wuminyu1 小时前
C++协程实现接收端的零拷贝Buffer管理原理剖析
java·linux·c语言·jvm·c++
m0_380743871 小时前
C++中的freopen的用法实例详解
开发语言·c++
科力锐品牌君2 小时前
应用级灾备 | 海量非结构化数据如何实现高效数据保护
linux·运维·网络·安全·系统安全·数据安全·灾备
Escalating_xu2 小时前
【Python】基础语法(1):常量、变量、类型、输入输出与运算符
开发语言·python
zhangrelay2 小时前
ROS项目设计案例智能大模型正经乱答案例
linux·笔记·学习·ubuntu·机器人
jimy12 小时前
polymorph.cpp里面的“析构函数、智能指针”问题
开发语言·c++
m0_380743872 小时前
PHP 8.3 缓存清除不生效怎么排查
开发语言·php
朝朝辞暮i2 小时前
C++ 第 6 课:switch —— 多状态选择
开发语言·c++·算法
流浪0012 小时前
Linux系统篇39——线程(四) pthread库的由来和线程的创建与等待
linux·操作系统·线程·pthread库