-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_bppms.py
49 lines (38 loc) · 1.33 KB
/
get_bppms.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import argparse
from pathlib import Path
import os
import sys
ARNIE_CONFIG_PATH = 'path/to/arnie/arnie_config.txt'
os.environ['ARNIEFILE'] = ARNIE_CONFIG_PATH
ARNIE_PATH = 'path/to/arnie/src/'
sys.path.append(ARNIE_PATH)
import arnie
from arnie.bpps import bpps
import numpy as np
import pandas as pd
import concurrent.futures
import tqdm
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--out_dir", type = str)
parser.add_argument("-d", "--data_path", type = str)
args = parser.parse_args()
AIM_DIR = Path(args.out_dir)
AIM_DIR.mkdir(parents=True, exist_ok=True)
DATA_PATH = Path(args.data_path)
def calc_arnie(seq, seqid):
res = bpps(seq, package="eternafold")
outpath = AIM_DIR / f"{seqid}.npy"
np.save(outpath, res)
df = pd.read_csv(DATA_PATH, sep="\t")
with concurrent.futures.ProcessPoolExecutor(max_workers=30) as executor:
futures = {}
for ind, seqid, seq in tqdm.tqdm(df[['id', 'sequence']].itertuples(), total=len(df)):
ft = executor.submit(calc_arnie, seqid=seqid, seq=seq.upper())
futures[ft] = seqid
for ft in tqdm.tqdm(concurrent.futures.as_completed(futures), total=len(futures)):
try:
ft.result()
except Exception as exc:
print(exc)
seqid = futures[ft]
print(f"Error occured while processing {seqid}: {exc}")