Last updated: 2022-03-07

Checks: 7 0

Knit directory: wildlife-ticks/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20210211) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 7b4fd7e. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/_footer.html
    Ignored:    output/.DS_Store
    Ignored:    output/plots/.DS_Store

Untracked files:
    Untracked:  .Rprofile
    Untracked:  ENA_submission/
    Untracked:  NCBI_submission/
    Untracked:  analysis/images/
    Untracked:  data/
    Untracked:  experiments/
    Untracked:  flex.Rmd
    Untracked:  flex.html
    Untracked:  list.csv
    Untracked:  output/plots/allmap1.pdf
    Untracked:  output/plots/allmap2.pdf
    Untracked:  output/plots/allmapala1.pdf
    Untracked:  output/plots/allmapala2.pdf
    Untracked:  output/plots/combined-map5.pdf
    Untracked:  output/plots/combined-map6.pdf
    Untracked:  output/plots/combined-map7.pdf
    Untracked:  output/plots/combined-map8.pdf
    Untracked:  output/plots/map-ala.html
    Untracked:  output/plots/map-ala_files/
    Untracked:  output/plots/map-all-ala.html
    Untracked:  output/plots/map-all-ala_files/
    Untracked:  output/plots/map-all-curated.html
    Untracked:  output/plots/map-all-curated_files/
    Untracked:  output/plots/map-atrig-facet-edit.pdf
    Untracked:  output/plots/map-atrig-facet-edit.png
    Untracked:  output/plots/map-atrig-facet-edit.svg
    Untracked:  output/plots/map-atrig-subspecies1.pdf
    Untracked:  output/plots/map-atrig-subspecies2.pdf
    Untracked:  output/plots/map-atrig1.pdf
    Untracked:  output/plots/map-atrig2.pdf
    Untracked:  output/plots/map-ixhol1-edit.pdf
    Untracked:  output/plots/map-ixhol1-edit.png
    Untracked:  output/plots/map-ixhol1-edit.svg
    Untracked:  output/plots/map-ixtas1-edit.pdf
    Untracked:  output/plots/map-ixtas1-edit.png
    Untracked:  output/plots/map-ixtas1-edit.svg
    Untracked:  output/plots/maplegend-ala.pdf
    Untracked:  output/plots/maplegend-edit.pdf
    Untracked:  output/plots/maplegend-edit.png
    Untracked:  output/plots/maplegend-edit.svg
    Untracked:  output/plots/maplegend.pdf
    Untracked:  speciesNames.csv
    Untracked:  temp/

Unstaged changes:
    Modified:   README.md
    Modified:   analysis/_site.yml
    Deleted:    analysis/mapping.Rmd
    Deleted:    output/plots/combined-map.pdf
    Modified:   output/plots/combined-map1.pdf
    Modified:   output/plots/combined-map2.pdf
    Modified:   output/plots/combined-map3.pdf
    Modified:   output/plots/combined-map4.pdf
    Deleted:    output/plots/map-atrig-comb-nolegend.pdf
    Deleted:    output/plots/map-atrig-comb.pdf
    Modified:   output/plots/map-atrig-facet.pdf
    Deleted:    output/plots/map-atrig-simple1.pdf
    Deleted:    output/plots/map-atrig-simple2.pdf
    Modified:   output/plots/map-ixhol1.pdf
    Modified:   output/plots/map-ixhol2.pdf
    Modified:   output/plots/map-ixtas1.pdf
    Modified:   output/plots/map-ixtas2.pdf

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/Ixodida12SNGS.Rmd) and HTML (docs/Ixodida12SNGS.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 7b4fd7e Siobhon Egan 2022-03-07 Update prj website

Bioinformatics

Retrieve information for GenBank sequences used in the 12S rDNA phylogenetic analysis.

library(readxl)
df <- read_excel("data/12S_zotu_tree/MAFFT_aln_one_outgroup_refined_highlighted.xlsx")
View(df)
library(ape)
ref <- df$GenBank
## Copy/paste or type the following commands if you
## want to try them.
# }
# NOT RUN {
Rampho <- read.GenBank(ref)
## get the species names:
attr(Rampho, "species")
## build a matrix with the species names and the accession numbers:
sp <- cbind(attr(Rampho, "species"), names(Rampho))
write.csv(sp, "data/12S_zotu_tree/speciesNames.csv")
## print the first sequence
## (can be done with `Rampho$U15717' as well)
Rampho[[1]]
## the description from each FASTA sequence:
attr(Rampho, "description")
# }

Analysis of high-throughput 12S rDNA data

source(../code/usearch11_12S_Ixodida.sh)
# Enter raw data directorry
raw_data="raw_data"
# Enter raw read information on raw sequences
read_summary="1.read_sumary"
# Enter directory for merged output
merged_data="2.merged_data"
# Enter max diff for merging - default 5 but should increase for paired end
maxdiffs="15"
# Enter minimum merge overlap - default is 16 bp
overlap="20"
# Enter directory for sequences that are matched to primers
primer_matched="3a.primer_matches"
# Enter directory for sequences that do not match primers
primer_not_matched="3b.primer_not_matched"
# Enter forward sequences (5'-3'). Wildcard letters indicating degenerate positions in the primer are supported. See IUPAC(https://drive5.com/usearch/manual/IUPAC_codes.html) codes for details.
fwd_primer="AAACTAGGATTAGATACCCT" #12S Ixodida primer T1B, ref Beati and Keirans, J Parasitol (2001) 87(1):32-48
rev_primer="AATGAGAGCGACGGGCGATGT" #12S Ixodida primer T2A, ref Beati and Keirans, J Parasitol (2001) 87(1):32-48
# Enter directory for quality filtered output
QF="4.quality_filtered"
# Enter max error rate. Natural choice is 1, however may want to decrease to 0.5 or 0.25 for more stringent filtering.
max_ee="1"
# Enter min length of sequence for trimming in bp (eg. to keep all seqs above 200 bp enter "200")
minlen="150"
# Enter directory for labeled data
labeled_data="5.labeled_data"
# Enter directory for dereplicated sequences
derep_dir="6.derep_data"
# Enter directory for singlteton filter data
SF="7.singleton_filtered"
# Enter directory for singlteton sequences
low_abund_seqs="8.singleton_sequences"
# Enter max size to discard i.e. to discard singletons = 1, duplicates = 2
maxsize="1"
# Enter directory for sequence clustering
cluster="9.cluster"
# Enter sub-directory for uparse_otu clustering
uparse_otus="9a.otus"
# Enter sub-directory for unoise_zotu clustering
unoise_zotus="9b.zotus"


##########################################################################################
# DO NOT EDIT BELOW THIS LINE
##########################################################################################

##########################################################################################

gunzip ${raw_data}/*.fastq.gz

#echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#echo Read summary of raw .fastq sequences
#echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Prouduce a short summary report of raw fastq sequences using `-fastx_info` command.
# Expected error should be <2 for both forward and reverse reads. Usually reverse reads have a higher error rate.

#mkdir $read_summary

#for fq in $raw_data/*R1*.fastq
#  do
#    echo ""
#    echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#    echo "fastq_info forward reads"
#
#    usearch11.0.667_i86osx64 -fastx_info $fastq -output $read_summary/a_fwd_fastq_info.txt
#done

#for fq in $raw_data/*R2*.fastq
#  do
#    echo ""
#    echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#    echo "fastq_info forward reads"

#    usearch11.0.667_i86osx64 -fastx_info $fastq -output $read_summary/b_rev_fastq_info.txt
#done

##########################################################################################

echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo Merging paried illumina .fastq sequences
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Merge paired-end reads using `-fastq_mergepairs` command, and rename sequences. This would be done before primers are trimmed.

mkdir ${merged_data}
mkdir working1

#*****************************************************************************************
# Part 1: merge reads

for file1 in ${raw_data}/*R1.fastq
  do
    echo ""
        echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        echo Merging paired reads
        echo forward reads are:
        echo $(basename ${file1})
        echo reverse reads are:
        echo $(basename ${file1} R1.fastq)R2.fastq

    usearch11.0.667_i86osx64 -fastq_mergepairs ${file1} -reverse "${raw_data}/$(basename -s R1.fastq ${file1})R2.fastq" -fastqout "working1/$(basename "$file1")" -fastq_maxdiffs ${maxdiffs} -fastq_minovlen ${overlap} -report ${merged_data}/2a_merging_seqs_report.txt -tabbedout ${merged_data}/2b_tabbedout.txt
done

#*****************************************************************************************
# Part 2: Remove "_L001_R1_001" from filenames

for file2 in working1/*.fastq
    do
        rm -rfile2} _L001_R1.fastq).fastq"
    mv ${file2} ${merged_data}/${rename}
done

#*****************************************************************************************
# Removing working directory

rm -r working1

##########################################################################################

echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo Triming primers and distal bases
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# The `-search_pcr2` command searches for matches to a primer pair and outputs the sequence in between (i.e. amplicon with primers removed) into `primer_matched` file

mkdir ${primer_matched}
mkdir ${primer_not_matched}

for file3 in ${merged_data}/*.fastq
    do

    usearch11.0.667_i86osx64 -search_pcr2 ${file3} -fwdprimer ${fwd_primer} \
    -revprimer ${rev_primer} \
    -strand both -fastqout "${primer_matched}/$(basename ${file3})" -notmatchedfq "${primer_not_matched}/$(basename ${file3})" -tabbedout ${primer_matched}pcr2_output.txt
done

##########################################################################################

echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo Quality control and removing dimer seqs
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Quality filtering of fastq files using the `-fastq_filter` command, output gives fasta files.

mkdir ${QF}

for file4 in ${primer_matched}/*.fastq
    do
        echo ""
        echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        echo Quality control and removing dimer seqs
        echo input is:
        echo ${file4}

    usearch11.0.667_i86osx64 -fastq_filter ${file4} -fastaout "${QF}/$(basename "$file4" .fastq).fasta" -fastq_maxee ${max_ee} -fastq_minlen ${minlen}
done

##########################################################################################

echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo Renameing sequences with ">barcodelabel=sample_id;sequence_id"
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# For this script to run correctly input fasta label must be formatted >sequence_id and filename must be sample_id.fasta.
# Result will be ">barcodelabel=sample_id;sequenceid"

mkdir ${labeled_data}
mkdir working2

#*****************************************************************************************
# Part 1: Remove ">" from start of sequence_ID

for file5 in ${QF}/*.fasta
    do
        sed -e 's/>/>barcodelabel=;/g' ${file5} > working2/$(basename "$file5" .fasta).txt
done

#*****************************************************************************************
# Part 2: Add sample_ID (should be filename) to produce ">barcodelabel=sample_ID;sequence_ID"

for file6 in working2/*.txt
    do
        sample_id=$(basename ${file6} .txt)
        echo ${sample_id}

    sed -e "s/;/${sample_id};/g" ${file6} > "${labeled_data}/$(basename "$file6" .txt).fasta"
done

#*****************************************************************************************
# Remove working directories

rm -r working2

################################################################################################

echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo Removing low abundant seqs singletons per sample
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Remove low abundant sequences (e.g. singletons) in samples using the `-fastx_uniques` command

mkdir ${derep_dir}
mkdir ${SF}
mkdir ${low_abund_seqs}

#*****************************************************************************************
# Part 1: Dereplicating

for file7 in ${labeled_data}/*.fasta
    do
        echo ""
        echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        echo Removing singletons step 1: derep_fulllength
        echo input is:
        echo ${file7}

        usearch11.0.667_i86osx64 -fastx_uniques ${file7} -fastaout "${derep_dir}/$(basename "$file7" .fasta).fasta" -sizeout
done

#*****************************************************************************************
# Part 2: Filtering low abundant seqs {maxsize}

for file8 in ${derep_dir}/*.fasta
    do
        echo ""
        echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        echo Removing singletons step 2: sorting uniques
        echo input is:
        echo ${file8}

        usearch11.0.667_i86osx64 -sortbysize ${file8} -fastaout "${low_abund_seqs}/$(basename "$file8" .fasta).fasta" -maxsize ${maxsize}
done

#*****************************************************************************************
# Step 3: Mapping reads

for file9 in ${labeled_data}/*.fasta
    do
      echo ""
      echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      echo Removing singletons step 3: mapping reads to low abundant uniques
      echo input is:
      echo ${file9}

      usearch11.0.667_i86osx64 -search_exact ${file9} -db "${low_abund_seqs}/$(basename "$file9" .fasta).fasta" -strand plus -notmatched "${SF}/$(basename "$file9" .fasta).fasta"
done

################################################################################################
################################################################################################

echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo CLUSTERING
echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Concatenate all singleton filter sequences into a single fasta file
# Find the set of unique sequences in an input file, also called dereplication using `-fastx_uniques` command

mkdir ${cluster}

cat ${SF}/*.fasta > ${cluster}/all_SF.fasta

cd ${cluster}

usearch11.0.667_i86osx64 -fastx_uniques all_SF.fasta -fastaout all_SF_DR.fasta -sizeout

#*****************************************************************************************

echo ----------------------------------------------------------------------------
echo Part a - Generating UPARSE OTUs
echo ----------------------------------------------------------------------------

# Cluster sequences in 97% operational taxonomic units (OTUs) using UPARSE algorithm `-cluster_otus` command and generate an OTU table

mkdir ${uparse_otus}
cd ${uparse_otus}

    usearch11.0.667_i86osx64 -cluster_otus ../all_SF_DR.fasta -otus uparse_otus.fasta -relabel OTU

  usearch11.0.667_i86osx64 -usearch_global ../all_SF.fasta -db uparse_otus.fasta -strand both -id 0.97 -otutabout uparse_otu_tab.txt -biomout uparse_otu_biom.biom

  # The next two lines produce a distance matrix file and then a tree (newick format)
  # Current parameters are a guide only and you will need to optimse them for your data
  # Large datasets can take a long time, so you can skip this part for now to speed up analysis

#  usearch11.0.667_i86osx64 -calc_distmx uparse_otus.fasta -tabbedout uparse_otus_distmx.txt -maxdist 0.2 -termdist 0.3

#   usearch11.0.667_i86osx64 -cluster_aggd uparse_otus_distmx.txt -treeout uparse_otus_clusters.tree -clusterout uparse_otus_clusters.txt \
#     -id 0.80 -linkage min
cd ..

#*****************************************************************************************

echo ----------------------------------------------------------------------------
echo Part b - Generating UNOISE ZOTUs
echo ----------------------------------------------------------------------------

# Cluster sequences in zero-radius operational taxonomic units (ZOTUs) using `-unoise3` command and generate a ZOTU table

mkdir ${unoise_zotus}
cd ${unoise_zotus}

usearch11.0.667_i86osx64 -unoise3 ../all_SF_DR.fasta -zotus unoise_zotus.fasta -tabbedout unoise_tab.txt

usearch11.0.667_i86osx64 -fastx_relabel unoise_zotus.fasta -prefix Otu -fastaout unoise_zotus_relabeled.fasta -keep_annots

usearch11.0.667_i86osx64 -otutab ../all_SF.fasta -zotus unoise_zotus_relabeled.fasta -otutabout unoise_otu_tab.txt -biomout unoise_otu_biom.biom -mapout unoise_map.txt -notmatched unoise_notmatched.fasta -dbmatched dbmatches.fasta -sizeout

  # The next two lines produce a distance matrix file and then a tree (newick format)
  # Current parameters are a guide only and you will need to optimse them for your data
  # Large datasets can take a long time, so you can skip this part for now to speed up analysis

#  usearch11.0.667_i86osx64 -calc_distmx unoise_zotus.fasta -tabbedout unoise_zotus_distmx.txt -maxdist 0.2 -termdist 0.3

#  usearch11.0.667_i86osx64 -cluster_aggd unoise_zotus_distmx.txt -treeout unoise_zotus_clusters.tree -clusterout unoise_zotus_clusters.txt \
#    -id 0.80 -linkage min
cd ..
cd ..

sessionInfo()

Project website by Siobhon L. Egan, 2022. This site was created in R Markdown with workflowr