-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.tex
More file actions
2874 lines (2195 loc) · 101 KB
/
index.tex
File metadata and controls
2874 lines (2195 loc) · 101 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Options for packages loaded elsewhere
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
%
\documentclass[
letterpaper,
DIV=11,
numbers=noendperiod]{scrreprt}
\usepackage{xcolor}
\usepackage{amsmath,amssymb}
\setcounter{secnumdepth}{5}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math} % this also loads fontspec
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
% xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
% Make \paragraph and \subparagraph free-standing
\makeatletter
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}{
\@ifstar
\xxxParagraphStar
\xxxParagraphNoStar
}
\newcommand{\xxxParagraphStar}[1]{\oldparagraph*{#1}\mbox{}}
\newcommand{\xxxParagraphNoStar}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}{
\@ifstar
\xxxSubParagraphStar
\xxxSubParagraphNoStar
}
\newcommand{\xxxSubParagraphStar}[1]{\oldsubparagraph*{#1}\mbox{}}
\newcommand{\xxxSubParagraphNoStar}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
\makeatother
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{241,243,245}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.40,0.45,0.13}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\ExtensionTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.28,0.35,0.67}{#1}}
\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.00,0.46,0.62}{#1}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.07,0.07,0.07}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\newsavebox\pandoc@box
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
\sbox\pandoc@box{#1}%
\Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
\Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
\ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
\ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
\else\usebox{\pandoc@box}%
\fi%
}
% Set default figure placement to htbp
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\KOMAoption{captions}{tableheading}
\makeatletter
\@ifpackageloaded{tcolorbox}{}{\usepackage[skins,breakable]{tcolorbox}}
\@ifpackageloaded{fontawesome5}{}{\usepackage{fontawesome5}}
\definecolor{quarto-callout-color}{HTML}{909090}
\definecolor{quarto-callout-note-color}{HTML}{0758E5}
\definecolor{quarto-callout-important-color}{HTML}{CC1914}
\definecolor{quarto-callout-warning-color}{HTML}{EB9113}
\definecolor{quarto-callout-tip-color}{HTML}{00A047}
\definecolor{quarto-callout-caution-color}{HTML}{FC5300}
\definecolor{quarto-callout-color-frame}{HTML}{acacac}
\definecolor{quarto-callout-note-color-frame}{HTML}{4582ec}
\definecolor{quarto-callout-important-color-frame}{HTML}{d9534f}
\definecolor{quarto-callout-warning-color-frame}{HTML}{f0ad4e}
\definecolor{quarto-callout-tip-color-frame}{HTML}{02b875}
\definecolor{quarto-callout-caution-color-frame}{HTML}{fd7e14}
\makeatother
\makeatletter
\@ifpackageloaded{bookmark}{}{\usepackage{bookmark}}
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\AtBeginDocument{%
\ifdefined\contentsname
\renewcommand*\contentsname{Table of contents}
\else
\newcommand\contentsname{Table of contents}
\fi
\ifdefined\listfigurename
\renewcommand*\listfigurename{List of Figures}
\else
\newcommand\listfigurename{List of Figures}
\fi
\ifdefined\listtablename
\renewcommand*\listtablename{List of Tables}
\else
\newcommand\listtablename{List of Tables}
\fi
\ifdefined\figurename
\renewcommand*\figurename{Figure}
\else
\newcommand\figurename{Figure}
\fi
\ifdefined\tablename
\renewcommand*\tablename{Table}
\else
\newcommand\tablename{Table}
\fi
}
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{Listing}
\newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
\makeatother
\makeatletter
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
\makeatother
\makeatletter
\@ifpackageloaded{tikz}{}{\usepackage{tikz}}
\makeatother
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=1pt] (char) {{\scriptsize#1}};}}
\usepackage{bookmark}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
pdftitle={Bash for Bioinformatics},
pdfauthor={Ted Laderas},
colorlinks=true,
linkcolor={blue},
filecolor={Maroon},
citecolor={Blue},
urlcolor={Blue},
pdfcreator={LaTeX via pandoc}}
\title{Bash for Bioinformatics}
\author{Ted Laderas}
\date{2025-07-09}
\begin{document}
\maketitle
\renewcommand*\contentsname{Table of contents}
{
\hypersetup{linkcolor=}
\setcounter{tocdepth}{2}
\tableofcontents
}
\bookmarksetup{startatroot}
\chapter*{Bash for Bio}\label{bash-for-bio}
\addcontentsline{toc}{chapter}{Bash for Bio}
\markboth{Bash for Bio}{Bash for Bio}
\section*{Who this course is for}\label{who-this-course-is-for}
\addcontentsline{toc}{section}{Who this course is for}
\markright{Who this course is for}
\begin{itemize}
\tightlist
\item
Have you needed to align a folder of FASTA files and not know how to
do it?
\item
Do you want to automate an R or Python script you wrote to work on a
bunch of files?
\item
Do you want to do all of this on a high performance cluster ()?
\end{itemize}
If so, this course is for you! We will learn enough bash scripting to do
useful things on the Fred Hutch cluster and automate the boring parts.
\section*{Learning Objectives}\label{learning-objectives}
\addcontentsline{toc}{section}{Learning Objectives}
\markright{Learning Objectives}
\begin{itemize}
\tightlist
\item
\textbf{Articulate} basic HPC architecture concepts and why they're
useful in your work
\item
\textbf{Apply} bash scripting to execute alignment, and Python/R
scripts
\item
\textbf{Navigate} and \textbf{process} data on the different
filesystems available at FH
\item
\textbf{Leverage} bash scripting to execute jobs on a high performance
cluster.
\item
\textbf{Execute} batch processing of multiple files in a project
\item
\textbf{Manage} software dependencies reproducibly using
container-based technologies such as Docker/Apptainer containers or
EasyBuild modules
\end{itemize}
\section*{Prerequisites}\label{prerequisites}
\addcontentsline{toc}{section}{Prerequisites}
\markright{Prerequisites}
\begin{itemize}
\tightlist
\item
You will need an account on \texttt{rhino} and know how to connect to
it through VPN
\item
We highly recommend reviewing
\href{https://hutchdatascience.org/Intro_to_Command_Line/}{Intro to
Command Line} and
\href{https://hutchdatascience.org/FH_Cluster_101/}{Cluster 101}
\item
Basic knowledge of the following commands:
\begin{itemize}
\tightlist
\item
\texttt{ls}
\item
\texttt{cd} and basic directory navigation
\item
\texttt{mv}/\texttt{cp}/\texttt{mkdir}/\texttt{rm}
\end{itemize}
\end{itemize}
\begin{tcolorbox}[enhanced jigsaw, colbacktitle=quarto-callout-note-color!10!white, left=2mm, toprule=.15mm, toptitle=1mm, opacityback=0, bottomrule=.15mm, breakable, leftrule=.75mm, colframe=quarto-callout-note-color-frame, bottomtitle=1mm, titlerule=0mm, coltitle=black, title=\textcolor{quarto-callout-note-color}{\faInfo}\hspace{0.5em}{Terminology}, rightrule=.15mm, arc=.35mm, opacitybacktitle=0.6, colback=white]
We know that not all of us have the same vocabulary. We try to define
terminology as much as possible. These are indicated by double
underlines such as this:
You can click and hold on the term to define it.
\end{tcolorbox}
\section*{Schedule}\label{schedule}
\addcontentsline{toc}{section}{Schedule}
\markright{Schedule}
\begin{longtable}[]{@{}
>{\raggedright\arraybackslash}p{(\linewidth - 2\tabcolsep) * \real{0.4000}}
>{\raggedright\arraybackslash}p{(\linewidth - 2\tabcolsep) * \real{0.6000}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Week
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Topics
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
Preclass & Review
\href{https://hutchdatascience.org/Intro_to_Command_Line/}{Intro to
Command Line} and
\href{https://hutchdatascience.org/FH_Cluster_101/}{Cluster 101} \\
Week 1 & \href{01_basics.qmd}{Filesystem Basics} \\
Week 2 & \href{02_scripting.qmd}{Writing and Running Bash Scripts} \\
Week 3 & Batch Processing and HPC Jobs \\
Week 4 & Testing Scripts/Workflow Managers \\
On your own time & \href{configuring.qmd}{Configuring your Bash
Shell} \\
\end{longtable}
\section*{Reference Text}\label{reference-text}
\addcontentsline{toc}{section}{Reference Text}
\markright{Reference Text}
\begin{itemize}
\tightlist
\item
We will be using Julia Evan's
\href{https://wizardzines.com/zines/bite-size-bash/}{Bite Size Bash}
as our reference text. Julia's explanations are incredibly clear and
it will be a valuable reference even beyond this course. You will
receive the PDF as part of class.
\item
If you want to know the true power of the command line, I recommend
\href{}{Data Science at the Command Line}.
\end{itemize}
\bookmarksetup{startatroot}
\chapter{Navigating the Bash
Filesystem}\label{navigating-the-bash-filesystem}
\section{Learning Objectives}\label{learning-objectives-1}
By the end of this session, you should be able to:
\begin{itemize}
\tightlist
\item
\textbf{Navigate} and \textbf{copy} data to the different filesystems
available at Fred Hutch.
\item
\textbf{Explain} the difference between \emph{absolute} and
\emph{relative} file paths.
\item
\textbf{Set} Permissions on and \textbf{execute} a bash script
\item
\textbf{Find} help on the system
\end{itemize}
\section{Map of the Material}\label{map-of-the-material}
\includegraphics[width=2.88in,height=5.31in]{01_basics_files/figure-latex/mermaid-figure-1.png}
\begin{tcolorbox}[enhanced jigsaw, colbacktitle=quarto-callout-note-color!10!white, left=2mm, toprule=.15mm, toptitle=1mm, opacityback=0, bottomrule=.15mm, breakable, leftrule=.75mm, colframe=quarto-callout-note-color-frame, bottomtitle=1mm, titlerule=0mm, coltitle=black, title=\textcolor{quarto-callout-note-color}{\faInfo}\hspace{0.5em}{Reminder about Terminology}, rightrule=.15mm, arc=.35mm, opacitybacktitle=0.6, colback=white]
Defined words are double underlined. You can \emph{click and hold} on
them to see the definition. Try it below!
\end{tcolorbox}
\section{Navigating the Bash
Terminal}\label{navigating-the-bash-terminal}
\begin{quote}
We recommend that you review the material for Intro to Command Line and
know the following: Changing directories,
\end{quote}
By default, when you log into a remote system such as \texttt{rhino},
you are in a .
Why is it a bash shell? Bash is the default shell for linux systems,
especially for high performance clusters (HPCs), and there are some
quirks about navigating around the command line you should be aware of.
\begin{tcolorbox}[enhanced jigsaw, breakable, leftrule=.75mm, colframe=quarto-callout-color-frame, left=2mm, toprule=.15mm, arc=.35mm, rightrule=.15mm, opacityback=0, bottomrule=.15mm, colback=white]
\vspace{-3mm}\textbf{A helpful key: \texttt{\textless{}Up\ Arrow\textgreater{}}}\vspace{3mm}
The key will let you cycle through your history, or previous executed
commands. This can be super helpful if you have typed a long command
with a syntax error. You can use
\texttt{\textless{}Up\ Arrow\textgreater{}} to fix mistakes and run that
command again.
\end{tcolorbox}
\section{Setting Yourself Up for
Success}\label{setting-yourself-up-for-success}
So we have logged into \texttt{rhino}. Now what?
\section{Navigating the Filesystems}\label{navigating-the-filesystems}
\subsection{\texorpdfstring{\texttt{pwd} Where Am
I?}{pwd Where Am I?}}\label{pwd-where-am-i}
The \texttt{pwd} command (short for \emph{present working directory})
will let you know your current location in the filesystem. Knowing your
current directory is critical when using \emph{relative} file paths.
If I run \texttt{pwd} right after signing into \texttt{rhino} I get:
\begin{verbatim}
/home/tladera2
\end{verbatim}
You should have a similar path, except with your user name. This is your
\emph{home directory} - where you have a limited amount of space to
store scripts and other files. Don't worry, the majority of your data is
stored elsewhere ()
\section{\texorpdfstring{Going \texttt{/home}:
\texttt{\textasciitilde{}/}}{Going /home: \textasciitilde/}}\label{sec-home}
There is one important file alias you should always remember:
\texttt{\textasciitilde{}/} is shorthand for your own \emph{home
directory}.
Depending on the linux distribution, this can be a different location.
On the FH filesystem, when I use \texttt{\textasciitilde{}/}, it maps
to:
\texttt{/home/tladera2/}
The home directory is also important because it is where your
configuration files live, such as \texttt{.bashrc} (see
Section~\ref{sec-bashrc}).
Depending on how you work, you may want to store your scripts and
workflows in \texttt{/home/}. Some people prefer to keep their scripts,
data, and results in a single folder. This is not really practical for
most genomics projects, unless you are saving processed data. For more
info, see Section~\ref{sec-project}.
\begin{tcolorbox}[enhanced jigsaw, breakable, leftrule=.75mm, colframe=quarto-callout-color-frame, left=2mm, toprule=.15mm, arc=.35mm, rightrule=.15mm, opacityback=0, bottomrule=.15mm, colback=white]
\vspace{-3mm}\textbf{Your current working directory}\vspace{3mm}
There is an alias for your current directory: \texttt{.} (the period
sign).
This becomes useful when you want to output files to your current
location.
\end{tcolorbox}
\subsection{\texorpdfstring{\texttt{du}: How much
space?}{du: How much space?}}\label{du-how-much-space}
One of the things we can do is check for disk usage with the \texttt{du}
command. If I run \texttt{du} by itself on the command line, it will
give me the disk usage of all folders and files in our current
directory, which is a lot of output.
There is an option called \texttt{-d} that lets us specify the
\emph{depth}. \texttt{-d\ 1} will give us only the file sizes of the top
level folders in our directory:
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{du} \AttributeTok{{-}d}\NormalTok{ 1 .}
\end{Highlighting}
\end{Shaded}
Here are the first few lines of my \texttt{du} output.
\begin{verbatim}
630440 ./Code
32 ./Downloads
32 ./Pictures
2495144 ./miniconda3
64 ./.launch-rstudio-server
72 ./.ipynb_checkpoints
64 ./.qt
1616 ./.config
32 ./Music
32 ./Desktop
\end{verbatim}
If we want to specify \texttt{du} to scan only a single folder, we can
give the folder name.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{du} \AttributeTok{{-}d}\NormalTok{ 1 Desktop}
\end{Highlighting}
\end{Shaded}
I have nothing really stored in my \texttt{Desktop/} folder, so I get
the following:
\begin{verbatim}
32 Desktop/
\end{verbatim}
\begin{tcolorbox}[enhanced jigsaw, breakable, leftrule=.75mm, colframe=quarto-callout-color-frame, left=2mm, toprule=.15mm, arc=.35mm, rightrule=.15mm, opacityback=0, bottomrule=.15mm, colback=white]
\vspace{-3mm}\textbf{Try it out}\vspace{3mm}
Try checking the disk usage using \texttt{du} for the \texttt{Desktop}
folder in your \texttt{/home} directory (mine is
\texttt{/home/tladera2}).
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{du} \AttributeTok{{-}d}\NormalTok{ 1 }\AttributeTok{{-}{-}{-}{-}{-}{-}{-}{-}}\NormalTok{/}
\end{Highlighting}
\end{Shaded}
Try out using \texttt{du\ -d\ 2} on your home directory:
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{du} \AttributeTok{{-}d}\NormalTok{ 2 \textasciitilde{}/}
\end{Highlighting}
\end{Shaded}
\end{tcolorbox}
\section{FH users: the main filesystems}\label{sec-filesystems}
When working on the Fred Hutch HPC, there are four main filesystems you
should consider:
\begin{itemize}
\tightlist
\item
\texttt{/home/} - The home filesystem. Your scripts can live here.
Also where your configuration files (such as \texttt{.bashrc}) live.
Can be accessed using \texttt{\textasciitilde{}/}.
\item
\texttt{/fh/fast/} (also known as \texttt{fast}) - Research storage.
Raw files and processed results should live here.
\item
\texttt{/hpc/temp/} (also known as \texttt{temp}) - The temporary
filesystem. This filesystem is faster to access for gizmo nodes on the
cluster, so files can be copied to for computation. The output files
you generate should be moved back into an appropriate folder on
\texttt{/fh/fast/}. Note that files on \texttt{/fh/temp/} will be
deleted after 30 days.
\item
\texttt{/fh/regulated/} - A secure filesystem meant for NIH regulated
data. If you are processing data that is regulated under the current
NIH guidelines, you will process it here.
\end{itemize}
So, how do we utilize these filesystems? We will be running commands
like this:
\phantomsection\label{annotated-cell-7}%
\begin{Shaded}
\begin{Highlighting}[]
\ExtensionTok{ml}\NormalTok{ BWA }\hspace*{\fill}\NormalTok{\circled{1}}
\ExtensionTok{bwa}\NormalTok{ mem }\AttributeTok{{-}M} \AttributeTok{{-}t}\NormalTok{ 2 }\hspace*{\fill}\NormalTok{\circled{2}}
\ExtensionTok{/fh/fast/reference\_data/chr20} \hspace*{\fill}\NormalTok{\circled{3}}
\ExtensionTok{/fh/fast/laderas\_t/raw\_data/na12878\_1.fq} \hspace*{\fill}\NormalTok{\circled{4}}
\ExtensionTok{/fh/fast/laderas\_t/raw\_data/na12878\_2.fq}
\OperatorTok{\textgreater{}}\NormalTok{ /hpc/temp/laderas\_t/aligned\_data/na12878\_1.sam }\hspace*{\fill}\NormalTok{\circled{5}}
\end{Highlighting}
\end{Shaded}
\begin{description}
\tightlist
\item[\circled{1}]
Load bwa software
\item[\circled{2}]
Start \texttt{bwa\ mem} (aligner)
\item[\circled{3}]
path of genome index
\item[\circled{4}]
path of paired end reads files
\item[\circled{5}]
path of output
\end{description}
To understand the above, We first have to familiarize ourselves with
\emph{absolute} vs \emph{relative} paths.
\section{Absolute versus relative paths}\label{sec-paths}
You may have muddled with file paths, and maybe have used absolute paths
to specify the location of a file. When you are processing files, it is
important to understand the difference.
\textbf{Absolute paths} contain all the information needed to find a
file in a file system from the root \texttt{/} directory. For example,
this would be an absolute path:
\begin{verbatim}
/fh/fast/laderast/immuno_project/raw_data/chr2.fa.gz
\end{verbatim}
Absolute paths always start with \texttt{/}, because that is the root
directory, where all the top folders and files live.
In terms of folder structure, this is what this looks like:
\phantomsection\label{annotated-cell-9}%
\begin{Shaded}
\begin{Highlighting}[]
\ExtensionTok{/} \hspace*{\fill}\NormalTok{\circled{1}}
\ExtensionTok{├──}\NormalTok{ fh }\hspace*{\fill}\NormalTok{\circled{2}}
\ExtensionTok{│}\NormalTok{ └──fast}
\ExtensionTok{│}\NormalTok{ └──laderast}
\KeywordTok{|} \ExtensionTok{└──immuno\_project}
\ExtensionTok{│}\NormalTok{ └──raw\_data}
\ExtensionTok{│}\NormalTok{ └──chr2.fa.gz}
\end{Highlighting}
\end{Shaded}
\begin{description}
\tightlist
\item[\circled{1}]
Root directory
\item[\circled{2}]
Folders in root directory
\end{description}
\textbf{Relative paths} break up an absolute path into two pieces of
information: 1) your current directory and 2) the path \emph{relative}
to that directory. Relative paths are really helpful because things
don't break when you move your folder or files.
If my current working directory is the directory
\texttt{/fh/fast/laderas\_t/immuno\_project/}, then the relative path to
that same file would be:
\begin{verbatim}
raw_data/chr2.fa.gz
\end{verbatim}
We can visualize the relative path like this, where our working
directory is indicated by a star:
\phantomsection\label{annotated-cell-11}%
\begin{Shaded}
\begin{Highlighting}[]
\ExtensionTok{/} \hspace*{\fill}\NormalTok{\circled{1}}
\ExtensionTok{├──}\NormalTok{ fh/fast/laderast/immuno\_project/ }\hspace*{\fill}\NormalTok{\circled{2}}
\KeywordTok{|} \ExtensionTok{└──raw\_data} \hspace*{\fill}\NormalTok{\circled{3}}
\ExtensionTok{│}\NormalTok{ └──chr2.fa.gz }
\end{Highlighting}
\end{Shaded}
\begin{description}
\tightlist
\item[\circled{1}]
The root directory
\item[\circled{2}]
Our working directory
\item[\circled{3}]
Our relative path
\end{description}
Note that this relative path does not start with a \texttt{/}, because
our current directory isn't the root directory. Relative paths are
incredibly useful when scripting in a reproducible manner, such as using
project-based workflows to process files in a single folder.
\begin{tcolorbox}[enhanced jigsaw, breakable, leftrule=.75mm, colframe=quarto-callout-color-frame, left=2mm, toprule=.15mm, arc=.35mm, rightrule=.15mm, opacityback=0, bottomrule=.15mm, colback=white]
\vspace{-3mm}\textbf{\texttt{\textless{}TAB\textgreater{}} is for autocompletion of paths}\vspace{3mm}
Never underestimate the usefulness of the
\texttt{\textless{}TAB\textgreater{}} key, which triggers autocompletion
on the command line. It can help you complete paths to files and save
you a lot of typing.
For example, say I have a path that I want to navigate to
\texttt{/home/tladera2/my\_long\_path}
I can type in the first part of the path and then hit
\texttt{\textless{}TAB\textgreater{}}:
\texttt{/home/tladera2/my\_\textless{}TAB\textgreater{}}
And if the prefix \texttt{my\_} is unique in my folder, it will
autocomplete the path:
\texttt{/home/tladera2/my\_long\_path}
Note that we need to use enough of the folder name so that completing it
is unambiguous. If there are multiple choices, then autocomplete will
list all of them.
\end{tcolorbox}
\section{Grabbing Stuff from GitHub}\label{grabbing-stuff-from-github}
For the rest of the exercises for today, we'll be grabbing the scripts
from github using \texttt{git\ clone}.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{git}\NormalTok{ clone https://github.com/fhdsl/bash\_for\_bio\_scripts}
\end{Highlighting}
\end{Shaded}
This will create a folder called \texttt{bash\_for\_bio\_scripts/} in
our current directory.
\section{File Permissions}\label{sec-permissions}
File permissions are that are attached to file objects. They are how the
system prevents certain files from being modified or restricting access
of these files to certain people or groups.
All files have the following level of access permissions:
\begin{longtable}[]{@{}ll@{}}
\toprule\noalign{}
Level & Description \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
Owner-level & The owner of the file \\
Group-level & The group of the file \\
Everyone & The rest of the world \\
\end{longtable}
For example, if I'm the owner of the file, I can restrict the type of
access to only myself (owner-level), the group I'm in (Group-level), or
make the file freely available to everyone on the system (Everyone).
Each level has the following type of access:
\begin{longtable}[]{@{}
>{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.1176}}
>{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.3235}}
>{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.3529}}
>{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.2059}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Type
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Description
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Abbreviation
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Example
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
Read & Level can only read contents of file & \texttt{r} & A list of
users in a text file \\
Write & Level can write to the file & \texttt{w} & Appending an entry to
the end of a log \\
Execute & Level can run the file as an executable & \texttt{x} &
samtools \\
\end{longtable}
You can see the permissions for a file using the
\texttt{ls\ -l\ \textless{}FILENAME\textgreater{}}. For example:
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{ls} \AttributeTok{{-}l}\NormalTok{ scripts}
\end{Highlighting}
\end{Shaded}
will give me the following line:
\begin{Shaded}
\begin{Highlighting}[]
\ExtensionTok{{-}rwxrwxrwx}\NormalTok{ 1 tladera2 staff 16 Jul 11 11:05 tell\_the\_time.sh}
\end{Highlighting}
\end{Shaded}
The cardinal rule to remember is that:
\begin{quote}
If you want to run a file as an executable, you (or your group) needs to
have executable level permission.
\end{quote}
For example, if I want to run a script called \texttt{run\_samtools.sh}
in my directory like this:
\begin{verbatim}
./run_samtools.sh my_bam_file.bam
\end{verbatim}
I will need to have execute privileges at the user, group, or others
level.
We can change the permissions of our files using the \texttt{chmod}
command.
\begin{tcolorbox}[enhanced jigsaw, breakable, leftrule=.75mm, colframe=quarto-callout-color-frame, left=2mm, toprule=.15mm, arc=.35mm, rightrule=.15mm, opacityback=0, bottomrule=.15mm, colback=white]
\vspace{-3mm}\textbf{Helpful unix permissions situations}\vspace{3mm}
I tend to just go by memory when setting file permissions. If I have
collaborators who just want to set
\begin{longtable}[]{@{}ll@{}}
\toprule\noalign{}
Situation & Command \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
Only I can execute/read/write a file &
\texttt{chmod\ 700\ \textless{}filename\textgreater{}} \\
Only I and my group can read a file &
\texttt{chmod\ 110\ \textless{}filename\textgreater{}} \\
Grant my group read permissions &
\texttt{chmod\ 710\ \textless{}filename\textgreater{}} \\
Make executable/read/write by all &
\texttt{chmod\ 777\ \textless{}filename\textgreater{}} \\
\end{longtable}
\end{tcolorbox}
\begin{tcolorbox}[enhanced jigsaw, breakable, leftrule=.75mm, colframe=quarto-callout-color-frame, left=2mm, toprule=.15mm, arc=.35mm, rightrule=.15mm, opacityback=0, bottomrule=.15mm, colback=white]
\vspace{-3mm}\textbf{Even if you don't have execute permissions}\vspace{3mm}
With bash scripts, you can still run them if you have \texttt{read}
permissions. You can still run bash scripts by using the \texttt{bash}
command:
\begin{verbatim}
bash run_samtools.sh my_bam_file.bam
\end{verbatim}
\end{tcolorbox}
\subsection{Try it out}\label{try-it-out-1}
What are the permissions for the GitHub repo (bash\_for\_bio) that you
just downloaded?
\section{Moving Things Around}\label{sec-moving}
A lot of the time, we need to move files between shared filesystems. One
filesystem might be good at storage and be backed up on a regular basis,
while another filesystem might be better for temporary work on the
cluster.
You might be familiar with \texttt{mv}, which lets you move files around
in Unix. One thing to keep in mind when you're \texttt{mv}ing things to
a new folder that there is a difference between:
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{mv}\NormalTok{ log.txt my\_folder }\CommentTok{\#\# renames log.txt to my\_folder}
\end{Highlighting}
\end{Shaded}
and
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{mv}\NormalTok{ log.txt my\_folder/ }\CommentTok{\#\# moves log.txt to be in my\_folder}
\end{Highlighting}
\end{Shaded}
This is one thing that still trips me up all the time.
This is one situation where using a GUI such as Motuz
(\textbf{?@sec-motuz}) can be very helpful. You don't have to worry
about accidentally renaming files.
Other tools for sync'ing between filesystems include \texttt{rsync},
which requires careful reading of documentation.
\begin{tcolorbox}[enhanced jigsaw, breakable, leftrule=.75mm, colframe=quarto-callout-color-frame, left=2mm, toprule=.15mm, arc=.35mm, rightrule=.15mm, opacityback=0, bottomrule=.15mm, colback=white]
\vspace{-3mm}\textbf{Things I always forget: the difference between \texttt{/home/mydir/} and
\texttt{home/mydir/}}\vspace{3mm}
Some things that trip me up all the time. The difference between
\begin{Shaded}
\begin{Highlighting}[]
\ExtensionTok{/home/mydir/} \CommentTok{\#absolute path}
\end{Highlighting}
\end{Shaded}
and
\begin{Shaded}
\begin{Highlighting}[]
\ExtensionTok{home/mydir/} \CommentTok{\#relative path}
\end{Highlighting}
\end{Shaded}
The first one is an \emph{absolute path}, and the second is a
\emph{relative path}. Your clue is the leading \texttt{/} at the
beginning of a path. If you're getting \texttt{file\ not\ found}
messages, check to make sure the path is the right format.
\end{tcolorbox}
\subsection{Keep Everything in
Folders}\label{keep-everything-in-folders}
We need to talk about code and data organization. For the FH system, we
have a \texttt{/home/} directory, and if we have generated research
data, a \texttt{/fh/fast/} directory. If we want our scripts to live in
\texttt{/home/} and our data is in \texttt{/fh/temp/}, we'll need to
refer to each of these file locations.
Ideally, we want to make the naming conventions of our code and our data
as similar as possible.
\begin{tcolorbox}[enhanced jigsaw, colbacktitle=quarto-callout-note-color!10!white, left=2mm, toprule=.15mm, toptitle=1mm, opacityback=0, bottomrule=.15mm, breakable, leftrule=.75mm, colframe=quarto-callout-note-color-frame, bottomtitle=1mm, titlerule=0mm, coltitle=black, title=\textcolor{quarto-callout-note-color}{\faInfo}\hspace{0.5em}{Try it Out}, rightrule=.15mm, arc=.35mm, opacitybacktitle=0.6, colback=white]
Copy the script \texttt{tell\_the\_time.sh} in the \texttt{scripts/}
directory to your home directory.
Make the script executable.
\end{tcolorbox}
\section{What's in the script}\label{whats-in-the-script}
We can see what's in the script by using \texttt{cat}:
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{cat}\NormalTok{ tell\_the\_time.sh}
\end{Highlighting}
\end{Shaded}
And you'll get the following:
\begin{verbatim}
#!/bin/bash
date
\end{verbatim}
\section{Running a Bash Script}\label{running-a-bash-script}
Ok, now we have a bash script \texttt{tell\_the\_time.sh} in our current
directory, how do we run it?