Skip to content
Snippets Groups Projects
Commit 894f05c9 authored by pinyili2's avatar pinyili2
Browse files

add

parent bf90ece7
No related branches found
No related tags found
1 merge request!1Pinyili2
......@@ -122,10 +122,10 @@ def gen_prop_table(fname):
nt_prop["bp"]=bp
non_stack_ind,=np.where(nt_prop["stack"]==-1)
for i in non_stack_ind:
zid=int(nt_prop.loc[i]["zid"])+int(nt_prop.loc[i]["fwd"])*2-1
try:
nt_prop["stack"][i]=bp_map[(nt_prop.loc[i]["vh"],str(zid),nt_prop.loc[i]["fwd"])]
except:
zid=int(nt_prop.loc[i]["zid"])+int(nt_prop.loc[i]["fwd"])*2.0-1.0
if (nt_prop.loc[i]["vh"],zid,nt_prop.loc[i]["fwd"]) in bp_map.keys():
nt_prop["stack"][i]=bp_map[(nt_prop.loc[i]["vh"],zid,nt_prop.loc[i]["fwd"])]
else:
continue
nt_prop["r"]=list(np.array([nt_prop["x"],nt_prop["y"],nt_prop["z"]],dtype="<f4").T)
......
%% Cell type:code id:b3d4de16 tags:
``` python
from mrdna import logger, devlogger
import pickle
import pandas as pd
import sys
import mrdna.readers.libs as libs
import numpy as np
from scipy.spatial import distance_matrix
import mrdna
```
%% Output
_
_____ ___ _| |___ ___
| | _| . | | .'|
|_|_|_|_| |___|_|_|__,| v1.0a.dev121
it/its
%% Cell type:code id:85f99c60 tags:
``` python
from mrdna.readers.segmentmodel_from_oxdna_pinyi import*
```
%% Cell type:code id:409255b3 tags:
``` python
virt2nuc="test_insert.json.virt2nuc"
top_data = np.loadtxt("test_insert.json.top", skiprows=1,
unpack=True,
dtype=np.dtype('i4,U1,i4,i4')
)
def _find_vh_vb_table(s,is_scaf):
L=[]
for i in list(s.keys()):
vh,zid=i
strand,indices=s[i]
if len(indices)==0:
continue
else:
if len(indices)==1:
zids=[str(zid)]
else:
zids=[str(zid)+"."+str(j) for j in range(len(indices))]
for index,z in zip(indices,zids):
L.append(pd.Series({"index":index,"vh":vh,"zid":z,"strand":strand,"is_scaf":bool(is_scaf)}))
return L
virt_pickle=open(virt2nuc,"rb")
vh_vb,pattern=pickle.load(virt_pickle)
L1=_find_vh_vb_table(vh_vb._scaf,1)
L2=_find_vh_vb_table(vh_vb._stap,0)
nt_prop=pd.DataFrame(L1+L2)
nt_prop.set_index("index",inplace=True)
nt_prop.sort_index(inplace=True)
nt_prop["threeprime"]=top_data[2]
nt_prop["stack"]=top_data[2]
vh_bool=1-(nt_prop["vh"]%2)*2
is_scaf_bool=nt_prop["is_scaf"]*2-1
nt_prop["fwd"]=np.array((is_scaf_bool.T*vh_bool+1)/2,dtype=bool)
```
%% Cell type:code id:9649d37f tags:
``` python
stack_map=dict(zip(zip(nt_prop["vh"],nt_prop["zid"],nt_prop["fwd"]),nt_prop.index,))
```
%% Cell type:code id:dfe5ba1e tags:
``` python
bp_map=dict(zip(zip(nt_prop["vh"],nt_prop["zid"],nt_prop["fwd"]),nt_prop.index))
```
%% Cell type:code id:0b94dcec tags:
``` python
non_stack_ind,=np.where(nt_prop["stack"]==-1)
for i in non_stack_ind:
zid=int(nt_prop.loc[i]["zid"])+int(nt_prop.loc[i]["fwd"])*2-1
try:
nt_prop["stack"][i]=bp_map[(nt_prop.loc[i]["vh"],str(zid),nt_prop.loc[i]["fwd"])]
except:
continue
```
%% Cell type:code id:d17224f8 tags:
``` python
n,=np.where(nt_prop["vh"]==0)
t,=np.where(nt_prop["fwd"][n]==True)
f,=np.where(nt_prop["fwd"][n]==False)
dt=nt_prop.loc[n[t]]
dt.set_index(["vh","zid"],inplace=True)
df=nt_prop.loc[n[f]]
df.set_index(["vh","zid"],inplace=True)
```
%% Cell type:code id:b2e7198d tags:
``` python
nt_prop.loc[333]
```
%% Output
vh 0
zid 24
strand 10
is_scaf False
threeprime -1
stack 332
fwd False
Name: 333, dtype: object
%% Cell type:code id:169aa122 tags:
``` python
n=nt_prop.set_index(["vh","zid","fwd"])
print(n.loc[(0,"21",False)],n.loc[(0,"20",False)])
```
%% Output
strand 9
is_scaf False
threeprime 329
stack 329
Name: (0, 21, False), dtype: object strand 8
is_scaf False
threeprime 291
stack 291
Name: (0, 20, False), dtype: object
%% Cell type:code id:c0605ccd tags:
``` python
print(n.loc[(1,"21",True)],n.loc[(1,"20",True)])
```
%% Output
strand 9
is_scaf False
threeprime 328
stack 328
Name: (1, 21, True), dtype: object strand 8
is_scaf False
threeprime 292
stack 292
Name: (1, 20, True), dtype: object
%% Cell type:code id:d787b235 tags:
``` python
nt_prop.loc[[327,328,290,291,292,293]]
```
%% Output
vh zid strand is_scaf threeprime stack fwd
index
327 1 23 9 False 326 326 True
328 1 22 9 False 327 327 True
290 0 18 8 False 289 289 False
291 0 19 8 False 290 290 False
292 0 20 8 False 291 291 False
293 1 20 8 False 292 292 True
%% Cell type:code id:9088a520 tags:
``` python
n,=np.where(nt_prop["stack"]==-1)
for vh,zid,fwd in stack[n]:
if fwd==True:
zid=str(int(zid)+1)
else:
zid=str(int(zid)-1)
if (vh,zid,fwd) in stack:
nt_prop[]
```
%% Output
array([['0', '41', 'True'],
['1', '39', 'False'],
['2', '41', 'True'],
['2', '0', 'False'],
['3', '37', 'False'],
['4', '3', 'True'],
['5', '0', 'False'],
['5', '23', 'False'],
['0', '2', 'False'],
['1', '38', 'True'],
['0', '24', 'False'],
['5', '39', 'True'],
['4', '9', 'False'],
['3', '34', 'True']], dtype='<U21')
%% Cell type:code id:6508fe8e tags:
``` python
df
```
%% Output
index vh zid strand is_scaf
0 2 0 39 0 True
1 1 0 40 0 True
2 0 0 41 0 True
3 5 1 41 1 True
4 4 1 40 1 True
.. ... .. .. ... ...
450 427 3 30 13 False
451 426 3 31 13 False
452 425 3 32 13 False
453 424 3 33 13 False
454 423 3 34 13 False
[455 rows x 5 columns]
%% Cell type:code id:e163e703 tags:
``` python
```
../libs
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment