2021年5月7日金曜日

References of Ubuntu 20.04 Installation

Description 

Ubuntuマシンを使いたくなり、久しぶりにLinuxのクリーンインストールを実施した。手法の詳細は様々な情報があるので、差し当たり自分が使用した情報のreferenceを覚書として記録した。


References

ubuntu.jp

  1. https://www.ubuntulinux.jp

ブートUSB作成(Mac)

  1. https://sy-base.com/myrobotics/mac/ubuntu_bootusb/

ubuntu 日本語Remixダウンロードサイト

  1. https://www.ubuntulinux.jp/download

インストール情報

  1. https://linuxfan.info/ubuntu-20-04-install-guide#google_vignette

日本語入力変換

  1. https://linuxfan.info/ubuntu-18-04-japanese-input

解像度問題〜NVIDIA gpu  driver更新

  1. https://ayatansnl.hatenablog.com/entry/2016/03/02/190055
  2. https://zenn.dev/190ikp/articles/how_to_install_nvidia_drivers
  3. https://qiita.com/kenji-miyake/items/06b8c3807bef0ba5c451#nvidia-driver-のインストール
  4. https://hibiki-press.tech/dev-env/ubuntu/add-ppa/4640
  5. https://qiita.com/ksasaki/items/b20a785e1a0f610efa08
  6. https://k-hyoda.hatenablog.com/entry/2020/07/09/223907
  7. https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-20-04-focal-fossa-linux

IPアドレス確認

  1. https://news.mynavi.jp/article/20190825-883094/

SSHインストールと接続

  1. https://codechacha.com/ja/ubuntu-install-openssh/
HDD, SSDマウント確認
  1. アプリケーション:「ディスク」で確認できる。マウントポイントも見れる。ここでマウントポイントの書き換えも可能らしい
  2. コマンドラインで見るときはfdiskで確認できる
  3. sudo disk -l
  4. ファイルシステムの確認は、lsblk -f
  5. マウントポイントは/media/<my_dir>/<UUID>になっていた。UUIDが長いので、この「ディスク」アプリケーションを使って書き換えることもできそう。

解析用プログラム、アプリケーション準備
  1. Atom
  2. Anaconda3 (Jupyter, Spyder)
  3. R
  4. RStudio
  5. R package各種






2020年7月18日土曜日

次世代加速器の記事 (雑感)

昨年度読んだSFでとても面白かったのが、中国のSF作家劉慈欣が書いた「三体」だった。三体は三部作で、第一作の三体 I は前評判も高く新聞の広告とかにも結構大きく載っていたので興味を持って読んでみたが、とても面白いSFだった。現在は第二部の翻訳が6月に出たところだ。第一部を読み終わった時点では日本語訳はまだ出ていなかったので、英語翻訳版 (The dark forest) を購入して春先くらいに読んだ。一部目に続いて壮大なスケールで展開されるお話だった。今は、第三部(Death's end) を暇を見つけて読んでいる。第二部の日本語翻訳版も読んでみたい。

三体のストーリーの中で、「人類の科学の進歩」が重要なキーワードになっている。その中でも「人類の基礎科学のレベルが上がること」を危惧した三体星人により、量子物理学で使われる加速器の結果をでたらめにして無効化してしまう「智子(sophon)」が地球に送り込まれる。作品では、物理学などの基礎科学が文明の発展にいかに重要か、それをめぐる地球人と三体人との攻防が描かれている。なんとなく中国の人たちの科学感や期待が感じられるような気がする設定だと思った。

科学技術レベルが国の覇権にとって重要なのは確かだ。そして、現実世界では基礎科学でも欧米や日本が中国にいづれ追い付かれ追い越されていくであろうことを予感させるような話が出てきている。

先端科学 中国先行に危惧
欧米「日本で次世代加速器建設を」 8000億円、日本は負担懸念
日本経済新聞 朝刊

生命科学の分野でも日本は中国に急速に追い上げられ、一部ではすでに劣後しつつあるのではないかと思う。もちろん基礎科学は文化的な側面もあり、これまで培われてきた欧米の科学研究の風土がなくなってしまうわけではないと思う。しかし、あらゆる分野で覇権を握ろうという意思があり、予算的なバックアップをしている中国に、今後はいろんな分野で追いつき追い越されていくのかもしれない。

日本で科学技術に関係した職についており、日本の科学研究の上での地位が低下していくことに、危機感と寂しさを感じるのは否定できない。だが、一方では、こうした地位の逆転は今までにも度々起こってきたことなのだろうし、人類の科学そのものの停滞を意味するわけではないだろう。日本はただ沈んでいくのではなく、これまでの遺産を生かしながら、科学研究の世界でそれなりの地位を守っていくことを真剣に考えないといけない時期かもしれない。

2020年6月10日水曜日

bamファイルからのリサンプリング



fastq / fasta ファイルからのリサンプリングについては、前回にまとめた通り、seqkitやseqtkを使ってサンプリングすることができる。



$ seqkit sample -n 100 -s 100 seq_R1.fastq.gz -o subseq_R1.fastq.gz



または、seqtkを使う場合は、



$ seqtk sample -s 100 seq_R1.fastq.gz 1000 > subseq_R1.fastq



以下では、すでにマッピングされたデータのbamファイルから、リード数や割合を指定してダウンサンプリングする方法をまとめる。



bamを扱うbamtools randomを使ってサンプリングできる他、samtools viewを使ってサンプリングすることもできる。bamファイルのリード数やサマリーはbamtools countや、bamtools statsで得ることができる。




bamファイルのリードをサンプリングする場合



 1.  bamtools randomを使ってサンプリングする



$ bamtools random -n 1000 -in input.bam -out random_1000.bam



このコマンド実行には、bamファイルのindexが必要になる。



$ bamtools random --help
Description: grab a random subset of alignments.

Usage: bamtools random [-in <filename> -in <filename> ... | -list <filelist>] [-out <filename>] [-forceCompression] [-n] [-region <REGION>]

Input & Output:
  -in <BAM filename>                the input BAM file [stdin]
  -list <filename>                  the input BAM file list, one
                                    line per file
  -out <BAM filename>               the output BAM file [stdout]
  -region <REGION>                  only pull random alignments
                                    from within this genomic region. Index
                                    file is recommended for better
                                    performance, and is used automatically if
                                    it exists. See 'bamtools help index' for
                                    more details on creating one
  -forceCompression                 if results are sent to stdout
                                    (like when piping to another tool),
                                    default behavior is to leave output
                                    uncompressed. Use this flag to override
                                    and force compression

Settings:
  -n <count>                        number of alignments to grab.
                                    Note - no duplicate checking is performed
                                    [10000]
  -seed <unsigned integer>          random number generator seed
                                    (for repeatable results). Current time is
                                    used if no seed value is provided.

Help:
  --help, -h                        shows this help text





2. samtools view を使ってサンプリングする



samtools view -@ 8 -s 0.01 -b input.bam > random_0.01.bam



@8では用いるスレッド数を指定し、-sではサンプリングする割合を指定している。
bamファイルにindexがなくてもサンプリングが行われる。



$ samtools view

Usage: samtools view [options] <in.bam>|<in.sam>|<in.cram> [region ...]

Options:
  -b       output BAM
  -C       output CRAM (requires -T)
  -1       use fast BAM compression (implies -b)
  -u       uncompressed BAM output (implies -b)
  -h       include header in SAM output
  -H       print SAM header only (no alignments)
  -c       print only the count of matching records
  -o FILE  output file name [stdout]
  -U FILE  output reads not selected by filters to FILE [null]
  -t FILE  FILE listing reference names and lengths (see long help) [null]
  -L FILE  only include reads overlapping this BED FILE [null]
  -r STR   only include reads in read group STR [null]
  -R FILE  only include reads with read group listed in FILE [null]
  -q INT   only include reads with mapping quality >= INT [0]
  -l STR   only include reads in library STR [null]
  -m INT   only include reads with number of CIGAR operations consuming
           query sequence >= INT [0]
  -f INT   only include reads with all  of the FLAGs in INT present [0]
  -F INT   only include reads with none of the FLAGS in INT present [0]
  -G INT   only EXCLUDE reads with all  of the FLAGs in INT present [0]
  -s FLOAT subsample reads (given INT.FRAC option value, 0.FRAC is the
           fraction of templates/read pairs to keep; INT part sets seed)
  -M       use the multi-region iterator (increases the speed, removes
           duplicates and outputs the reads as they are ordered in the file)
  -x STR   read tag to strip (repeatable) [null]
  -B       collapse the backward CIGAR operation
  -?       print long help, including note about region specification
  -S       ignored (input format is auto-detected)
      --input-fmt-option OPT[=VAL]
               Specify a single input file format option in the form
               of OPTION or OPTION=VALUE
  -O, --output-fmt FORMAT[,OPT[=VAL]]...
               Specify output format (SAM, BAM, CRAM)
      --output-fmt-option OPT[=VAL]
               Specify a single output file format option in the form
               of OPTION or OPTION=VALUE
  -T, --reference FILE
               Reference sequence FASTA FILE [null]
  -@, --threads INT
               Number of additional threads to use [0]




bamファイルのリード数の確認



bamtools countを使って、bamファイルのリード数を確認することができる。
この場合、リード数のカウントのみが返される。



$ bamtools count -in output.bam



bamtools statsを実行した場合、bamファイルのいくつかの統計量が返ってくる。



$ bamtools stats -in output.bam




実行例



1-1. bamtools random を使った実行例とリード数確認



$ bamtools random -n 1000 -in Map_sorted.bam -out random1000.bam



$ bamtools stats -in random1000.bam
**********************************************
Stats for BAM file(s): 
**********************************************

Total reads:       1000
Mapped reads:      1000 (100%)
Forward strand:    488 (48.8%)
Reverse strand:    512 (51.2%)
Failed QC:         0 (0%)
Duplicates:        0 (0%)
Paired-end reads:  0 (0%)



$ bamtools count -in random1000.bam 
1000




1-2. index dataがないとエラーになる



$ bamtools random -n 1000 -in random0.01.bam -out random0.01c.bam
bamtools random ERROR: could not load index data for all input BAM file(s)... Aborting.




2-1. samtools viewを使った実行例とリード数確認



$ samtools view -@ 8 -s 0.01 -b Map_sorted.bam > random0.01.bam



$ bamtools count -in Map_sorted.bam
83451883



$ bamtools stats -in Map_sorted.bam

**********************************************
Stats for BAM file(s): 
**********************************************

Total reads:       83451883
Mapped reads:      73599533 (88.194%)
Forward strand:    50335770 (60.3171%)
Reverse strand:    33116113 (39.6829%)
Failed QC:         0 (0%)
Duplicates:        0 (0%)
Paired-end reads:  0 (0%)



$ bamtools stats -in random0.01.bam 

**********************************************
Stats for BAM file(s): 
**********************************************

Total reads:       833871
Mapped reads:      735382 (88.1889%)
Forward strand:    503605 (60.3936%)
Reverse strand:    330266 (39.6064%)
Failed QC:         0 (0%)
Duplicates:        0 (0%)
Paired-end reads:  0 (0%)



$ bamtools count -in random0.01.bam 
833871



2-2.  samtools viewはinxex情報がなくてもサンプリングを実行する。



$ samtools view -@ 8 -s 0.01 -b random0.01.bam > random0.01b.bam



$ bamtools count -in random0.01b.bam 
833871



$ bamtools stats -in random0.01b.bam 

**********************************************
Stats for BAM file(s): 
**********************************************

Total reads:       833871
Mapped reads:      735382 (88.1889%)
Forward strand:    503605 (60.3936%)
Reverse strand:    330266 (39.6064%)
Failed QC:         0 (0%)
Duplicates:        0 (0%)
Paired-end reads:  0 (0%)




備考

bamtoolsのバージョンは、2.5.1を用いた。
samtoolsのバージョンは、1.9を用いた。