Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
NETseq_with_SpikeIns/source/createBarcodeDictionary.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
30 lines (27 sloc)
731 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import pickle | |
bLen=snakemake.params[0] | |
d={} | |
print(bLen) | |
with open(snakemake.input[0],'r') as txt: | |
for line in txt: | |
counts=int(line.strip().split()[1]) | |
ln=line.strip().split()[0] | |
r=ln[bLen:].strip() | |
if r in d: | |
if ln[:bLen] in d[r]: | |
d[r][ln[:bLen]]+=counts | |
else: | |
d[r][ln[:bLen]]=counts | |
else: | |
d[r]={ln[:bLen]:counts} | |
i=1 | |
sd={} | |
with open(snakemake.output[1],'w') as f: | |
for key in d: | |
sd[i]=d[key] | |
f.write('>'+str(i)+'\n') | |
f.write(key+'\n') | |
i+=1 | |
with open(snakemake.output[0],'wb') as f: | |
pickle.dump(sd,f,pickle.HIGHEST_PROTOCOL) |