{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Use taxonomic read classifications from MEGAN6 to extract Phylum-specific FastQs from Arthropoda and Alveolata" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "TODAY'S DATE:\n", "Wed Jan 22 14:30:07 PST 2020\n", "------------\n", "\n", "Distributor ID:\tUbuntu\n", "Description:\tUbuntu 16.04.6 LTS\n", "Release:\t16.04\n", "Codename:\txenial\n", "\n", "------------\n", "HOSTNAME: \n", "swoose\n", "\n", "------------\n", "Computer Specs:\n", "\n", "Architecture: x86_64\n", "CPU op-mode(s): 32-bit, 64-bit\n", "Byte Order: Little Endian\n", "CPU(s): 24\n", "On-line CPU(s) list: 0-23\n", "Thread(s) per core: 2\n", "Core(s) per socket: 6\n", "Socket(s): 2\n", "NUMA node(s): 1\n", "Vendor ID: GenuineIntel\n", "CPU family: 6\n", "Model: 44\n", "Model name: Intel(R) Xeon(R) CPU X5670 @ 2.93GHz\n", "Stepping: 2\n", "CPU MHz: 2925.783\n", "BogoMIPS: 5851.61\n", "Virtualization: VT-x\n", "L1d cache: 32K\n", "L1i cache: 32K\n", "L2 cache: 256K\n", "L3 cache: 12288K\n", "NUMA node0 CPU(s): 0-23\n", "Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 popcnt aes lahf_lm epb ssbd ibrs ibpb stibp kaiser tpr_shadow vnmi flexpriority ept vpid dtherm ida arat flush_l1d\n", "\n", "------------\n", "\n", "Memory Specs\n", "\n", " total used free shared buff/cache available\n", "Mem: 70G 5.4G 410M 547M 65G 64G\n", "Swap: 4.7G 777M 3.9G\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "No LSB modules are available.\n" ] } ], "source": [ "%%bash\n", "echo \"TODAY'S DATE:\"\n", "date\n", "echo \"------------\"\n", "echo \"\"\n", "#Display operating system info\n", "lsb_release -a\n", "echo \"\"\n", "echo \"------------\"\n", "echo \"HOSTNAME: \"; hostname \n", "echo \"\"\n", "echo \"------------\"\n", "echo \"Computer Specs:\"\n", "echo \"\"\n", "lscpu\n", "echo \"\"\n", "echo \"------------\"\n", "echo \"\"\n", "echo \"Memory Specs\"\n", "echo \"\"\n", "free -mh" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set variables" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "env: crab_data=/home/sam/data/C_bairdi/RNAseq\n", "env: hemat_data=/home/sam/data/Hematodinium/RNAseq\n", "env: wd=/home/sam/analyses\n", "env: seqtk=/home/sam/programs/seqtk-1.3/seqtk\n" ] } ], "source": [ "# Set data directories\n", "%env crab_data=/home/sam/data/C_bairdi/RNAseq\n", "%env hemat_data=/home/sam/data/Hematodinium/RNAseq\n", "%env wd=/home/sam/analyses\n", "\n", "# Programs\n", "%env seqtk=/home/sam/programs/seqtk-1.3/seqtk" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Input data are here:\n", "\n", "FastAs: https://gannet.fish.washington.edu/Atumefaciens/20200114_cbai_MEGAN_read_extractions/\n", "\n", "Trimmed-FastQs: https://gannet.fish.washington.edu/Atumefaciens/20191218_cbai_fastp_RNAseq_trimming/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Extract phylum-specific reads from trimmed FastQ files\n", "\n", "\n", "Use FastA IDs from MEGAN6 taxonomic read extraction FastAs to pull out appropriate reads from each phylum (Arthropoda and Alveolata). This is performed because MEGAN6 strips paired read ID after the first space. As such, the resulting read extractions using MEGAN end up with a FastA file containing two reads with identicial headers. Not sure if this will cause any downstream issues (i.e. with Trinity) where paired end data is used, so playing it safe and using the truncated IDs to pull FastQs with complete sequence headers for use in subsequent data wrangling." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Finished with FastA ID extraction.\n", "\n", "Moving on to read extractions...\n", "\n", "\n", "Extracting R1 reads from /home/sam/data/C_bairdi/RNAseq/304428_S1_L001_R1_001.fastp-trim.201912183855.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/C_bairdi/RNAseq/304428_S1_L002_R1_001.fastp-trim.201912184416.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/C_bairdi/RNAseq/329774_S1_L001_R1_001.fastp-trim.201912184855.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/C_bairdi/RNAseq/329774_S1_L002_R1_001.fastp-trim.201912185239.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/C_bairdi/RNAseq/329775_S2_L001_R1_001.fastp-trim.201912185554.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/C_bairdi/RNAseq/329775_S2_L002_R1_001.fastp-trim.201912185856.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/C_bairdi/RNAseq/329776_S3_L001_R1_001.fastp-trim.201912180142.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/C_bairdi/RNAseq/329776_S3_L002_R1_001.fastp-trim.201912180540.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/C_bairdi/RNAseq/329777_S4_L001_R1_001.fastp-trim.201912180900.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/C_bairdi/RNAseq/329777_S4_L002_R1_001.fastp-trim.201912181245.fq.gz\n", "\n", "\n", "Done with R1 read extractions\n", "\n", "------------\n", "\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/329777_S4_L002_R1_001.fastp-trim.201912181245.fq.gz\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/304428_S1_L001_R2_001.fastp-trim.201912183855.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/304428_S1_L002_R2_001.fastp-trim.201912184416.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/329774_S1_L001_R2_001.fastp-trim.201912184855.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/329774_S1_L002_R2_001.fastp-trim.201912185239.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/329775_S2_L001_R2_001.fastp-trim.201912185554.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/329775_S2_L002_R2_001.fastp-trim.201912185856.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/329776_S3_L001_R2_001.fastp-trim.201912180142.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/329776_S3_L002_R2_001.fastp-trim.201912180540.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/329777_S4_L001_R2_001.fastp-trim.201912180900.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/C_bairdi/RNAseq/329777_S4_L002_R2_001.fastp-trim.201912181245.fq.gz\n", "\n", "-------------------------------------\n", "/home/sam/analyses/20200122.C_bairdi_megan_reads\n", "total 19G\n", "-rw-rw-r-- 1 sam sam 1.3G Jan 22 12:50 20200122.C_bairdi.seqtk.read_id.list\n", "-rw-rw-r-- 1 sam sam 8.9G Jan 22 13:10 20200122.C_bairdi.megan_R1.fq\n", "-rw-rw-r-- 1 sam sam 8.9G Jan 22 13:29 20200122.C_bairdi.megan_R2.fq\n", "\n", "-------------------------------------\n", "\n", "\n", "Finished with FastA ID extraction.\n", "\n", "Moving on to read extractions...\n", "\n", "\n", "Extracting R1 reads from /home/sam/data/Hematodinium/RNAseq/304428_S1_L001_R1_001.fastp-trim.201912183855.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/Hematodinium/RNAseq/304428_S1_L002_R1_001.fastp-trim.201912184416.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/Hematodinium/RNAseq/329774_S1_L001_R1_001.fastp-trim.201912184855.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/Hematodinium/RNAseq/329774_S1_L002_R1_001.fastp-trim.201912185239.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/Hematodinium/RNAseq/329775_S2_L001_R1_001.fastp-trim.201912185554.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/Hematodinium/RNAseq/329775_S2_L002_R1_001.fastp-trim.201912185856.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/Hematodinium/RNAseq/329776_S3_L001_R1_001.fastp-trim.201912180142.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/Hematodinium/RNAseq/329776_S3_L002_R1_001.fastp-trim.201912180540.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/Hematodinium/RNAseq/329777_S4_L001_R1_001.fastp-trim.201912180900.fq.gz\n", "\n", "Extracting R1 reads from /home/sam/data/Hematodinium/RNAseq/329777_S4_L002_R1_001.fastp-trim.201912181245.fq.gz\n", "\n", "\n", "Done with R1 read extractions\n", "\n", "------------\n", "\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/329777_S4_L002_R1_001.fastp-trim.201912181245.fq.gz\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/304428_S1_L001_R2_001.fastp-trim.201912183855.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/304428_S1_L002_R2_001.fastp-trim.201912184416.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/329774_S1_L001_R2_001.fastp-trim.201912184855.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/329774_S1_L002_R2_001.fastp-trim.201912185239.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/329775_S2_L001_R2_001.fastp-trim.201912185554.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/329775_S2_L002_R2_001.fastp-trim.201912185856.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/329776_S3_L001_R2_001.fastp-trim.201912180142.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/329776_S3_L002_R2_001.fastp-trim.201912180540.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/329777_S4_L001_R2_001.fastp-trim.201912180900.fq.gz\n", "\n", "Extracting R2 reads from /home/sam/data/Hematodinium/RNAseq/329777_S4_L002_R2_001.fastp-trim.201912181245.fq.gz\n", "\n", "-------------------------------------\n", "/home/sam/analyses/20200122.Hematodinium_megan_reads\n", "total 947M\n", "-rw-rw-r-- 1 sam sam 64M Jan 22 13:29 20200122.Hematodinium.seqtk.read_id.list\n", "-rw-rw-r-- 1 sam sam 442M Jan 22 13:36 20200122.Hematodinium.megan_R1.fq\n", "-rw-rw-r-- 1 sam sam 442M Jan 22 13:44 20200122.Hematodinium.megan_R2.fq\n", "\n", "-------------------------------------\n", "\n" ] } ], "source": [ "%%bash\n", "\n", "timestamp=$(date +%Y%m%d)\n", "\n", "\n", "for directory in ${crab_data} ${hemat_data}\n", "do\n", "\t# Get species name\n", "\tspecies=$(echo ${directory} | awk -F\"/\" '{print $5}')\n", " \n", " # Make new directory and change to that directory (\"$_\" means use previous command's argument)\n", " mkdir --parents ${wd}/\"${timestamp}\".\"${species}\"_megan_reads \\\n", " && cd \"$_\" || exit\n", "\n", "\t# Set seqtk list filename\n", "\tseqtk_list=${timestamp}.${species}.seqtk.read_id.list\n", "\n", "\t# Set output FastQ filenames\n", "\tR1_fq=${timestamp}.${species}.megan_R1.fq\n", "\tR2_fq=${timestamp}.${species}.megan_R2.fq\n", "\n", "\t######################################################\n", "\t# Create FastA IDs list to use for sequence extraction\n", "\t######################################################\n", "\tfor fasta in \"${directory}\"/*.fasta\n", "\tdo\n", " echo \"Pulling FastA IDs from ${fasta}\"\n", " echo \"\"\n", " grep \">\" \"${fasta}\" | awk 'sub(/^>/, \"\")'\n", "\tdone | sort -u >> \"${seqtk_list}\"\n", " \n", " \n", " echo \"\"\n", " echo \"Finished with FastA ID extraction.\"\n", " echo \"\"\n", " echo \"Moving on to read extractions...\" \n", " echo \"\"\n", " echo \"\"\n", " \n", " \n", " ######################################################\n", "\t# Extract corresponding R1 and R2 reads using seqtk FastA ID list\n", " ######################################################\n", "\tfor fastq in \"${directory}\"/*R1*.gz\n", "\tdo\n", " echo \"Extracting R1 reads from ${fastq}\"\n", " echo \"\"\n", "\t ${seqtk} subseq \"${fastq}\" \"${seqtk_list}\" >> \"${R1_fq}\"\n", "\tdone\n", " \n", " echo \"\"\n", " echo \"Done with R1 read extractions\"\n", " echo \"\"\n", " echo \"------------\"\n", " echo \"\"\n", " echo \"Extracting R2 reads from ${fastq}\"\n", "\n", "\tfor fastq in \"${directory}\"/*R2*.gz\n", "\tdo\n", " echo \"Extracting R2 reads from ${fastq}\"\n", " echo \"\"\n", "\t ${seqtk} subseq \"${fastq}\" \"${seqtk_list}\" >> \"${R2_fq}\"\n", "\tdone\n", " \n", " echo \"-------------------------------------\"\n", " # Print working directoyr and list files\n", " pwd\n", "\tls -ltrh\n", " echo \"\"\n", " echo \"-------------------------------------\"\n", " echo \"\"\n", "done\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### See if resulting FastQ files have same number of lines (i.e. same number of reads)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "191512684 20200121.C_bairdi.megan_R1.fq\n", "191512684 20200121.C_bairdi.megan_R2.fq\n", "47878171 20200121.C_bairdi.seqtk.read_id.list\n", "8232564 20200121.Hematodinium.megan_R1.fq\n", "8232564 20200121.Hematodinium.megan_R2.fq\n", "2058141 20200121.Hematodinium.seqtk.read_id.list\n" ] } ], "source": [ "%%bash\n", "for directory in /home/sam/analyses/20200121.C_bairdi_megan_reads /home/sam/analyses/20200121.Hematodinium_megan_reads\n", "do\n", " cd \"${directory}\" || exit\n", " for file in *\n", " do\n", " wc -l ${file}\n", " done\n", "done" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }