SlideShare a Scribd company logo
1 of 78
2017.10.18
Bio Shell Trick
with Answers
#バイオシェル芸 でツイートされた解答を掲載しました
掲載してほしくない方や、解答が漏れているという方は@emi_2shedsまでご連絡ください
スクリーンショットにマウスポインタが映り込んでいる場合がありますが、それもきわどいところに
映り込んでコマンドを隠している場合すらありますが、手作業の味ということでご容赦ください
(修正しません)
解答をグループ分けしようと試みましたが最初の二問で力尽きました(誰かお願いします)
ツイートされた解答について、当方では実行確認していません
解答者に質問するか、#バイオシェル芸 でつぶやいてみてください
Thank you
(研究者がみんな
「魔法」を使えるようにしたい...)
(でもその都度教える余裕はない...)
バイオインフォでありがちな処理を
あらかじめ書いておいて
困っている人にここ見てね、と言える
サイトをGithubで作成中です
https://bio-shell.github.io/dailybiocommands/
• 共同編集大歓迎です
• もしくは、Qiitaで「バイオシェル芸」タグで
記事を書いてくだされば見つけて勝手に
リンクさせていただきます
今日のみなさまのコマンドも掲載予定
1問あたり10~20分くらいで進めます
司会から問題発表→各自 #バイオシェル芸 #問題 でTweet
→わいわいする
GNUコマンド以外に、PerlやRuby、R等のワンライナーもOK
バイオの解析の役に立ちそうならなんでもあり
Rules
git clone https://github.com/bio-shell/study1.git
or
docker run -it --rm emihat/bioshellenv
Are you ready ?
Test data
- ゴリラをチキンにする
- コイは大変
- Homo以外は帰ってくれないか
- 拡張子ゲシュタルト崩壊
- リンダCommaっちゃう
Today’s menu
- 歩く屍
- BEDで煙草は吸わないで
- 13日の金曜日
- SAMってほんとユニーク
- 5秒後に消えます
問題の投稿ありがとうございました!
テストデータの関係で採用を見送った問題があります(ごめんなさい)
ゴリラを
チキンにする
Presented by
emi_2sheds
Gorilla gorillaという文字列をGallus gallusに変換してください
丸ごと置換する 以外で
× echo "Gorilla gorilla" | sed -e 's/Gorilla gorilla/Gallus gallus/’
達人は sedを使わない で
ゴリラをチキンにする
#バイオシェル芸
#ゴリラチキン
Example Answer of #ゴリラチキン
echo "Gorilla gorilla" | sed -e 's/orilla/allus/g'
sedを使わない例:
echo "Gorilla gorilla" | awk '{gsub("orilla","allus")}'
まずはsedで・1
まずはsedで・2
gsub, tr
シェルの置換
vim芸
いろいろな言語で
echoのことは忘れた
コイは大変
Presented by
匿名希望
鯉(Cyprinus carpio)の染色体はchr1-50, MT, Unです
koiというディレクトリを作り、その下に以下52個の
ディレクトリを作ってください
chr1, chr2, …, chr50, chrMT, chrUn
コイは大変
#バイオシェル芸
#コイ
for i in {1..50} MT Un; do mkdir –p koi/chr$i; done
Example Answer of #コイ
ブレース展開
郡山市が気になります
seq
Python芸、JS芸
ぷるさんの問題は #バイオシェル芸 #JSシェル芸 で!
Homo以外は
帰ってくれないか
Presented by
匿名希望
merge-test-c.vcfからジェノタイプが「ALTのHomo(1/1)」
かつInsertionの行だけ抜き出してください
https://github.com/bio-shell/study1/blob/master/data/merge-
test-c.vcf
Homo以外は帰ってくれないか
#バイオシェル芸
#Homo
次ページでもう少し説明
merge-test-c.vcf
- vcftools 0.1.13ソースコードのexamplesに入っているVCFファイル
- VCFフォーマットの説明は https://samtools.github.io/hts-specs/VCFv4.2.pdf
REF(4列目)の塩基数<ALT(5列目)塩基数
かつ
#で始まる
行は無視
最終列に1/1が含まれる行だけ
#バイオシェル芸
#Homo
awk -F"¥t|," '$0!~/^#/ && (length($4) < length($5) ||
(length($4) < length($6) && $6~/^[A-Z]+$/)) &&
$(NF)~/1¥/1/' merge-test-c.vcf
Example Answer of #Homo
死?!
ことねさん無双
拡張子
ゲシュタルト崩壊
Presented by
emi_2sheds
GTH.tar.gz を解凍し、GTHフォルダ内のファイル名を
次のルールで変更してください
- 拡張子が.fa、.mfa、.fas、fasta →拡張子.faに統一
- 拡張子が.fq、.fastq →拡張子.fqに統一
- ファイル名が重複した場合は上書き
https://github.com/bio-shell/study1/blob/master/data/GTH.tar.gz
拡張子ゲシュタルト崩壊
#バイオシェル芸
#拡張子
tar xzvf GTH.tar.gz; cd GTH; rename s/.fastq$/.fq/ *;
rename -f s/.m?fas?t?a?$/.fa/ *
bash on windowsの実行例です
Coreutils on macOS Sierraではrenameが無いようなのでbrewで入れてください
renameコマンドは環境により仕様が異なります
‐fオプションが無い場合(emihat/bioshellenv等)はつけるとエラーになります
Example Answer of #拡張子
リンダCommaっちゃう
Presented by
emi_2sheds
linda.txtはlinda属の虫について学名や命名者名を記載した
コンマ区切りテキストです
Binomial name(9列目)だけを抜き出してください
https://github.com/bio-shell/study1/blob/master/data/linda.txt
リンダCommaっちゃう
次ページでもう少し説明
#バイオシェル芸
#Comma
linda.txt
学名などが書かれたコンマ区切りテキスト
Family(6列目)とGenus(8列目)の間に
変な列が入ってしまっています
Binomial name(後ろから2列目)
だけ抜き出す
#で始まる行は無視
#バイオシェル芸
#Comma
awk -F"," '$1!~/^#/{print $(NF-1)}' linda.txt
Example Answer of #Comma
息をするようにコマンドを吐く創始者
Presented by
匿名希望
歩
く
屍
exp_survivor.txt, exp_walker.txtは生存者とゾンビの遺伝子
発現データです(※仮想データ)
2ファイルをマージして、遺伝子名、生存者の発現量、ゾンビ
の発現量の3列を出力してください
値がないところは-で埋めてください
歩く屍
#バイオシェル芸
#歩く屍
次ページでもう少し説明
exp_survivor.txt, exp_walker.txt
遺伝子名と発現量の2列からなるタブ区切りテキスト
GeneA 1.1
GeneB
29.1
GeneC 0.3
GeneE 4.2
GeneF 3.9
exp_survivor.txt
GeneA 0.1
GeneB 0.1
GeneD
500.6
GeneE 4.2
GeneG
34.7
exp_walker.txt
GeneA 1.1 0.1
GeneB 29.1 0.1
GeneC 0.3 -
GeneD - 500.6
GeneE 4.2 4.2
GeneF 3.9 -
GeneG - 34.7
+ →
#バイオシェル芸
#歩く屍
join -a 1 -a 2 -o 0 1.2 2.2 -e '-'
exp_survivor.txt exp_walker.txt
Example Answer of #歩く屍
Coreutils on macOS Sierraでは –o 0,1.2,2.2 のようにコンマ区切りにしないとエラーになるようです
BEDで煙草は
吸わないで
Presented by
emi_2sheds
tommo_EGFR.txtのうちAlt頻度(9列目)が0.9以上の行を
BED3フォーマットに変換してください
https://github.com/bio-
shell/study1/blob/master/data/tommo_EGFR.txt
BEDで煙草は吸わないで
次ページでもう少し説明
#バイオシェル芸
#BED
BED format
BEDフォーマットの説明は
https://genome.ucsc.edu/FAQ/FAQformat.html#format1
次の3列からなるフォーマット
(BED3の場合)
1. 染色体番号
2. スタート位置(0スタート)
3. エンド位置
#バイオシェル芸
#BED
tommo_EGFR.txt
tommo_EGFR.txt は東北メディカルメガバンクv1の頻度5%以上のSNV
(https://humandbs.biosciencedbc.jp/files/hum0015/hum0015.v1.freq.v
1.zip)からEGFR遺伝子の変異行のみを抜き出したファイルです
使用したデータの一部はバイオシェル芸勉強会主催者によって取得され、科学技術振興機構(JST)の「バイオサイエンスデータベースセンター
(NBDC)」ウェブサイト(http://biosciencedbc.jp/)を通じて提供されたものです
Chromosome(1列目)、Position(2列目)-1、Position(2列目)を出力
1行目は
無視
9列目が0.9以上の行だけ
#バイオシェル芸
#BED
awk -F"¥t" '$9>=0.9{print $1"¥t"$2-1"¥t"$2}'
tommo_EGFR.txt
Example Answer of #BED
13日の
金曜日
Presented by
emi_2sheds
fridayThe13th.jsonからaccession, symbol, definitionを抜き
出しタブ区切りで出力してください
https://github.com/bio-
shell/study1/blob/master/data/fridayThe13th.json
13日の金曜日
次ページでもう少し説明
#バイオシェル芸
#JSON
JSON format
JSONフォーマットの説明は http://www.json.org/
「JSONの例」by IBM
https://www.ibm.com/support/knowledg
ecenter/ja/SS9H2Y_7.1.0/com.ibm.dp.do
c/json_jsonexamples.html
#バイオシェル芸
#JSON
fridayThe13th.json
GGRNAを“thirteen” and “fri”で検索した結果をJSONで出力したファイルです
http://ggrna.dbcls.jp/hs/thirteen+fri.json
{"error":"none","results":[{"aa_position":[19],"accession":"NM_001303620","definition":"Homo sapiens deoxyribonuclease
1 like 1 (DNASE1L1), transcript variant 5,
mRNA.","division":"RefSeq","geneid":"1774","gi":"","length":"2649","nt_position":[],"snippet":"NP_001290549.1¥"
/db_xref=¥"CCDS:CCDS14747.1¥" /db_xref=¥"GeneID:1774¥" /db_xref=¥"HGNC:HGNC:2957¥" /db_xref=¥"MIM:300081¥"
/translation=¥"MHYPTALLFLILANGAQAFRICAFNAQRLTLAKVAREQVMDTLVRILARCDIMVLQEVVDSSGSAIPLLLRELNRFDGSGPYSTLSSPQLGRSTYMETYVYFYR
SHKTQVLSSYVYNDEDDVFAREPFVAQFSLPSNVLPSLVLVPLHTTPKAVEKELNALYDVFLEVSQH...R, Ciccodicola A, Chen CN, Zuo L, Heiner C,
Burough F, Repetto M, Schlessinger D and D'Urso M. TITLE Long-range sequence analysis in Xq28: thirteen known and six
candidate genes in 219.4 kb of high GC DNA between the RCP/GCP and G6PD loci JOURNAL Hum. Mol. Genet. 5 (5), 659-668
(1996) PUBMED...","source":"Homo sapiens (human)","symbol":"DNASE1L1","synonym":"DNAS1L1; DNASEX; DNL1L; G4.8;
XIB","version":"NM_001303620.1"},{"aa_position":[19],"accession":"NM_001009934","definition":"Homo sapiens
deoxyribonuclease 1 like 1 (DNASE1L1), transcript variant 4,
mRNA.","division":"RefSeq","geneid":"1774","gi":"","length":"2683","nt_position":[],"snippet":"NP_001009934.1¥"
/db_xref=¥"CCDS:CCDS14747.1¥" /db_xref=¥"GeneID:1774¥" /db_xref=¥"HGNC:HGNC:2957¥" /db_xref=¥"MIM:300081¥"
/translation=¥"MHYPTALLFLILANGAQAFRICAFNAQRLTLAKVAREQVMDTLVRILARCDIMVLQEVVDSSGSAIPLLLRELNRFDGSGPYSTLSSPQLGRSTYMETYVYFYR
SHKTQVLSSYVYNDEDDVFAREPFVAQFSLPSNVLPSLVLVPLHTTPKAVEKELNALYDVFLEVSQH...R, Ciccodicola A, Chen CN, Zuo L, Heiner C,
Burough F, Repetto M, Schlessinger D and D'Urso M. TITLE Long-range sequence analysis in Xq28: thirteen known and six
candidate genes in 219.4 kb of high GC DNA between the RCP/GCP and G6PD loci JOURNAL Hum. Mol. Genet. 5 (5), 659-668
(1996) PUBMED...","source":"Homo sapiens (human)","symbol":"DNASE1L1","synonym":"DNAS1L1; DNASEX; DNL1L; G4.8
~後略
jq -r '.results[] |
[.accession,.symbol,.definition] | @csv'
fridayThe13th.json | sed -e 's/"//g'
GGRNAはタブ区切りでも出力できます! http://ggrna.dbcls.jp/hs/thirteen+fri.txt 今回はタブ区切りで出すほうが早いですね
jq1.4.1以降なら @tsv が使えて以下のように書けます
jq -r '.results[] | [.accession,.symbol,.definition] | @tsv'
fridayThe13th.json
Example Answer of #JSON
SAMって
ほんとユニーク
Presented by
caripso
test_input_1_a.sam からunmappedとマルチヒットを取り除い
たSAMファイルを作ってください
https://github.com/bio-
shell/study1/blob/master/data/test_input_1_a.sam
Samtoolsを使ってもOK
SAMってほんとユニーク
次ページでもう少し説明
#バイオシェル芸
#SAM
test_input_1_a.sam
samtools 1.5ソースコードのtest/dat/に入っているSAMファイル
SAMフォーマットの説明は https://samtools.github.io/hts-specs/SAMv1.pdf
QNAME(1列目)の
ファイル全体での登場数が
ジャスト2回のQNAMEの行を出力
FLAG(2列目)が0の行は無視
@で始まる行は無視
簡易ルールです
やれる方は厳密にやってください
#バイオシェル芸
#SAM
awk -F"¥t" '$0!~/^@/ && awk -F"¥t" '$0!~/^@/ &&
$2>0{lines[$1]=lines[$1]$0"¥n";cnt[$1]+=1} END {for(q
in lines){if(cnt[q]==2) print lines[q]}}'
test_input_1_a.sam | grep -v '^¥s*$'
samtoolsを使う例:
samtools view -S -f 2 test_input_1_a.sam
今回のデータで動く例です
sam/bamのFLAGやMAPQの
仕様はソフトにより異なります
Example Answer of #SAM
5秒後に
消えます
Presented by
emi_2sheds
「This message will self-destruct in five seconds.」と
画面に出力した後、5秒後に画面からそのメッセージを
消してください
5秒後に消えます
#バイオシェル芸
#5秒後
echo 'This message will self-destruct in five
seconds.'; sleep 5; clear; history -c
Example Answer of #5秒後に消えます
history -cでコマンド履歴が全部消えますので消したくない方はclearで止めてください
Bio Shell
Trick
or Treat!
AND

More Related Content

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

バイオシェル芸 解答つき