Skip to content

Commit b7d6704

Browse files
committed
GIT, more examples for cycles and branching.
1 parent db75e6f commit b7d6704

File tree

4 files changed

+275
-42
lines changed

4 files changed

+275
-42
lines changed

presentation/git.png

259 KB
Loading

presentation/linux_bash_metacentrum_course.tex

Lines changed: 222 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,8 @@ \subsection{Searching}
15601560
find files/ -type f -exec chmod 777 '{}' \;
15611561
# Find all executable files within current directory and list them
15621562
find . -executable -type f -print
1563-
man find # See another options
1563+
find doc/ -type d -empty -execdir rmdir {} \; # Delete empty directories
1564+
man find # See another options. Much more...
15641565
\end{bashcode}
15651566
\end{frame}
15661567
@@ -2629,36 +2630,77 @@ \subsection{Branching the code}
26292630
\end{itemize}
26302631
\end{frame}
26312632
2632-
% \begin{frame}[fragile]{Selecting version of RAxML according the CPU type} % TODO RAxML branching - CPU type
2633-
% \begin{itemize}
2634-
% \item
2635-
% \end{itemize}
2636-
% \begin{bashcode}
2637-
% #
2638-
% \end{bashcode}
2639-
% \end{frame}
2633+
\begin{frame}[fragile]{Selecting version of RAxML according the CPU type I}
2634+
\begin{itemize}
2635+
\item \href{https://github.com/stamatak/standard-RAxML}{RAxML} can take advantage of modern CPUs to highly speed up calculations, with or without parallelization -- every version has separated binary, user must select, see \href{https://github.com/stamatak/standard-RAxML/blob/master/README}{README}
2636+
\item After compilation, the script can select e.g. on remote server
2637+
\item RAxML binaries must be in \texttt{\$PATH}
2638+
\item See \texttt{raxml\_if.sh} for whole script
2639+
\end{itemize}
2640+
\begin{bashcode}
2641+
if grep -iq avx2 /proc/cpuinfo; then # Does the CPU support AVX2?
2642+
RAXML='raxmlHPC-AVX2' # Select appropriate binary
2643+
elif grep -iq avx /proc/cpuinfo; then # Does the CPU support AVX?
2644+
RAXML='raxmlHPC-AVX' # Select appropriate binary
2645+
elif grep -iq sse3 /proc/cpuinfo; then # Does the CPU support SSE3?
2646+
RAXML='raxmlHPC-SSE3' # Select appropriate binary
2647+
else # The very last option
2648+
RAXML='raxmlHPC' # Slowest oldest CPU...
2649+
fi # End of branching
2650+
$RAXML -s $INPUT ... # All the parameters as usually...
2651+
\end{bashcode}
2652+
\end{frame}
26402653
2641-
% \begin{frame}[fragile]{Multiple branching in one step} % TODO Multiple branching with case
2642-
% \begin{itemize}
2643-
% \item
2644-
% \end{itemize}
2645-
% \begin{bashcode}
2646-
% #
2647-
% \end{bashcode}
2648-
% \end{frame}
2654+
\begin{frame}[fragile]{Selecting version of RAxML according the CPU type II}{Multiple branching in one step}
2655+
\begin{itemize}
2656+
\item Same task as on previous slide, but instead of it-then branching it is using \texttt{case}
2657+
\item See \texttt{raxml\_case.sh} for whole script
2658+
\end{itemize}
2659+
\begin{bashcode}
2660+
# Determine which CPU is available and which binary use then
2661+
CPUFLAGS=$(grep -i flags /proc/cpuinfo | uniq)
2662+
case "$CPUFLAGS" in
2663+
*avx2*|*AVX2*) # Does the CPU support AVX2?
2664+
RAXML='raxmlHPC-AVX2';; # Select appropriate binary
2665+
*avx*|*AVX*) # Does the CPU support AVX?
2666+
RAXML='raxmlHPC-AVX';; # Select appropriate binary
2667+
*sse3*|*SSE3*) # Does the CPU support SSE3?
2668+
RAXML='raxmlHPC-SSE3';; # Select appropriate binary
2669+
*) # The very last option
2670+
RAXML='raxmlHPC';; # Slowest oldest CPU...
2671+
esac # End of branching
2672+
$RAXML -s $INPUT # All the parameters as usually...
2673+
\end{bashcode}
2674+
\end{frame}
26492675
2650-
\subsection{Loops} % TODO More examples, break, ...
2676+
\subsection{Loops}
26512677
2652-
\begin{frame}[fragile]{For, while and until cycles}
2678+
\begin{frame}[fragile]{For cycles}
26532679
\begin{bashcode}
2654-
# One line for cycle for resizing of images
2655-
for file in *.jpg; do convert $file -resize 100x100 thumbs-$file; done
2680+
# Ways how to declare number of repetitions
2681+
for I in `seq 1 10`; do echo $I; done # "seq" is outdated
2682+
for I in 1 2 3 4 5 6 7 8 9 10; do echo $I; done
2683+
for I in {1..10}; do echo $I; done
2684+
for (( I=1; I<=10; I++ )); do echo $I; done
2685+
# One line for cycle for resizing of images (another option, as above)
2686+
for JPGF in *.jpg; do convert $JPGF -resize 100x100 thumbs-$JPGF; done
26562687
# More commands in a block
2657-
for file in `ls -1 *.jpg`; do
2658-
echo "Processing file $file"
2659-
convert $file -resize 100x100 thumbs-$file
2660-
echo thumbs-$file created
2688+
for JPGF in `ls -1 *.jpg`; do
2689+
echo "Processing JPGF $JPGF"
2690+
convert $JPGF -resize 100x100 thumbs-$JPGF
2691+
echo "File thumbs-$file created"
26612692
done
2693+
for ...; do # Start cyclus as you need
2694+
command1 # command1 will be executed in any cas
2695+
if (condition); then # Set some condition to skip command2
2696+
continue; fi # Go to next iteration of the loop and skip command2
2697+
command2
2698+
done
2699+
\end{bashcode}
2700+
\end{frame}
2701+
2702+
\begin{frame}[fragile]{While and until cycles}
2703+
\begin{bashcode}
26622704
# while cycle is evaluating expression and if it is equal to 0
26632705
# the cycle body is launched, repeatedly while the condition is met
26642706
while expression
@@ -2669,6 +2711,15 @@ \subsection{Loops} % TODO More examples, break, ...
26692711
until expression; do
26702712
commands
26712713
done
2714+
while ...; do # Start cyclus as you need
2715+
commands...
2716+
if [condition]; then # If something happens
2717+
break; fi # End up the cyclus and continue by following commands
2718+
while read TEXTLINE; do # Run cyclus on text file
2719+
commands...
2720+
done < text_file_to_process.txt
2721+
while :; do echo "Press CTRL+C to exit..."; done # Infinite loop
2722+
for (( ; ; )) ; do echo "Press CTRL+C to exit..."; done # Infinite loop
26722723
\end{bashcode}
26732724
\end{frame}
26742725
@@ -2849,13 +2900,42 @@ \subsection{Java}
28492900
\end{bashcode}
28502901
\end{frame}
28512902
2852-
% \subsection{Windows applications} % TODO Wine
2903+
\subsection{Windows applications}
28532904
2854-
% \begin{frame}{Launching of Windows and DOS applications in Linux}
2855-
% \begin{itemize}
2856-
% \item
2857-
% \end{itemize}
2858-
% \end{frame}
2905+
\begin{frame}[allowframebreaks]{Windows applications on Linux}
2906+
\begin{itemize}
2907+
\item Applications written for one operating system do not work on the other systems\ldots
2908+
\begin{itemize}
2909+
\item They must be written in portable language like Java or script like Perl, Python or BASH
2910+
\item Otherwise we need an emulator -- not everything works
2911+
\end{itemize}
2912+
\item Windows 10 has \href{https://blogs.windows.com/buildingapps/2016/07/22/fun-with-the-windows-subsystem-for-linux/}{possibility to run Linux applications}, other option (for more Windows versions) is \href{https://www.cygwin.com/}{Cygwin} (application must be specially compiled to support Cygwin)
2913+
\item To run Windows applications on Linux use \href{https://www.winehq.org/}{Wine}
2914+
\begin{itemize}
2915+
\item Search for packages named \texttt{wine} and install it
2916+
\item Sometimes, extra functionality is in extra packages -- check \texttt{wine-*}
2917+
\end{itemize}
2918+
\item To run DOS application on Linux use \href{http://www.dosbox.com/}{dosbox} (package \texttt{dosbox})
2919+
\item As soon as Wine is installed, just click to Windows \texttt{*.exe} file\ldots
2920+
\item Windows applications are installed into \texttt{$\sim$/.wine/} where Windows directory structure is created, launchers use to be placed to standard application menu into \textbf{Wine} section
2921+
\item Use \texttt{winecfg} to change settings (e.g. version of Windows -- can be different for each application, custom DLL library,~\ldots)
2922+
\item \texttt{winefile} starts Windows file browser, \texttt{notepad} Notepad, \texttt{winemine} Mines
2923+
\item To install some extra parts required by some applications use \texttt{winetricks}
2924+
\begin{itemize}
2925+
\item Usage use to differ according to distribution and GUI
2926+
\item Browsing and selecting items to install can be bit messy\ldots
2927+
\item It can be hard to check application requirements -- if it fails, check if it is listed at \url{https://appdb.winehq.org/} and/or run it from command line like \texttt{wine application.exe} and inspect errors in output
2928+
\end{itemize}
2929+
\item Before installing Windows application under Wine, check if there is some native Linux application to fit your needs\ldots
2930+
\begin{itemize}
2931+
\item Plenty of applications are available for more operating systems
2932+
\item Linux distributions use to have external contributor's sites to provide more packages
2933+
\item For many Windows-only applications there are fully comparable alternatives
2934+
\end{itemize}
2935+
\item Some applications do not work under Wine (from various reasons), some complex packages are \href{https://www.codeweavers.com/}{supported commercially} (I have no experience with it)
2936+
\item Wine is well compatible with rest of the Linux hosting system, it is considerable to install Windows in e.g. WirtualBox (or another virtualization platform), if needed
2937+
\end{itemize}
2938+
\end{frame}
28592939
28602940
\section{MetaCentrum}
28612941
@@ -3180,19 +3260,119 @@ \subsection{System services}
31803260
\end{bashcode}
31813261
\end{frame}
31823262
3183-
% \section{Git} % TODO Git
3263+
\section{Git}
31843264
3185-
% \begin{frame}[fragile]{Git and GitHub}
3186-
% \begin{itemize}
3187-
% \item \href{https://github.com/}{GitHub} is currently probably the most popular platform to host development of open-source projects
3188-
% \item \href{https://git-scm.com/}{Git} is version controlling system -- it traces changes among all versions -- absolutely crucial for any software development
3189-
% \end{itemize}
3190-
% \begin{bashcode}
3191-
% #
3192-
% \end{bashcode}
3193-
% \end{frame}
3265+
\begin{frame}[fragile]{Git and GitHub}
3266+
\begin{itemize}
3267+
\item \href{https://git-scm.com/}{Git} is \href{https://en.wikipedia.org/wiki/Version_control}{version controlling} system -- it traces changes among all versions -- absolutely crucial for any software development
3268+
\item \href{https://github.com/}{GitHub} is currently probably the most popular platform to host development of open-source projects, see \href{https://help.github.com/}{documentation}
3269+
\item Older (nowadays not so common) version controlling systems is Subversion (SVN), there are many more
3270+
\item Probably the best textbook for Git is \href{https://git-scm.com/book/en/v2}{Chacon's Pro Git}
3271+
\begin{itemize}
3272+
\item Dostupná i~\href{https://git-scm.com/book/cs/v2}{česky} (včetně \href{https://knihy.nic.cz/}{prvního vydání})
3273+
\end{itemize}
3274+
\item Changes and their history is stored in repository (local or network, shared or private) -- it is possible to view any historical state and differences between any versions
3275+
\item It is possible to trace who and when did what
3276+
\item Branching and merging of branches helps with making of big changes
3277+
\end{itemize}
3278+
\end{frame}
3279+
3280+
\begin{frame}[fragile]{Git principles}
3281+
\begin{multicols}{2}
3282+
\begin{itemize}
3283+
\item Three main areas
3284+
\begin{enumerate}
3285+
\item Working directory
3286+
\item Staging (changes awaiting to be pushed to the repository)
3287+
\item Git repository (remote/local)
3288+
\end{enumerate}
3289+
\item Everyone has whole repository and history -- very robust
3290+
\item Flexible branches
3291+
\begin{itemize}
3292+
\item Very convenient
3293+
\item Keeping work structured
3294+
\item Separation of tasks
3295+
\item Keeping more versions of the project in parallel
3296+
\end{itemize}
3297+
\end{itemize}
3298+
\begin{center}
3299+
\includegraphics[height=5.75cm]{git.png}
3300+
\end{center}
3301+
\begin{flushright}
3302+
\begin{footnotesize}
3303+
\href{https://git-scm.com/book/en/v2/Getting-Started-Git-Basics}{https://git-scm.com/}, \href{http://nvie.com/posts/a-successful-git-branching-model/}{http://nvie.com/}
3304+
\end{footnotesize}
3305+
\end{flushright}
3306+
\end{multicols}
3307+
\end{frame}
31943308
3195-
\section{The end}
3309+
\begin{frame}[fragile]{Working with Git -- start and sending changes}
3310+
\begin{bashcode}
3311+
# Create a new repository for new project
3312+
git init # No need when cloning from existing repository
3313+
# Or checkout (make a copy) for another local or remote repository
3314+
git clone /path/to/local/repository # Locally mounted repository
3315+
git clone username@host:/path/to/remote/repository # Over SSH
3316+
git clone https://github.com/V-Z/course-linux-command-line-bash-
3317+
scripting-metacentrum.git # Clone from web, e.g. GitHub
3318+
# Add files to trace with Git
3319+
# Ignored files (or patterns) can be listed in .gitignore file
3320+
git add <files> # Or "git add *"
3321+
# Commit changes to prepare then to send to repository
3322+
git commit -m "Message..."
3323+
# If you did not start by cloning, add connection to server
3324+
git remote add origin <location> # Do only once on the beginning
3325+
# <location> can be remote server or local path
3326+
git remote add origin . # For repository within working directory
3327+
# Push changes into the (regardless where it is) repository
3328+
git push origin master # See further for selection of branches
3329+
\end{bashcode}
3330+
\end{frame}
3331+
3332+
\begin{frame}[fragile]{Working with Git -- branching and getting changes}
3333+
\begin{bashcode}
3334+
# Making new branch and switching to it
3335+
git checkout -b NewFeature # Now we are in branch NewFeature
3336+
# Switch back to branch master
3337+
git checkout master # Generally, "git checkout <branch>"
3338+
# Delete the branch (changes there are lost, must be in another branch)
3339+
git branch -d NewFeature # Delete local branch, to delete remote do:
3340+
git push origin --delete <branch>
3341+
# Branch must be also pushed to the remote server
3342+
git push origin <branch>
3343+
# List branches (current is marked by asterisk on the beginning)
3344+
git branch
3345+
# Update local repository to the newest version from central repository
3346+
git pull # Fetch and merge remote changes
3347+
# Merge another branch into the current one
3348+
git merge <branch>
3349+
# In case of conflict, git shows editor and user must fix it manually
3350+
git add <file with conflict> # Needed to re-add conflicting file
3351+
# To see changes before merging
3352+
git diff <source_branch> <target_branch>
3353+
\end{bashcode}
3354+
\end{frame}
3355+
3356+
\begin{frame}[fragile]{Working with Git -- tags, logs and settings}
3357+
\begin{bashcode}
3358+
# Tagging e.g. milestones, released versions of software, etc.
3359+
git tag <name> <commit id> # <name> can be custom, <commit id> from log:
3360+
git log # Newest is on top, see also "git log --help"
3361+
git log --graph --oneline --decorate --all # Full long log
3362+
# Discard local changes for particular file
3363+
git checkout -- <file>
3364+
# Discard all local changes
3365+
git fetch origin # Overwrite local changes
3366+
git reset --hard origin/master # If local repository is broken...
3367+
gitk # Graphical interface
3368+
git config color.ui true # Set output to be colored
3369+
git config format.pretty oneline # Nicer log output
3370+
~/.git # Contains user's settings, .git in every repository contains
3371+
# data and settings for particular repository
3372+
\end{bashcode}
3373+
\end{frame}
3374+
3375+
\section{The End}
31963376
31973377
% \subsection{Switching to Linux} % TODO Switching
31983378

scripts/raxml_case.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Script takes one single parameter - name of input file, e.g. "./raxml_if.sh input.fasta"
4+
5+
INPUT="$1" # Specification of input file
6+
7+
# Determine which CPU is available and which binary use then
8+
CPUFLAGS=$(grep -i flags /proc/cpuinfo | uniq)
9+
10+
case "$CPUFLAGS" in
11+
*avx2*|*AVX2*) # Does the CPU support AVX2?
12+
RAXML='raxmlHPC-AVX2' # Select appropriate binary
13+
;;
14+
*avx*|*AVX*) # Does the CPU support AVX?
15+
RAXML='raxmlHPC-AVX' # Select appropriate binary
16+
;;
17+
*sse3*|*SSE3*) # Does the CPU support SSE3?
18+
RAXML='raxmlHPC-SSE3' # Select appropriate binary
19+
;;
20+
*) # The very last option
21+
RAXML='raxmlHPC' # Slowest oldest CPU...
22+
;;
23+
esac # End of branching
24+
25+
# Tell us the result
26+
echo "Using $RAXML binary."
27+
28+
$RAXML -s $INPUT # All the parameters as usually...
29+
30+
exit

scripts/raxml_if.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Script takes one single parameter - name of input file, e.g. "./raxml_if.sh input.fasta"
4+
5+
INPUT="$1" # Specification of input file
6+
7+
# Determine which CPU is available and which binary use then
8+
if grep -iq avx2 /proc/cpuinfo; then # Does the CPU support AVX2?
9+
RAXML='raxmlHPC-AVX2' # Select appropriate binary
10+
elif grep -iq avx /proc/cpuinfo; then # Does the CPU support AVX?
11+
RAXML='raxmlHPC-AVX' # Select appropriate binary
12+
elif grep -iq sse3 /proc/cpuinfo; then # Does the CPU support SSE3?
13+
RAXML='raxmlHPC-SSE3' # Select appropriate binary
14+
else # The very last option
15+
RAXML='raxmlHPC' # Slowest oldest CPU...
16+
fi # End of branching
17+
18+
# Tell us the result
19+
echo "Using $RAXML binary."
20+
21+
$RAXML -s $INPUT # All the parameters as usually...
22+
23+
exit

0 commit comments

Comments
 (0)