def parseClusterResult(result_file):
	table = {}
	transformer = BitWiseTransformer()
	count = 0  
	header = ''
	for line in open(result_file, 'r'):
		count = count + 1	
		if count == 1:
			print(line)
			header = line.strip()
			continue
		parts = line.strip().split(',')
		kmer = transformer.bitwise(int(parts[2]), 20)
		if kmer in table:
			print(','.join(table[kmer]))
			print(line)
			raise RuntimeError("duplicate found!\n")
		else:
			table[kmer] = parts
	return (header,table)			
def transform_2_seq(count_table_file, skip = 0):
	table = {}
	transformer = BitWiseTransformer()
	count = 0
	for line in open(count_table_file,'r'):
		count = count + 1
		if count <= skip:
			continue 
		if ',' in line:
			l = line.strip().split(',')
		else:
			l = line.strip().split('\t')
		if len(l) == 3:
			kmer = transformer.bitwise(int(l[0]),int(l[1]))
		else:
			kmer = transformer.bitwise(int(l[0]), 20)
		if kmer in table:
			print(','.join(table[kmer]))
			print(line)
			raise RuntimeError("duplicate found")
		else:
			table[kmer] = l
	return table
Пример #3
0
#!/usr/bin/python
from bitwise import BitWiseTransformer
def extract_barcode(f,b_len):
	table = {}
	count = 0
	for line in open(f, 'r'):
		count = count + 1
		if count == 1:
			continue
		parts = line.strip().split(',')
		try:
			if int(parts[1]) == b_len:
				table[parts[0]] =parts[2]
		except Exception as err:
			print(parts[1])
			print(parts)
		
	return table

if __name__ == '__main__':
	f = "../data/single_end_data/single_end_data_count.csv"
	table = extract_barcode(f, 20)
	output = open('../data/single_end_data/single_end_data_20_count.csv','w')
	trans = BitWiseTransformer()
	for k,v in table.items():
		output.write(k + ',' + trans.bitwise(int(k),20) + ',' + v + '\n')
	output.close()
	
	
	
def primers(f, l = 10):
	result = []
	bt = BT()
	for i in range(f):
		result.append(bt.bitwise(i, l))
	return result