#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 21 14:15:18 2017

@author: nikka.keivanfar
"""
chmod +x select_random_subset/adapter_16mers.py

#to do: fasta as input

P5_Read1 = 'AATGATACGGCGACCACCGAGATCTACACTCTTTCCCTACACGACGCTCTTCCGATCT'
P7 = 'ATCTCGTATGCCGTCTTCTGCTTG'
Read2 = 'AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC' ##keeping P7 and read 2 separate due to Nmer
                                             ##(sample index) between them

#P5-read1

P5_set = set()
for i in range(len(P5_Read1) - k + 1):
   P5_kmer = P5_Read1[i:i+k]
   #P5_read1 16mers in a set
   P5_set.add(P5_kmer)

 
#P7

P7_set = set()
for i in range(len(P7) - k + 1):
   P7_kmer = P7[i:i+k]
   #P7 16mers in a set
   P7_set.add(P7_kmer)

   
#read2

Read2_set = set()
for i in range(len(Read2) - k + 1):
   Read2_kmer = Read2[i:i+k]
   #Read2 16mers in a set
   Read2_set.add(Read2_kmer)


#combine all of above 16mers into a single set
   
from itertools import chain 
  
all_kmers = set(chain(P5_set, P7_set, Read2_set))
print(all_kmers)

@@ -164,15 +164,10 @@
 y%0A%0A#
-to do: 
+##
 fast
@@ -182,446 +182,519 @@
 ut%0A%0A
-P5_Read1 = 'AATGATACGGCGACCACCGAGATCTACACTCTTTCCCTACACGACGCTCTTCCGATCT'%0AP7 = 'ATCTCGTATGCCGTCTTCTGCTTG'%0ARead2 = 'AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC' ##keeping P7 and read 2 separate due to Nmer%0A                                             ##(sample index) between them%0A%0A#P5-read1%0A%0AP5_set = set()%0Afor i in range(len(P5_Read1) - k + 1):%0A   P5_kmer = P5_Read1%5Bi:i+k%5D%0A   #P5_read1 16mers in a set%0A   P5_set.add(P5_kmer)%0A%0A %0A#P7%0A%0AP7_set = set()
+%0Adef fasta_reader(filename):%0A    from Bio.SeqIO.FastaIO import FastaIterator%0A    with open(filename) as handle:%0A        for record in FastaIterator(handle):%0A            yield record%0A%0Asequences = %5B%5D%0Aadapters = %5B%5D%0A%0Afor entry in fasta_reader(%22adapters.fasta%22): #change path here%0A    heading = str(entry.id) #header of fasta%0A    adapters.append(heading)%0A    bp = str(entry.seq) #sequence of specific fasta entry%0A    sequences.append(bp)%0A%0Aadapters_dict = %7B%7D #make dictionary with fasta headers and corresponding seqs
 %0Afor
@@ -708,127 +708,212 @@
 ange
+ 
 (len(
-P7) - k + 1):%0A   P7_kmer = P7%5Bi:i+k%5D%0A   #P7 16mers in a set%0A   P7_set.add(P7_kmer)%0A%0A   %0A#read2%0A%0ARead2_set = set()%0A
+adapters)):%0A    adapters_dict%5Badapters%5Bi%5D%5D = sequences%5Bi%5D%0Aprint adapters_dict%0A%0Ak = 16%0A                                            %0Aall_adapters = set()%0Afor values in adapters_dict.itervalues():%0A    
 for 
@@ -927,21 +927,22 @@
 nge(len(
-Read2
+values
 ) - k + 
@@ -952,26 +952,26 @@
 %0A   
-Read2_
+     
 kmer = 
-Read2
+values
 %5Bi:i
@@ -981,207 +981,74 @@
 %0A   
-#Read2 16mers in a set%0A   Read2_set.add(Read2_kmer)%0A%0A%0A#combine
+     all_adapters.add(kmer)%0Aprint
  all
- of above 16mers into a single set%0A   %0Afrom itertools import chain %0A  %0Aall_kmers = set(chain(P5_set, P7_set, Read2_set))%0Aprint(all_km
+_adapters%0Aprint len(all_adapt
 ers)

Update adapter_16mers.py