-
Notifications
You must be signed in to change notification settings - Fork 2
/
PEASTssPromoter.py
59 lines (48 loc) · 2.25 KB
/
PEASTssPromoter.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
50
51
52
53
54
55
56
57
58
59
import sys
import pandas as pd
import numpy as np
import PEASUtil
import argparse
import os
wd = os.getcwd()
parser = argparse.ArgumentParser(description='Identifies promoters based on distance to TSS.')
parser.add_argument('featurefile', type=str, help='Feature file for identifying promoters.')
parser.add_argument('-c', dest='column', type=int, default=24, help='Index column containing the distance to TSS.')
parser.add_argument('-u', dest='upstreamtss', type=int, default=2000, help='The upstream distance threshold from the TSS. Default: 2000')
parser.add_argument('-d', dest='downstreamtss', type=int, default=2000, help='The downstream distance threshold from the TSS. Default: 2000')
parser.add_argument('-t', dest='dest', type=str, help='The promoter prediction file destination.')
parser.add_argument('-a', dest='annotationdest', type=str,
help='Include an annotation file path destination to append the feature file with a column for predictions.')
args = parser.parse_args()
inputfile = pd.read_csv(args.featurefile, sep="\t", header=None).values
dtssidx = args.column
downthresh = abs(int(args.downstreamtss))
upthresh = abs(int(args.upstreamtss))
if args.dest is not None:
dest = args.dest
else:
dest = args.featurefile+".promoterprediction.txt"
def getPromoterPredictions(dataset, dtssidx, upthresh, downthresh):
rv = []
for i in range(0, len(dataset)):
chr = dataset[i,0]
start = dataset[i,1]
end = dataset[i,2]
try:
dtss = int(dataset[i,dtssidx])
if dtss < 0:
rv.append([chr, start, end, int(abs(dtss) <= upthresh)])
elif dtss > 0:
rv.append([chr, start, end, int(dtss <= downthresh)])
else:
rv.append([chr, start, end, 1])
except:
pass
return np.array(rv)
predictions = getPromoterPredictions(inputfile, dtssidx, downthresh, upthresh)
print("Writing prediction file.")
pd.DataFrame(predictions, columns=["chr", "start", "end", "promoter prediction"]).to_csv(dest, sep="\t", index=None)
if args.annotationdest is not None:
print("Writing annotated feature file.")
PEASUtil.annotateWithPredictions(args.featurefile, dest, args.annotationdest)
print("Finished annotating promoters.")