In [2]:
### Notebook 10
### Data set 10: Pedicularis
### Authors: Eaton & Ree 2013
### Data Location: SRP021469
In [1]:
%%bash
## make a new directory for this analysis
mkdir -p empirical_10/fastq/
In [2]:
## IPython code
import pandas as pd
import numpy as np
import urllib2
import os
## open the SRA run table from github url
url = "https://raw.githubusercontent.com/"+\
"dereneaton/RADmissing/master/empirical_10_SraRunTable.txt"
intable = urllib2.urlopen(url)
indata = pd.read_table(intable, sep="\t")
## print first few rows
print indata.head()
In [3]:
def wget_download(SRR, outdir, outname):
""" Python function to get sra data from ncbi and write to
outdir with a new name using bash call wget """
## get output name
output = os.path.join(outdir, outname+".sra")
## create a call string
call = "wget -q -r -nH --cut-dirs=9 -O "+output+" "+\
"ftp://ftp-trace.ncbi.nlm.nih.gov/"+\
"sra/sra-instant/reads/ByRun/sra/SRR/"+\
"{}/{}/{}.sra;".format(SRR[:6], SRR, SRR)
## call bash script
! $call
Here we pass the SRR number and the sample name to the wget_download
function so that the files are saved with their sample names.
In [4]:
for ID, SRR in zip(indata.Sample_Name_s, indata.Run_s):
wget_download(SRR, "empirical_10/fastq/", ID)
In [5]:
%%bash
## convert sra files to fastq using fastq-dump tool
## output as gzipped into the fastq directory
fastq-dump --gzip -O empirical_10/fastq/ empirical_10/fastq/*.sra
## remove .sra files
rm empirical_10/fastq/*.sra
In [6]:
%%bash
ls -lh empirical_10/fastq/
In [10]:
%%bash
pyrad --version
In [7]:
%%bash
## remove old params file if it exists
rm params.txt
## create a new default params file
pyrad -n
In [8]:
%%bash
## substitute new parameters into file
sed -i '/## 1. /c\empirical_10/ ## 1. working directory ' params.txt
sed -i '/## 6. /c\TGCAG ## 6. cutters ' params.txt
sed -i '/## 7. /c\20 ## 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_10_m4 ## 14. output name ' params.txt
sed -i '/## 18./c\empirical_10/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 [10]:
cat params.txt
In [ ]:
%%bash
pyrad -p params.txt -s 234567 >> log.txt 2>&1
In [22]:
%%bash
sed -i '/## 12./c\2 ## 12. MinCov ' params.txt
sed -i '/## 14./c\empirical_10_m2 ## 14. output name ' params.txt
In [23]:
%%bash
pyrad -p params.txt -s 7 >> log.txt 2>&1
In [13]:
import pandas as pd
## read in the data
sdat = pd.read_table("empirical_10/stats/s2.rawedit.txt", header=0, nrows=14)
## print summary stats
print sdat["passed.total"].describe()
## find which sample has the most raw data
maxraw = sdat["passed.total"].max()
print "\nmost raw data in sample:"
print sdat['sample '][sdat['passed.total']==maxraw]
In [14]:
## read in the s3 results
sdat = pd.read_table("empirical_10/stats/s3.clusters.txt", header=0, nrows=14)
## print summary stats
print "summary of means\n=================="
print sdat['dpt.me'].describe()
## print summary stats
print "\nsummary of std\n=================="
print sdat['dpt.sd'].describe()
## print summary stats
print "\nsummary of proportion lowdepth\n=================="
print pd.Series(1-sdat['d>5.tot']/sdat["total"]).describe()
## find which sample has the greatest depth of retained loci
max_hiprop = (sdat["d>5.tot"]/sdat["total"]).max()
print "\nhighest coverage in sample:"
print sdat['taxa'][sdat['d>5.tot']/sdat["total"]==max_hiprop]
In [15]:
maxprop =(sdat['d>5.tot']/sdat['total']).max()
print "\nhighest prop coverage in sample:"
print sdat['taxa'][sdat['d>5.tot']/sdat['total']==maxprop]
In [16]:
import numpy as np
## print mean and std of coverage for the highest coverage sample
with open("empirical_10/clust.85/38362_rex.depths", 'rb') as indat:
depths = np.array(indat.read().strip().split(","), dtype=int)
print "Means for sample 38362_rex"
print depths.mean(), depths.std()
print depths[depths>5].mean(), depths[depths>5].std()
In [19]:
import toyplot
import toyplot.svg
import numpy as np
## read in the depth information for this sample
with open("empirical_10/clust.85/38362_rex.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="dataset10/sample=38362_rex")
## 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_10_depthplot.svg")
Out[19]:
In [20]:
cat empirical_10/stats/empirical_10_m4.stats
In [25]:
%%bash
head -n 10 empirical_10/stats/empirical_10_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_10/ \
-n empirical_10_m4 -s empirical_10/outfiles/empirical_10_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_10/ \
-n empirical_10_m2 -s empirical_10/outfiles/empirical_10_m2.phy
In [26]:
%%bash
head -n 20 empirical_10/RAxML_info.empirical_10_m4
In [27]:
%%bash
head -n 20 empirical_10/RAxML_info.empirical_10_m2
In [28]:
%load_ext rpy2.ipython
In [30]:
%%R -h 800 -w 800
library(ape)
tre <- read.tree("empirical_10/RAxML_bipartitions.empirical_10_m4")
ltre <- ladderize(tre)
par(mfrow=c(1,2))
plot(ltre, use.edge.length=F)
nodelabels(ltre$node.label)
plot(ltre, type='u')
In [31]:
%%R
mean(cophenetic.phylo(ltre))