<jupyter_start><jupyter_text>Pulling out rep 16S sequences for all 12-Con_bulk_core samples<jupyter_code>workDir = '/home/nick/notebook/SIPSim/dev/fullCyc/'
physeqDir = '/home/nick/notebook/fullCyc/data/MiSeq_16S/515f-806r/V4_Lib1-7/phyloseq/'
physeqBulkCore = 'bulk-core'

repSeqs = '/home/nick/notebook/fullCyc/data/MiSeq_16S/515f-806r/V4_Lib1-7/OTU_binning/otusn.fasta'
%load_ext rpy2.ipython
%%R
library(ggplot2)
library(dplyr)
library(tidyr)
library(phyloseq)
%%R -i workDir -i physeqDir -i physeqBulkCore

cat('variables loaded in R\n')
%%R

dir.create(workDir, showWarnings=FALSE)
%%R
# bulk core samples
F = file.path(physeqDir, physeqBulkCore)
physeq.bulk = readRDS(F)
physeq.bulk.m = physeq.bulk %>% sample_data
physeq.bulk
%%R
# just 12C-Con samples
physeq.bulk.12C = prune_samples(physeq.bulk.m$Substrate == '12C-Con', physeq.bulk) %>%
    filter_taxa(function(x) sum(x) > 0, TRUE)
physeq.bulk.12C.m = physeq.bulk.12C %>% sample_data
physeq.bulk.12C
%%R
# list of OTUs
x = physeq.bulk.12C %>% otu_table %>% rownames %>% 
    as.data.frame %>%
    mutate(OTU = sapply(., function(x) paste(c('>OTU.', x, '$'), collapse=''))) %>%
    select(OTU)    
        
outFile = file.path(workDir, 'bulk-core_12C-Con_OTUs.txt')
write.table(x, outFile, quote=FALSE, row.names=FALSE, col.names=FALSE, sep='\t')
# parsing OTU rep sequences

%Rpull outFile
outFile = outFile[0]

## output file
OTU_reps = os.path.join(workDir, 'OTU_reps.fna')

## parsing with egrep
!cd $workDir; \
    egrep -A 1 -f $outFile $repSeqs | \
    perl -ne 'print unless /^-+$/' > $OTU_reps

## checking file    
!printf "Number of OTUs: "
!cd $workDir; \
    grep -c ">" $OTU_reps<jupyter_output>Number of OTUs: 4370
{'fraction_non_alphanumeric': 0.16390532544378697, 'fraction_numerical': 0.03017751479289941, 'mean_word_length': 4.385350318471337, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '540603', 'license': 'MIT', 'n_tokens_mistral': 782, 'n_tokens_neox': 726, 'n_words': 134, 'path': 'ipynb/bac_genome/fullCyc/12C-Con_bulk_OTU_seqs.ipynb', 'repo_name': 'arischwartz/test', 'size': '1690'}