设为首页 收藏本站
查看: 564|回复: 0

[经验分享] Mac Unix & Perl

[复制链接]

尚未签到

发表于 2015-12-26 11:40:33 | 显示全部楼层 |阅读模式

  • On a Mac, plugged in drives appear as subdirectories in the special 'Volumes' directory.
  • cd ~ and cd achieve the same thing: go to home directory (/Users/whatever)
  • ls -l (L): list, the long version. ls -a: list all file(include hidden one).
  • Space view next page, b view previous page,q to quit. j scroll down a line, k scroll up a line.(man man). h to bring up a help page.
  • rm: remove file; rm -i *.txt: ask for confirmation before deleting; rmdir: remove a directory(empty), mkdir: generate a directory. mkdir -p Temp1/Temp2
  • touch: to create a new, empty file. eg: touch heaven.txt.
  • mv: move files. mv heaven.txt Temp/
  • wildcard: ? caracterizing a single character, and * means everything that matches.
  • cp: copy file. the default behavior of copy is to overwrite. cp -R Storage Storage1: copy directory.
  • less: to view text files, not edit.
  • ls -l: add a letter d to specify that it is a directory. ls -p use trailing slash.
  • $ alias ls='ls -p' make ls equals ls -p. Aliases only exist in the current terminal session.
  • nano profile: create a text editor file named profile. write into it and save(Ctrl + O):


    # some useful command line short-cuts
    alias ls='ls -p'
    alias rm='rm -i'



  • $ source profile

      to tell Unix to read the contents of a file and treat it as a series of Unix commands

  • to show hidden files on mac:

    • defaults write com.apple.finder AppleShowAllFiles 1

  • turn off hidden files on mac: ("killall finder" to see effect)

    • defaults write com.apple.finder AppleShowAllFiles 0

  • Type: source /Volumes/USB/Unix_and_Perl_course/.profile each time when you open terminal.

  • grep: search for matched lines, -v to invert. -i to ignore case. -c to count.



  • $ grep "ATGTGA" intro_IME_data.fasta | less
    $ grep -i ACGTC * | head                   #show first 10 lines of matched item
    $ head -n 1 chr1.fasta | sed 's/Chr1/Chromosome 1/'   # head -n 1 means the first line. sed to substitute.
      concept of pipe. then press "/" to search some kind of pattern say "ATGTGA", "?" to search backward



  • wc At_genes.gff; wc -l At_genes.gff: wc count lines, words, bytes, -l count only lines.



  • #!/usr/bin/perl
    # scalar.pl by Wade
    use warnings;
    $x = 3;
    print($x,"\n");

      the first line tell us that we can type: $ scalar.pl instead of $ perl scalar.pl.

  • Any text between single quotes will print exactly as shown: print '$x $s\n'  #=> $x $s\n
  • if we turen on strict: use strict; it becomes mandatory to say whether the variable is a local or global variable.




    • my $pi = 3.14;

        my: means this is a local variable.


  • eq (equal to); ne (not equal to); gt (greater than); lt (less than); . (concatenation); cmp (comparison);
  • print $x == $y ? "yes\n" : "no\n";
  • method, length(); ord() : convert to number; chr() : convert to letters;
  • =~ m// equals =~ // : matching; != // : not matching; =~ s/// : substitution(the first met) =~ s///g(global); =~ tr/// : transliteration;



  • die "non-DNA character in input\n" if ($input =~ /[efijlopqxz]/i);

      die ... if syntax : to stop perl if necessary.




  • $sequence =~ tr/A-Z/a-z/;
    push @animals, "fox";
    my $length = @animals;
    my @gene_names = qw(unc-10 cyc-1 act-1 let-7 dyf-2);
    my $joined_names = join(", ", @gene_names);
    my @digest = split("", $dna);  # split at every possible position at $dna (string);

    •   If you assign a list to a scalar variable, then the scalar variable becomes the length of the list.

  • difference between :

    • $length = @animals;    # variable $length means the size of the array;
    • ($length) = @animals; # list ($length) contains one element of array @animals;

  • Array:




    • pop(@array); shift(@array); push(@array, "element"); unshift(@array, "element"); splice();
    • scalar(@array) : function that calculate the length of the array;
    • index at 1.2, 1.7, .. rounded to 2.  -1 means count from tail.




  • @sorted_list = sort{$a <=> $b or uc($a) cmp uc($b)} @list;
  • foreach $animal (@animals) {print "$animal\n"}
  • for my $i (0..5) {print "$i\n"}
  • 0 ""(null string) be considered false.
  • next redo last => continue, redo, break;
  • while(<>) equals while($_ = <>). chomp() function removes a \n character from the end of a line if present.



  • #!/usr/bin/perl
    # filemunge.pl
    use strict; use warnings;
    open(IN, "<$ARGV[0]") or die "error reading $ARGV[0] for reading";
    open(OUT, ">$ARGV[0].munge") or die "error creating $ARGV[0].munge";
    while(<IN>) {
    chomp;
    my $rev = reverse $_;
    print OUT "$rev\n";
    }
    close IN;
    close OUT:
  • how to do I/Os: http://www.ualberta.ca/~hquamen/303/filehandles.html ; $! to store error messages. select handle. Perl now allows you to use a regular scalar as a filehandle.
  • reverse() function both reverse arrays and strings.



  • #hash
    %genetic_code = (
    ATG => 'Met';
    AAA => 'Lys';
    CCA => 'Pro';        
    );
    foreach $key (keys %genetic_code) {
    print "$key $genetic_code{key}\n";   
    }
    if (exists $genetic_code{AAA}) {print "AAA codon has a value\n"}
    else                         {print "No values set for AAA codon\n"}
    delete $genetic_code{AAA};
      The keys() function returns an array of keys, function values() returns an array of values.

  • sort function: http://perldoc.perl.org/functions/sort.html
  • varible $&: The string matched by the last successful pattern match.
  • uc(), lc() function: make string uppercase or lowercase:


    my $str = "What is Perl Language for";
    lc($str);
    print $str, "\n";
    # displays: What is Perl Language for
    $str = lc($str);
    print $str, "\n";
    # displays: what is perl language for
  • \s matches whitespaces \S matches non-whitespaces. "=~ m/[^ATGC]/i" (negated character class)



  • if($text =~ m/A{1,3}/) {...} # matches between 1 and 3 As
    if($text =~ m/C{42}/) {...} # matches exactly 42 Cs
    if($text =~ m/T{6,}/) {...} # matches at least 6 Ts
    # to match a "." you have to use backslash "\." eg. $sequence =~ m/A\. thaliana/ {...}
    my @fields = split; # \s+ or $_ are assumed, and space-delimited
  • Regular expressions in list context return values from parenthesized patterns: my ($beg, $end) = $line =~ /(\d+)\.\.(\d+)/;
  • file handler can only be processed one at a time. "If your inner loop is a filehandle iterator, then you will need to reset it."
  • f
  • f
  • f
  • f
  • f


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-156515-1-1.html 上篇帖子: LWP(Library for web acccess in perl) 下篇帖子: Perl多进程
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表