In [34]:
### Notebook 4
### Data set 4 (Orestias)
### Authors: Takahashi & Moreno (2015)
### Data Location: DDBJ DRA DRA003595
Sequence data for this study are archived on the NCBI sequence read archive (SRA). Below I read in SraRunTable.txt for this project which contains all of the information we need to download the data.
In [4]:
%%bash
## make a new directory for this analysis
mkdir -p empirical_4/fastq/
In [16]:
import os
def wget_download_ddbj(SRR, outdir):
""" Python function to get sra data from ncbi and write to
outdir with a new name using bash call wget """
## create a call string
call = "wget -q -r -nH --cut-dirs=9 -P "+outdir+" "+\
"ftp://ftp.ddbj.nig.ac.jp/ddbj_database/dra/sra/ByExp/"+\
"sra/DRX/DRX033/DRX033{:03d}".format(SRR)
## run wget call
! $call
Here we pass the SRR number and the sample name to the wget_download
function so that the files are saved. In this case we do not have the sample names, just their SRR IDs.
In [17]:
for ID in range(6,70):
wget_download_ddbj(ID, "empirical_4/fastq/")
In [18]:
%%bash
## convert sra files to fastq using fastq-dump tool
## output as gzipped into the fastq directory
fastq-dump --gzip -O empirical_4/fastq/ empirical_4/fastq/*.sra
## remove .sra files
rm empirical_4/fastq/*.sra
In [19]:
%%bash
pyrad --version
In [20]:
%%bash
## delete existing params file if it exits
rm params.txt
## create a new default params file
pyrad -n
In [10]:
%%bash
## substitute new parameters into file
sed -i '/## 1. /c\empirical_4/ ## 1. working directory ' params.txt
sed -i '/## 6. /c\TGCAGG ## 6. cutters ' params.txt
sed -i '/## 7. /c\30 ## 7. N processors ' params.txt
sed -i '/## 9. /c\6 ## 9. NQual ' params.txt
sed -i '/## 10./c\.85 ## 10. clust threshold ' params.txt
sed -i '/## 12./c\4 ## 12. MinCov ' params.txt
sed -i '/## 13./c\10 ## 13. maxSH ' params.txt
sed -i '/## 14./c\empirical_4_m4 ## 14. output name ' params.txt
sed -i '/## 18./c\empirical_4/fastq/*.gz ## 18. data location ' params.txt
sed -i '/## 29./c\2,2 ## 29. trim overhang ' params.txt
sed -i '/## 30./c\p,n,s ## 30. output formats ' params.txt
In [11]:
cat params.txt
In [ ]:
pyrad -p params.txt -s 234567 >> log.txt 2>&1
In [16]:
%%bash
sed -i '/## 12./c\2 ## 12. MinCov ' params.txt
sed -i '/## 14./c\empirical_4_m2 ## 14. output name ' params.txt
In [17]:
%%bash
pyrad -p params.txt -s 7 >> log.txt 2>&1
In [15]:
## import data frame
import pandas as pd
## read in the data
s4dat = pd.read_table("empirical_4/stats/s2.rawedit.txt", header=0, nrows=65)
## print summary stats
print s4dat["passed.total"].describe()
## find which sample has the most raw data
maxraw = s4dat["passed.total"].max()
print "\nmost raw data in sample:"
print s4dat['sample '][s4dat['passed.total']==maxraw]
In [18]:
## read in the s3 results
s4dat = pd.read_table("empirical_4/stats/s3.clusters.txt", header=0, nrows=65)
## print summary stats
print "summary of means\n=================="
print s4dat['dpt.me'].describe()
## print summary stats
print "\nsummary of std\n=================="
print s4dat['dpt.sd'].describe()
## print summary stats
print "\nsummary of proportion lowdepth\n=================="
print pd.Series(1-s4dat['d>5.tot']/s4dat["total"]).describe()
## find which sample has the greatest depth of retained loci
max_hiprop = (s4dat["d>5.tot"]/s4dat["total"]).max()
print "\nhighest coverage in sample:"
print s4dat['taxa'][s4dat['d>5.tot']/s4dat["total"]==max_hiprop]
In [9]:
import toyplot
import toyplot.svg
import numpy as np
## read in the depth information for this sample
with open("empirical_4/clust.85/DRR036775.depths", 'rb') as indat:
depths = np.array(indat.read().strip().split(","), dtype=int)
## make a barplot in Toyplot
canvas = toyplot.Canvas(width=350, height=300)
axes = canvas.axes(xlabel="Depth of coverage (N reads)",
ylabel="N loci",
label="dataset4/sample=DRR036775")
## select the loci with depth > 5 (kept)
keeps = depths[depths>5]
## plot kept and discarded loci
edat = np.histogram(depths, range(30)) # density=True)
kdat = np.histogram(keeps, range(30)) #, density=True)
axes.bars(edat)
axes.bars(kdat)
#toyplot.svg.render(canvas, "empirical_4_depthplot.svg")
Out[9]:
In [30]:
cat empirical_4/stats/empirical_4_m4.stats
In [19]:
%%bash
head -n 20 empirical_4/stats/empirical_4_m2.stats
In [ ]:
%%bash
## raxml argumement w/ ...
raxmlHPC-PTHREADS-AVX -f a -m GTRGAMMA -N 100 -x 12345 -p 12345 -T 20 \
-w /home/deren/Documents/RADmissing/empirical_4/ \
-n empirical_4_m4 -s empirical_4/outfiles/empirical_4_m4.phy
In [ ]:
%%bash
## raxml argumement w/ ...
raxmlHPC-PTHREADS-AVX -f a -m GTRGAMMA -N 100 -x 12345 -p 12345 -T 20 \
-w /home/deren/Documents/RADmissing/empirical_4/ \
-n empirical_4_m2 -s empirical_4/outfiles/empirical_4_m2.phy
In [2]:
%%bash
head -n 40 empirical_4/RAxML_info.empirical_4
In [21]:
%load_ext rpy2.ipython
In [27]:
%%R -w 1000 -h 800
library(ape)
tre <- read.tree("empirical_4/RAxML_bipartitions.empirical_4")
ltre <- ladderize(tre)
outgroups = c("DRR036791", "DRR036765", "DRR036790", "DRR036767", "DRR036769",
"DRR036766", "DRR036777", "DRR036793", "DRR036778", "DRR036778",
"DRR036792", "DRR036768", "DRR036775")
rtre <- root(ltre, outgroups)
ingrouptre <- drop.tip(ltre, outgroups)
par(mfrow=c(1,2))
plot(ltre, edge.width=2)
nodelabels(ltre$node.label, cex=1)
plot(ingrouptre, edge.width=2)
nodelabels(ingrouptre$node.label, cex=1)
In [28]:
%%R
mean(cophenetic.phylo(ltre))
In [33]:
%%R -h 700
utre <- ladderize(chronopl(rtre, 0.5, resolve.root=TRUE))
plot(utre, edge.width=2)