Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory effeciency of split_cpg_groups.py #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions script_in_snakemake/split_cpg_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
-keeping strandedness and readID information
"""

ch=[]
st=[]
pos=[]
log=[]
readID=[]
target ="CG"

target ="CG"
out = open(snakemake.output[1],'w')
out.write("\t".join(['Chr', 'Pos','Strand', 'Log.like.ratio', 'Read_ID']) + "\n")
with open(snakemake.input[0],'r') as fh:
next(fh)
for line in fh:
Expand All @@ -41,29 +38,29 @@
seq = str(fields[10])

if cpg_num == 1:
ch.append(chrom)
st.append(strand)
pos.append(start)
log.append(logRatio)
readID.append(read_name)
out.write(chrom + "\t" + str(start) + "\t" + strand + "\t" + str(logRatio) + "\t" + read_name + "\n")

elif cpg_num > 1:
index = []
pos.append(start)
for match in re.finditer(target, seq):
#print(match.start())
# index = []
# pos.append(start)
out.write(chrom + "\t" + str(start) + "\t" + strand + "\t" + str(logRatio) + "\t" + read_name + "\n")
for match in re.finditer(target, seq):
# print(match.start())
index.append(match.start())
length = len(index)
for i in range(1, length):
new_start = start + (index[i] - index[0])
pos.append(new_start)
#print(new_start)
# pos.append(new_start)
out.write(chrom + "\t" + str(new_start) + "\t" + strand + "\t" + logRatio + "\t" + read_name + "\n")
# print(new_start)
'''
ch.extend([chrom] * cpg_num)
st.extend([strand] * cpg_num)
log.extend([logRatio] * cpg_num)
readID.extend([read_name] * cpg_num)


final = pd.DataFrame(list(zip(ch,pos,st,log,readID)), columns =['Chr', 'Pos','Strand', 'Log.like.ratio', 'Read_ID'])
final.to_csv(snakemake.output[0], sep="\t", header=True, index=False)

'''