15-min Recap: From pwd to mamba create

Narrative thread: “You just logged in. Let’s trace what you’d actually do in the first hour of a new project.”


1. Where am I? (2 min)

pwd                     # print working directory
ls                      # what's here?
ls -lh                  # sizes, permissions, dates
ls -lh ~/               # same for home
cd data/                # move around
cd ..                   # go up
cd ~                    # go home

Key point: absolute vs relative paths, ~ shortcut.


2. Set up project structure (2 min)

mkdir project1
mkdir project1/data  project1/results
touch project1/README.txt
cp somefile.txt project1/data/
mv project1/data/somefile.txt project1/data/input.txt
rm project1/README.txt

Key point: filesystem is a tree; build it intentionally from day one.


3. Wildcards + pipes + redirects (2 min)

ls *.fq                     # wildcard matching
ls *.fq | wc -l             # how many FASTQ files?
ls *.tsv >> file_list.txt   # append to a log

Key point: | chains commands; > writes (overwrites!), >> appends. Check with ls before acting on wildcards.


4. Look inside files (3 min)

head -n 5 genes.tsv
tail -n 20 genes.tsv
less genes.tsv          # q to quit, / to search
wc -l genes.tsv         # line count

Then filter rows:

grep "protein_coding" genes.tsv       # lines matching pattern
grep -c "chr1" genes.tsv              # count matches
grep -i "brca" genes.tsv             # case-insensitive
awk '$3 > 10000' genes.tsv            # numeric filter on column 3

Key point: grep for rows, awk for math/numeric conditions — chain them with pipes.


5. Download a TSV/CSV and work with it (3 min)

curl -L -o genes.tsv https://example.org/genes.tsv
head -n 3 genes.tsv          # check the header

Extract and reshape columns:

cut -f1,3 genes.tsv              # columns 1 and 3 (tab-delimited)
cut -d',' -f2 genes.csv          # column 2 from a CSV
cut -f1,3 genes.tsv | head -n 5  # preview the extraction

Sort the results:

sort genes.tsv                       # alphabetical on column 1
sort -k2,2 genes.tsv                 # sort by column 2
sort -k3,3n genes.tsv                # numeric sort on column 3
sort -k3,3nr genes.tsv               # reverse numeric (largest first)
sort -u genes.tsv                    # unique lines only
cut -f1 genes.tsv | sort -u | wc -l # count unique values in column 1

Key point: cut selects columns, sort orders rows — together they are your quickest path from a raw table to a meaningful summary.


6. Why mamba? (1 min — concept only)

Problem: bioinformatics tools conflict. Tool A needs Python 3.8, Tool B needs 3.11. Solution: isolated environments.

  • Conda = package + environment manager
  • Mamba = same but faster
  • conda-forge / bioconda = the free channels we use

7. mamba create (3 min)

mamba search samtools            # what versions exist?
mamba create --name myproject samtools=1.21
mamba activate myproject
samtools --version               # confirm it's live
mamba list                       # what's installed?
mamba env list                   # all environments
mamba install fastqc=0.12.1      # add a package
mamba deactivate

Key point: always name the version. The environment is a directory — activate just prepends its bin/ to $PATH.

Bonus line:

mamba env export --from-history > myproject.yml   # reproducibility

Wrap-up (30 sec)

pwd/ls/cd  →  mkdir/cp/mv/rm  →  wildcards+pipes  →  head/grep/awk  →  curl+cut+sort  →  mamba
  where am I    structure          pattern matching     row filtering     column work      install tools

Everything feeds into everything else: you curl a table, cut the columns you need, sort by a numeric field, grep for hits — all with the tool you installed via mamba.


Previous submodule: