#!/usr/bin/python
import sys, re
fname = sys.argv[1]
barcodefname = sys.argv[2]
barcodefile = open(barcodefname, "r")
#list = open(barcodefname, "r").readlines(-1)
for barcode in barcodefile:
barcode = barcode.strip()
print "barcode: %s" % barcode
outfname = "%s.%s" % (fname, barcode)
outf = open(outfname, "w")
handle = open(fname, "r")
for line in handle:
potential_barcode = line[:len(barcode)]
if potential_barcode == barcode:
outseq = line[len(barcode):]
sys.stdout.write(outseq)
outf.write(outseq)
handle.close()
outf.close()
barcodefile.close()
The problem I have is that the second argument file looks something like this:
S1 djgbfgbf
S2 dkffbjfb
S3 lfjbvrid
....etc
I need to find a way to ignore the S1, S2, S3 at the beginning of each line and only match the following letters to the argument 1 file. On line 9 I was experimenting with creating a list somehow and reversing it but I'm not sure if that's the answer.