# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 2
#     language: python
#     name: python2
# ---

# # Goal
#
# * simulating amplicon fragments for genomes in non-singleton OTUs

# # Setting variables

# +
import os

workDir = '/var/seq_data/ncbi_db/genome/Jan2016/ampFrags/'
genomeDir = '/var/seq_data/ncbi_db/genome/Jan2016/bac_complete_rn/'
ampliconFile = '/var/seq_data/ncbi_db/genome/Jan2016/rnammer_aln/otusn_map_nonSingle.txt'
# -

# # Init

# %load_ext rpy2.ipython
# %load_ext pushnote

# + language="R"
# library(dplyr)
# library(tidyr)
# library(ggplot2)

# +
if not os.path.isdir(workDir):
    os.makedirs(workDir)
    
# %cd $workDir
# -

# simlink amplicon OTU map file
tmp = os.path.join(workDir, '../', ampliconFile)
# !ln -s -f $tmp .

# # Indexing genomes

# !head -n 3 $ampliconFile

# !cut -f 13 $ampliconFile | head

# ## symlinking all genomes of interest

# !cut -f 13 $ampliconFile | \
#     sort -u | \
#     perl -pe 's|^|../bac_complete_rn/|' | \
#     xargs -I % ln -s -f % .

# !cut -f 13 $ampliconFile | sort -u | wc -l
# !find . -name "*.fna" | wc -l

# !ls -thlc 2>/dev/null | head -n 4

# ## Making genome -> genome_file index 

# !cut -f 13 $ampliconFile | perl -pe 's/(.+).fna/\$1\t\$1\.fna/' | sort -u > genome_index.txt
# !wc -l genome_index.txt
# !head genome_index.txt

# # Index genomes

# !SIPSim genome_index \
#     genome_index.txt \
#     --fp . --np 26 \
#     > index_log.txt \
#     2> index_log_err.txt

# !find . -name "*sqlite3.db" | wc -l

# # Simulating fragments

# # copy primer file
# !cp /home/nick/notebook/SIPSim/dev/515F-806R.fna ../

# !SIPSim fragments \
#     genome_index.txt \
#     --fp $workDir \
#     --fr ../515F-806R.fna \
#     --fld skewed-normal,9000,2500,-5 \
#     --flr None,None \
#     --nf 10000 \
#     --np 20 \
#     2> ../ampFrags.log \
#     > ../ampFrags.pkl      

# %pushnote SIPSim fragments complete



StarcoderdataJupyterScriptsDedupFiltered