-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetIndelSize.py
executable file
·35 lines (33 loc) · 1.21 KB
/
GetIndelSize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python2.7
import sys,os,pandas
def GetIndelOne(f,name):
df=pandas.read_csv(f,sep="\t",header=0,index_col=None)
df["indel_size"]=df["n_inserted"]-df["n_deleted"]
sub=df[(df["Read_Status"]=="MODIFIED")&(df["n_deleted"]==0)&(df["n_inserted"]==0)]["#Reads"].sum()
modified=df[df["Read_Status"]=="MODIFIED"]["#Reads"].sum()
indel_count=modified-sub
df2=df[(df["Read_Status"]=="MODIFIED")&((df["n_deleted"]!=0)|(df["n_inserted"]!=0))]
df3=df2.groupby('indel_size')['#Reads'].sum().to_frame()
df3.columns=[name]
df3_freq=(df2.groupby('indel_size')['#Reads'].sum()/indel_count*100).to_frame()
df3_freq.columns=[name+"_freq"]
return df3,df3_freq
def GetIndelList(flist):
rl=[]
rl_freq=[]
for x in flist:
x=x.rstrip()
name=os.path.dirname(x).replace("./","").replace("/","_")
df3,df3_freq=GetIndelOne(x,name)
rl.append(df3)
rl_freq.append(df3_freq)
df_r=pandas.concat(rl,axis=1)
df_r=df_r.fillna(0)
df_freq=pandas.concat(rl_freq,axis=1)
df_freq=df_freq.fillna(0)
return df_r,df_freq
if __name__ == '__main__':
line=os.popen("find . -name 'Alleles_frequency_table.zip' ").readlines()
df_r,df_freq=GetIndelList(line)
df_r.to_csv("indel_size.txt",sep="\t")
df_freq.to_csv("indel_size_freq.txt",sep="\t")