京橋のバイオインフォマティシャンの日常

南国のビーチパラソルの下で、Rプログラムを打ってる日常を求めて、、Daily Life of Bioinformatician in Kyobashi of Osaka

Grep command for string processing (1) Processing of text in a file and other

About grep command

grep command is used in order to retrieve or search for a certain string.

Broadly speaking, the way you do the grep command depends on whether you grep the text in the file or the file name.

It's simple, but it can be applied to many things.

By the following command, you can download the files/folders for practice *1.

#Download
svn export  https://github.com/kumeS/Blog/trunk/grep_practice

#Move to the working folder
cd ./grep_practice

Processing of text in files

Show lines with a certain string

#Display the file
cat test_01.txt

#Output the lines containing 'abc'
grep 'abc' test_01.txt
#OR
grep "abc" test_01.txt
#OR
cat test_01.txt | grep 'abc'

Show lines without the certain string

#Output the lines without 'abc
grep -v 'abc' test_01.txt 
#OR
cat test_01.txt | grep -v "abc"

Output lines without a certain string as an alias file

#Save the lines without 'abc' as 'test_01_v.txt'.
grep -v 'abc' test_01.txt > test_01_v.txt

#Display of test_01_v.txt
cat test_01_v.txt

Option

-v: search for a string that does not contain or does not match

Delete blank lines

#Show the lines without blank lines
cat test_02.txt | grep -v '^\s*$'

#To save as an alias file
cat test_02.txt | grep -v '^\s*$' > test_02_r.txt

Option

^: beginning of line

\s: empty word

^\s*: Zero or more repeated spaces from the beginning of the line.

Count the number of lines in a file

#Counting the total number of lines
cat test_01.txt | grep '' -c

#How not to use grep
cat test_01.txt | wc -l

#Counting only the number of lines containing 'abc'
cat test_01.txt | grep 'abc' -c

Option

-c: Counting lines or stuffs.

Searching for strings with multiple criteria

cat test_02.txt

#AND search
#Showing lines that contain 'AAA' and 'ABB' in the companion
grep 'AAA' test_02.txt | grep 'ABB'
cat test_02.txt

#OR search (-e notation)
#Display lines containing 'AAA' or 'BBB'
grep -e 'AAA' -e 'BBB' test_02.txt

#OR search (regular expression)
#Display lines containing 'AAA' or 'BBB'
grep 'AAA\|BBB' test_02.txt

Option

-e: Specify a search pattern

-w: Search for a pattern match across words

-x: Find a whole line that matches the pattern

-i: It's not case sensitive.

-n: Show line numbers in the search results

Processing of file names

Search for file names with a certain string

#Display of files in the directory
ls

#Display the .txt file only
ls | grep '.txt'

#counting .txt file
ls | grep '.txt' | wc -l

#Display the line, word and byte counts in the file
ls | grep 'test_01.txt' | wc
#OR
wc test_01.txt

Option

-l: Targeting file names

Search including subdirectories

#Counting the number of files containing '.pdf'
ls | grep '.pdf' | wc -l

#Show files including subdirectories
du -a

#Display of files containing '.pdf', including subdirectories
du -a | grep '.pdf'

#Count the number of files, including subdirectories
du -a | grep '.pdf' | wc -l

Search and delete certain files

#Delete files that contain '.pdf' in the current directory
ls | grep '.pdf' | xargs rm -rf

#Delete files containing '.pdf' in the subdirectories
du -a | grep '.pdf' | xargs rm -rf

Here, xargs means the result of the previous command is passed to the next command rm as an argument.

Supplement info

Terminal Shortcuts

Move the cursor
Ctrl + b backward / backward a word
Ctrl + f move forward and one word forward
Ctrl + a move to the beginning of the line
Ctrl + e move to end of line
Delete
Ctrl + w delete a single word or phrase
Ctrl + k delete to end of line
Ctrl + u delete to the beginning of the line
Ctrl + d delete a character in the cursor
Ctrl + h remove one character after the cursor
History
previous command history
next command history
History History
Other
Ctrl + c kill the current command
Ctrl + z pause the running command
Ctrl + d Exit, Logout
Ctrl + l Clear the screen
Ctrl + t change the cursor's character with the previous one
Ctrl + m, Ctrl + j, Ctrl + o Enter

cat : view, merge, and create for file

#Display in the text file (test.txt)
cat test.txt

#Add line numbers and display the file
cat -n test.txt

#Create a combined file from multiple files
cat test1.txt test2.txt > test3.txt

#Create an empty file (press Ctrl + d to exit)
cat > test4.txt

#All history displays, "~ (tilde)" means the home directory
cat ~/.bash_history
#OR
history

head / tail : show the beginning and end of the file

#Display 10 lines from the top of the file.
head -n 10 test.txt

#Display 10 lines from the end of the file
tail -n 10 test.txt

Terminal Commands You Should Remember

#Terminate the system
shutdown -f now
              
#Reboot
reboot

#Give all users execute privileges
chmod a+x test.command

#Executing commands as the Root user
sudo ...

Other Terminal Commands

#Display the date and time
date

#View 2012 Calendar
cal 2020

#Show Active Jobs
jobs

*1:To run the command, delete the "$".

【生命科学とダイエット】低糖質ダイエットを生命科学的にヤルとしたら、どうすれば良いか??

はじめに、低糖質ダイエットとは?

ダイエット法の1つに、低糖質ダイエットあるいは糖質制限ダイエットという方法があります。

要するに、ご飯やパン、芋類などの炭水化物、甘い物などの糖質量を抑え*1その代わりに、肉、魚や豆腐など、高タンパク質、および葉野菜を主食として食べるダイエット法です。

この記事は、巷にある、低糖質・糖質制限ダイエットの話とはちょっと違い、 生命科学者っぽく、それを考察しようと思っています。

糖質を食べると、どうなる?

糖質を食べると、急激に血糖値(血液中の糖濃度)が上がります。 血糖が高い状態が続くのを身体が好まないため、それを抑えるために、膵臓からインスリンというホルモンが放出されます。そのホルモンが、体内への糖の貯蔵を促進し、血糖値を下げる働きをします。

ここでいう、糖は単糖つまりは、それ以上加水分解されない糖類で、ブドウ糖(グルコース)などを指します。

一方、分泌されたインスリンは、脂肪の合成を促進したり、脂肪分解を抑制したりと副次的な働きがあります。

逆に、インスリンが欠乏すると、中性脂肪分解が促進されるらしい*2

その結果として、糖質を食べると、体内の脂肪分解が妨げられる。その逆手を取って、低糖質あるいは糖質制限という話になっています。

本来、体重を減らしたいとなると、身体の脂肪量を減らすわけですよね。

摂取した糖質はどう利用されるか?

米やパン、芋類などに含まれる炭水化物の多くが、直接体内に取り込まれるわけではありません。 ここでいう、炭水化物は主にデンプン(多糖)で、その他にスクロースやラクトースなどのオリゴ糖も含まれます。

ヒトは多数の糖が繋がったデンプンなどを直接吸収できません。デンプンを小さい分子に切り分けないと体内に取り込めません。

図1. 炭水化物の消化酵素

例えば、デンプンは、唾液や膵液に含まれる糖質分解酵素であるアミラーゼ、小腸で分泌される消化酵素であるマルターゼによって、グルコース(単糖)まで分解されます。また、スクロース(ショ糖)やラクトース(乳糖)は腸液に含まれる消化酵素で分解されます。このように、糖類は小さく分解されて、腸管の毛細血管より体内に吸収される。

マルターゼは、α-グルコシダーゼと呼ばれる

マルターゼは小腸粘膜の上皮細胞膜に存在して、マルトースからグルコース2分子への消化とその吸収(膜消化)を担います。また、マルターゼは、酵素化学的な分類上、α-グルコシダーゼとも呼ばれます*3

図2. マルターゼの触媒反応

マルターゼは、マルトースが持つ、α-1,4-グルコシド結合を加水分解することから、α-グルコシダーゼの1つと位置付けられます。

これを踏まえると、マルターゼの働きを抑えると、マルトースの消化が進まず、その結果、体内にマルトース由来のグルコースが吸収されない(膜消化が起こらない)と考えられます。

もう少し詳しく言うと、食事で炭水化物を摂取しても、 マルターゼを含むα-グルコシダーゼがうまく働かないと、 そもそも食べたデンプン質が体の中で分解されない、利用されないことになります。

炭水化物が腸内で分解されず、また吸収もされずで、結果として血糖値が上がらない・上昇し難いと言えます*4

何がターゲットになりそうかという考えると、低糖質をミミックするには、 図1のアミラーゼやグルコシダーゼの働きを阻害してあげれば良いということになりますね。

薬剤化合物の探索とα-グルコシダーゼの阻害剤について

生命科学で薬剤探索とかをかじったことがある方々であれば、ここで、もう一つの課題が浮かぶはずです。

デンプンや糖質の分解酵素は、水溶性物質を基質として触媒反応を行なっています。これら分解酵素の働きを阻害するとなれば、同じく水溶性の性質をもつ化合物で、かつその酵素活性を阻害する働きのあるものということになります。

水溶性の化合物を、有機溶媒系で化学合成するのはかなり難しいです。

だいたい、水溶性化合物は、天然物化学の分野になります。 植物が造る化合物か、カビやバクテリアなどの微生物から抽出した化合物かという具合に、自然界から探索することになります。

未知のものを生物から探すというテーマは、夢がいっぱい、困難いっぱいという感じですね。 困難を乗り越え、それで新薬のタネが見つかれば、スターでしょうね。

前置きはこのくらいにして、実際、アミラーゼやグルコシダーゼの働きを阻害する、自然界の化合物があります。その化学物質の1つが、「アカルボース」というやつです。

アカルボースについて

図3. アカルボースの化学構造

アカルボースは、1970年代に放線菌から単離された、四糖からなる化合物です。

面白いことは、アカルボースは、α-アミラーゼやマルターゼといった、複数の酵素の活性を抑えることができることでしょう。

図4.アカルボースの作用機序

このアカルボースを食事前に摂取すれば、多糖類の分解に関わる酵素群の働きを抑えてくれます。 その間に、炭水化物を摂取しても、その分解の低下、体内への取り込み低下となり、 結果として、血糖の上昇が抑えられて、低糖質ダイエットと類似する効果が得られます。

じゃあ、放線菌をすり潰して、飲めば良いのかということになりますが。。。

アカルボースが多く含まれる、香辛料があるという研究報告があり、例えば、オールスパイス、シナモン、タイム、パセリとかに多く含まれています。

あと、世の中うまくできたもので、そもそも、薬として売られています。

編集後記

デンプン分解を抑えると思いもよらない、副作用があることも分かっています。

それは、まさかのオナラの回数が増加することです。

デンプン質の分解が小腸であまり進まず、そのまま大腸まで行ってしまうと、そこで余分な発酵が進んでしまい、腸内でガスが溜まってしまうということです。それがオナラとして放出されます。う^ん、この副作用は歓迎できませんね。

一方で、この腸内での発酵にはポジティブな効果があるともされています。

ガスの一部には、水素ガスが含まれていて、それが血中に溶けるようです。水素ガスは、身体のサビ付きを防ぐ、抗酸化効果があることが知られています。

以前に、Nature Medicine に報告された研究で、 「水素ガスを吸入すると、酸化ストレスの影響を緩衝して、虚血・再灌流時の脳損傷を顕著に抑える」みたいな報告がありました。

また、 scientific reportsでの研究報告では、「水素水を摂取した健康人で、炎症反応を抑制し、末梢血細胞のアポトーシスが抑制される」という報告もあるようです。

オナラが増えて、水素も増えるとは、生命科学は奥が深いですね。

*1:1日の糖質を60g以下に抑えるのが理想らしい

*2:http://www3.fctv.ne.jp/~judo/gakujyutu/jyouhou/energy/tani/innsurinn.html#:~:text=%E7%B3%96%E5%B0%BF%E7%97%85%E3%81%A7%E3%80%81%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%AA%E3%83%B3%E3%81%8C%E6%AC%A0%E4%B9%8F,%E4%BD%93%E9%87%8D%E3%81%AF%E6%B8%9B%E5%B0%91%E3%81%97%E3%81%BE%E3%81%99%E3%80%82

*3:グルコシダーゼは、グルコ結合 + 加水分解(シダーゼ)に由来する

*4:実際は、食事中に単糖も含まれるので、血糖値が上がらないというのはないのかもしれませんが。。。

R言語で核酸配列データを扱ってみた件【その2: FASTAフォーマット・ファイルの読み込み】

はじめに

Rを用いた、DNA配列データの基本的な処理の方法を概説します。

今回は、seqinrあるいはBiostringsパッケージを用いて FASTA形式のファイルを読み込んで、DNA配列データとして扱ってみます。

配列データを元にして、相補配列を作成します。

seqinrパッケージのインストール

まずは、Rを起動して、seqinrパッケージをセットアップします。

#インストール
install.packages("seqinr")

#ロード
library(seqinr)

Biostringsパッケージのインストール

次に、Biostringsパッケージをセットアップします。

#インストール
install.packages("BiocManager")
BiocManager::install("Biostrings")

#ロード
library(Biostrings)

seqinr::read.fastaを使って、HIV-1 全ゲノムのFASTAファイルの読み込み場合

Human immunodeficiency virus 1 の全ゲノム(NC_001802.1)の FASTAファイルを用意します。そのFASTAファイル(DNA配列)を読み込みます。

HIV-1 (ヒト免疫不全ウイルス-1) の全ゲノム RefSeq

FASTA形式とは、核酸配列やアミノ酸配列を記述するためのデータ形式のひとつです。

この形式では、「>」で始まる行に配列の名前を記載して、次の行以降に配列情報を示した形式です。 「>」で始まる行を複数設定することで、1つのFASTAファイル内に、複数の配列情報を列挙できます。

seqinr::read.fastaを使って、FASTAを「ベクトル」として読み込む

#「ベクトル」として読み込む
HIV <- seqinr::read.fasta("https://gist.githubusercontent.com/kumeS/aead5195f323560ab906aff290f51b3f/raw/dedf6599d4c57abc9924c8fa19a2a06c3295cb54/HIV1.fasta")

str(HIV)
#List of 1
# $ NC_001802.1: 'SeqFastadna' chr [1:9181] "g" "g" "t" "c" ...
#  ..- attr(*, "name")= chr "NC_001802.1"
#  ..- attr(*, "Annot")= chr ">NC_001802.1 Human immunodeficiency virus 1, complete genome"
  
#文字列に変換
HIVs <- seqinr::c2s(HIV$NC_001802.1)

str(HIVs)
# chr "ggtctctctggttagaccagatctgagcctgggagctctctggctaactagggaacccactgcttaagcctcaataaagcttgccttgagtgctt#caagtagtgtgtgccc"| __truncated__

seqinr::read.fastaを使って、FASTAを「文字列」として読み込む

#「文字列」として読み込む
HIV_str <- seqinr::read.fasta("https://gist.githubusercontent.com/kumeS/aead5195f323560ab906aff290f51b3f/raw/dedf6599d4c57abc9924c8fa19a2a06c3295cb54/HIV1.fasta", as.string=TRUE)

str(HIV_str)
#List of 1
# $ NC_001802.1: 'SeqFastadna' chr #"ggtctctctggttagaccagatctgagcctgggagctctctggctaactagggaacccactgcttaagcctcaataaagcttgccttgagtgcttcaagt#agtgtgtgccc"| __truncated__
#  ..- attr(*, "name")= chr "NC_001802.1"
#  ..- attr(*, "Annot")= chr ">NC_001802.1 Human immunodeficiency virus 1, complete genome"

#ベクトルに変換
HIVc <- seqinr::s2c(HIV_str$NC_001802.1)

str(HIVc)
#chr [1:9181] "g" "g" "t" "c" "t" "c" "t" "c" "t" "g" "g" ...

読み込んだ配列データから相補配列を求める配列データ処理の基本

#ベクトル部分の取り出し
HIVseq <- HIV$NC_001802.1

#相補配列の結果を返す
HIVcomp <- seqinr::comp(HIVseq, forceToLower = FALSE)

#headで表示
head(HIVseq, n=10)
#[1] "g" "g" "t" "c" "t" "c" "t" "c" "t" "g"

head(HIVcomp, n=10)
#[1] "c" "c" "a" "g" "a" "g" "a" "g" "a" "c"

Biostrings::readDNAStringSetを使って、HIV-1 全ゲノムのFASTAファイルの読み込み場合

Biostringsパッケージでは、FASTAファイル(DNA配列)の読み込みには、readDNAStringSet関数を用います。

#FASTAファイルの読み込み
HIV_bio <- Biostrings::readDNAStringSet(filepath="https://gist.githubusercontent.com/kumeS/aead5195f323560ab906aff290f51b3f/raw/dedf6599d4c57abc9924c8fa19a2a06c3295cb54/HIV1.fasta",
                 format="fasta")

HIV_bio
#DNAStringSet object of length 1:
#    width seq                            names               
#[1]  9181 GGTCTCTCTGGTTA...CCTTGAGTGCTTC NC_001802.1 Human...

#相補配列を求める
Biostrings::complement(HIV_bio)
#DNAStringSet object of length 1:
#    width seq                            names               
#[1]  9181 CCAGAGAGACCAAT...GGAACTCACGAAG NC_001802.1 Human...

DNAStringSetでの出力結果

HIV-1 (ヒト免疫不全ウイルス-1) の全ゲノム RefSeq

gist.github.com