求解释代码

软件和网站开发以及相关技术探讨
回复
youbatu
帖子: 9
注册时间: 2011-11-02 15:47

求解释代码

#1

帖子 youbatu » 2011-11-06 18:56

我是刚搞生物信息的 什么都不懂 这是一段将.seq转化为.fasta的代码 有好心人帮我解释下吗?我地一句就看不懂了 @ARGV ,谢谢各位了
#! /usr/bin/perl

#function: transfer *.seq to *.fasta, and combine them.

#usage: perl ptransfer <input folder's pathway> <output filename>

#time: 2011-11-04



use strict;

use warnings;

if(@ARGV != 2){

print "warning!$!\nusage:perl ptransfer <input folder's pathway> <output filename> ";

}

my($dir,$out)=@ARGV;

open(OUT,">$out");

opendir(DH,"$dir");

my(@total,$i);

$i=0;

foreach (readdir DH){

$total[$i]=$_;

$i++;

}

closedir DH;

my($num,);

$num=0;

foreach(@total){

my($filename);

$filename=$_;

open(OR,"$dir/$filename");

$filename=substr($filename,0,-4);

while(<OR>){

my($line);

$line=$_;

chomp($line);

if($line=~/^[ATCG][ATCG]/i){

$line=uc($line);

print OUT ">$filename\n$line\n";

$num++;

}

}

close OR;

}

close OUT;

print "$num\nall done!\n";
头像
cuihao
帖子: 4793
注册时间: 2008-07-24 11:33
来自: 郑州
联系:

Re: 求解释代码

#2

帖子 cuihao » 2011-11-06 19:20

虽然不会perl,但强烈建议LZ加缩进。

代码: 全选

[code]代码
[/code]
求人不如求它仨: 天蓝的Wiki 屎黄的Wiki 绿
Site: CUIHAO.TK    Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
头像
ChenFengyuan
帖子: 770
注册时间: 2008-03-23 0:39

Re: 求解释代码

#3

帖子 ChenFengyuan » 2011-11-07 15:44

看到在用perl很高兴。

ARGV The special filehandle that iterates over command-line filenames in @ARGV. Usually written as the
null filehandle in the angle operator "<>". Note that currently "ARGV" only has its magical
effect within the "<>" operator; elsewhere it is just a plain filehandle corresponding to the
last file opened by "<>". In particular, passing "\*ARGV" as a parameter to a function that
expects a filehandle may not cause your function to automatically read the contents of all the
files in @ARGV.
头像
tangboyun
帖子: 701
注册时间: 2009-07-25 1:57
联系:

Re: 求解释代码

#4

帖子 tangboyun » 2011-11-15 21:20

这段代码我如果没弄错的话,应该是将序列转为大写,然后计数序列数的,一般.seq就是fasta格式的。而fasta也并不强制大小写规范。

不过这代码写的很那啥,对输入做了太多假设。因为fasta格式只保证序列头一定是在一行内并以回车结束的,但并没有保证序列数据本身一定是在一行的。具体可以参考Fasta格式的Wiki页。一般数序列,还是直接计数'>'或者'#'起始的行数比较有保证的。

另:刚入行的话,推荐两本《Beginning Perl For Bioinformatics》《Learning Perl》
https://github.com/tangboyun
http://tangboyun.is-programmer.com/
提问的智慧————Eric Steven Raymond
回答的智慧————Andrew Clarke
吾尝终日而思矣,不如须臾之所学也;吾尝跂而望矣,不如登高之博见也。
急急急标题什么的,最讨厌了!
急急复急急,急急何其多,我生待急急,万事急急急。
头像
xw_y_am
帖子: 3333
注册时间: 2009-05-08 14:18
系统: Arch
来自: 河南新乡
联系:

Re: 求解释代码

#5

帖子 xw_y_am » 2011-11-15 22:50

ee大神何在???
Linux 相关链接大杂烩

代码: 全选

if(read) {
    if(practise) return g☘☘d;
    else return w☘☘d;
} else {
    return t☘☘d;
}
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 求解释代码

#6

帖子 eexpress » 2011-11-16 10:04

学术的,找 ChenFengyuan

我只实用主义。你要啥功能,如果适合的,我写出来。
● 鸣学
xiaoyafeng
帖子: 56
注册时间: 2009-10-13 22:58

Re: 求解释代码

#7

帖子 xiaoyafeng » 2011-11-16 14:42

这是谁写的? 写得也太烂了吧?
回复