バイオシェル芸のためのPerlワンライナー

7cf213f4930be5a6a21edae1674bcb36?s=47 ktnyt
October 18, 2017
900

 バイオシェル芸のためのPerlワンライナー

「本物」のワンライナーを書こう。

7cf213f4930be5a6a21edae1674bcb36?s=128

ktnyt

October 18, 2017
Tweet

Transcript

  1. όΠΦγΣϧܳͷͨΊͷ PerlϫϯϥΠφʔ @kotone_nyt

  2. ࣗݾ঺հ ࣾձෆద߹ऀΩϟϯύεʹि̍Ͱ௨͍ͬͯΔ ͦͷੲόΠΦܥͷιϑτ΢ΣΞΛ։ൃͯͨ͠ ΞΠυϧϚελʔγϯσϨϥΨʔϧζΛѪ͢Δ υϫϯΰਓ޻஌ೳݚڀॴͷόΠτ ͜ͱ @kotone_nyt

  3. ΤΠϦΞεΛషΔ͚ͩͰ͍͍͔ΒҠ২ੑ͕ߴ͍ ίϐϖ͢Δ͚ͩͰ࢖͑ΔͷͰಋೖͷোน͕௿͍ ϓϩάϥϜΛҰߦͰهड़͢ΔͷͰݟ௨͕͠ྑ͍ ϝϦοτ ͋ͱָ͍͠ʂʂʂ✌('ω' ✌)ࡾ✌('ω')✌ࡾ(✌ 'ω')✌

  4. One Line FASTQ Filter

  5. $ cat test.fastq | perl -MList::Util -lne '$d[($.-1)/4]->[($.-1)%4]=$_}{print join("\n",map{join("\n",@{$_})} grep{List::Util::sum(map{ord($_)-33}split(//,$_-

    >[3]))>2000}@d)' > filtered.fastq FASTQ Filter ίʔυࣗମ͸ͨͬͨͷ129όΠτʂ
  6. $ cat test.fastq | perl -MList::Util -lne '$d[($.-1)/4]->[($.-1)%4]=$_}{ print join("\n",

    map{join("\n",@{$_})} grep{ List::Util::sum( map{ ord($_)-33 }split(//,$_->[3]) )>2000 }@d )' > filtered.fastq FASTQ Filter
  7. $ cat test.fastq | perl -MList::Util -lne '$d[($.-1)/4]->[($.-1)%4]=$_}{ print join("\n",

    map{join("\n",@{$_})} grep{ List::Util::sum( map{ ord($_)-33 }split(//,$_->[3]) )>2000 }@d )' > filtered.fastq FASTQ Filter
  8. ֤छϑϥά ϑϥά ػೳ -e ϫϯϥΠφʔϞʔυ -l print ڧ੍վߦ -n ෳ਺ߦॲཧ

    -a AWKϞʔυ -p ෳ਺ߦ+print -MModule use Module; https://qiita.com/tossh/items/f8d448c0c039f68c0ea3
  9. $ cat test.fastq | perl -MList::Util -lne '$d[($.-1)/4]->[($.-1)%4]=$_}{ print join("\n",

    map{join("\n",@{$_})} grep{ List::Util::sum( map{ ord($_)-33 }split(//,$_->[3]) )>2000 }@d )' > filtered.fastq FASTQ Filter
  10. $. Perlͷ҉໧ม਺ͷ͏ͪͷҰͭ ߦ൪߸͕֨ೲ͞Ε͍ͯΔ 0Ͱ͸ͳ͘1ΠϯσΫεͳͷͰ஫ҙ

  11. $ cat test.fastq | perl -MList::Util -lne '$d[($.-1)/4]->[($.-1)%4]=$_}{ print join("\n",

    map{join("\n",@{$_})} grep{ List::Util::sum( map{ ord($_)-33 }split(//,$_->[3]) )>2000 }@d )' > filtered.fastq FASTQ Filter
  12. }{ ͍ΘΏΔൿີԋࢉࢠͷҰͭ ϫϯϥΠφʔʹENDϒϩοΫΛ௥Ճ͢Δԋࢉࢠ ϑΝΠϧΛॲཧͯ͠࠷ޙʹprintΈ͍ͨͳࣄ͕Ͱ͖Δ

  13. $ cat test.fastq | perl -MList::Util -lne '$d[($.-1)/4]->[($.-1)%4]=$_}{ print join("\n",

    map{join("\n",@{$_})} grep{ List::Util::sum( map{ ord($_)-33 }split(//,$_->[3]) )>2000 }@d )' > filtered.fastq FASTQ Filter
  14. ·ͱΊ • ͜ΕͬͯPerlܳ͡Όͳ͍ʁ • ·͊ɺͦ͏Ͱ͢Ͷ... • ͩ͜ΘΓΛ࣋ͭͱָ͍͠ • ηϛίϩϯΛ࢖Θͳ͍ͱ͔ •

    grep/map/subΛ͏·͘࢖͍·͠ΐ͏
  15. ͓·͚ɿॏෳͷౕ $ cat hoge | tr -dc a-z | perl

    -le 'sub{map{print}split(//,shift)}->(<>)' | uniq -c | sort -nr | head -n 1 7 a
  16. ͓·͚ɿFASTQੜ੒ $ seq 10 | perl -lne 'print join("\n", (sprintf("\@seq%03d",$.),join("",map{qw(a

    t g c) [rand(4)]}0..99),sprintf("\+seq%03d", $.),join("",map{chr(rand(41)+33)}0..99)))'
  17. ͓·͚ɿST*P while("STAP"ne$s){print$s=join("",map{qw(S T A P)[4*rand]}0..3),"\n"}print"ཅੑ͔͘ʹΜ! Α͔ ͬͨˑ\n"