-
Notifications
You must be signed in to change notification settings - Fork 13
/
ENCODE_shoppinator.py
84 lines (72 loc) · 2.64 KB
/
ENCODE_shoppinator.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import argparse
import os
EPILOG = '''
For more details:
%(prog)s --help
'''
'''
Example commands:
python3 ENCODE_shoppinator.py --key https://test.encodedcc.org/ --infile accessions_list_file
python3 ENCODE_shoppinator.py --infile ENCBS123ABC,ENCBS123ABD,ENCBS124ABC
'''
def getArgs():
parser = argparse.ArgumentParser(
description=__doc__, epilog=EPILOG,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument('--key',
default='https://www.encodeproject.org/',
help="Server you want the shoppinator URL to be associated with. \
Default is https://www.encodeproject.org/")
parser.add_argument('--infile',
help="A comma separated list or datafile containing " +
"accessions list to be " +
"addded to the shopping cart URL")
parser.add_argument('--object-type',
default='Experiment',
help="object type the list of accessions in the " +
"shoppinator belongs to")
args = parser.parse_args()
return args
def main():
args = getArgs()
server = args.key
object_type = args.object_type
infile = args.infile
if infile:
if os.path.isfile(infile):
ACCESSIONS = [line.rstrip('\n') for line in open(infile)]
else:
ACCESSIONS = infile.split(",")
object_types = {
'Experiment': 'ENCSR',
'Biosample': 'ENCBS',
'MouseDonor': 'ENCDO',
'HumanDonor': 'ENCDO',
'FlyDonor': 'ENCDO',
'WormDonor': 'ENCDO',
'Pipeline': 'ENCPL',
'File': 'ENCFF'
}
if object_type not in object_types:
print('ERROR - Unrecognized object type : ' + object_type +
', please specify type from the following list : ' +
str(sorted(object_types.keys())))
else:
is_valid = True
attach = ''
for acc in ACCESSIONS:
if acc.startswith(object_types[object_type]) is False:
print('ERROR - Accession ' + acc +
' does not match specified object type ' + object_type)
is_valid = False
if len(acc) != 11:
print('ERROR - Accession ' + acc +
' does not match ENCODE accession format ' +
'(ENCXY123ABC) length')
is_valid = False
attach += '&accession=' + acc
if is_valid:
print(server + 'search/?type=' + object_type + attach)
if __name__ == '__main__':
main()