UNIX講習会 シェルスクリプト2 31/July/2015 情報管理解析室 西出 浩世
SGE
~/unix15/sge $ cd ~/unix15/sge $ ls script* script2.sh script3.sh script4.sh ~/unix15/sge/results sam 12 $ ls results/*.sam $ rm -r results $ cp -r /usr/local/data/unix15/sge/results.
for script1.sh $ emacs script1.sh #!/bin/sh for sm in results/*.sam do echo ${sm} done script1.sh $ chmod +x script1.sh $./script1.sh results/ecoli.1.sam results/ecoli.10.sam results/ecoli.11.sam results/ecoli.12.sam
for for for in do done No do Yes for done for 1 for
for for f in./* do done ${f} 1 for i in 1 2 3 4 5 6 7 do done for i in {1..10} do done 1 7 ${i} 1 7 1 10 ${i} 1 10
if script2.sh bowtie $ less script2.sh #!/bin/sh if [ -f results/ecoli.10.sam ] then echo 'ok' else echo 'not ok' fi $ chmod +x script2.sh $./script2.sh ok
if if [ ] if [ ] then else fi if -> -> then if fi False if True then else if fi elif
if if elif False if if [ 1 ] then elif [ 2 ] then elif [ 3 ] then else fi True then elif True then else if fi False
if : [ ] test man test 1 -eq 2 1 -ne 2 1 -gt 2 1 -lt 2 1 -ge 2 1 -le 2 1 > 2 1 < 2 1 >= 2 1 =< 2 -n 0! 0 1 = 2 1!= 2! 1 -a 2 1, 2 1 -o 2 1, 2 -d -f -e -L -r -w -x -s 0 1 -nt 2 1 2 1 -ot 2 1 2
~/sge/results/ 12.sam.bam samtools sam -> bam samtools view -bs example.sam > example.bam.bam
: basename $ basename ~/unix15/sge/results/ecoli.9.sam ecoli.9.sam $ basename ~/unix15/sge/results/ecoli.9.sam.sam ecoli.9 $ basename ~/unix15/sge/results/ecoli.10.sam 0.sam ecoli.1
` ` date $ date 2015 1 20 11:26:31 JST $ echo "Today is date" Today is date $ echo "Today is `date`" Today is 2015 1 20 11:28:08 JST basename $ fn=`basename result/ecoli.9.sam.sam` $ echo ${fn} ecoli.9
basename sam -> bam samtools view -bs example.sam > example.bam results/ecoli.1.sam bam result/ecoli.1.bam $ fn=`basename results/ecoli.1.sam.sam` $ echo ${fn} ecoli.1 $ samtools view -bs results/ecoli.1.sam > results/${fn}.bam 1) 2) 1) fn ecoli.1 2) ${fn}.bam bam
for, basename, ` ` $ less script3.sh for sm in results/*.sam do fn=`basename ${sm}.sam` echo ${sm} ${fn} done script3.sh results.sam ${sm}, ${fn} $ chmod +x script3.sh $./script3.sh
for ~/unix15/sge/results/.sam.bam samtools sam -> bam samtools view -bs example.sam > example.bam script3.sh.bam results/ ecoli.1.bam ecoli.12.bam basename qsub samtools echo./script3.sh echo echo qsub script3.sh
#!/bin/sh for sm in results/*.sam do fn=`basename ${sm}.sam` script5.sh echo samtools view -bs ${sm} > results/${fn}.bam done $./script3.sh
#!/bin/sh #$ -cwd for sm in results/*.sam do fn=`basename ${sm}.sam` script5.sh samtools view -bs ${sm} > results/${fn}.bam done $ qsub script3.sh
( ) $ { [ ] } $ array=("human" "mouse" "rat") $ echo ${array} human $ echo ${array[2]} rat $ echo ${array[@]} 0,,,,,,,,,,,,,,,,,,,1,,,,,,,,,,,,,,,,2 human mouse rat human mouse rat $ fl=(results/*.sam) $ echo ${fl[0]} $ fl=(`ls`) $ echo ${fl[@]} results/.sam
for #!/bin/sh array=(results/*.sam) for i in {1..12} do fn=`basename ${array[i-1]}.sam` echo $fn ${array[i-1]} done results.sam ${array} 12 1 12 1 for i in {0..11} 1
#!/bin/sh #$ -t 1-12 #$ -cwd list=(`ls../rnaseq/test_fastq/`) script4.sh bowtie2 -x../rnaseq/ecoli_genome -U../rnaseq/test_fastq/${list[${SGE_TASK_ID}-1]} -S results/ecoli.${sge_task_id}.sam 0 SGE_TASK_ID 1 1 ${list[${sge_task_id}-1]}