-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheu_get_exp_gms.py
More file actions
executable file
·74 lines (67 loc) · 2.19 KB
/
eu_get_exp_gms.py
File metadata and controls
executable file
·74 lines (67 loc) · 2.19 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
###
# © 2018 The Board of Trustees of the Leland Stanford Junior University
# Nathaniel Watson
# nathankw@stanford.edu
###
"""
For the provided DCC experiment identifiers, writes out the unique set of associated genetic_modification
accessions to the specified output file, one per line.
"""
import argparse
import datetime
import json
import os
import pdb
import encode_utils.connection as euc
from encode_utils.parent_argparser import dcc_login_parser
def get_parser():
parser = argparse.ArgumentParser(
description=__doc__,
parents=[dcc_login_parser],
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-o", "--outfile", required=True, help="Output file name.")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-r", "--records", default=[], nargs="+", help="""
One or more DCC experiment identifiers. """)
group.add_argument("-i", "--infile", help="""
An input file containing one or more DCC experiment identifiers, one per line. Empty lines and
lines starting with '#' are skipped. """)
return parser
def main():
parser = get_parser()
args = parser.parse_args()
rec_ids = args.records
infile = args.infile
outfile = args.outfile
# Connect to the Portal
dcc_mode = args.dcc_mode
if dcc_mode:
conn = euc.Connection(dcc_mode)
else:
# Default dcc_mode taken from environment variable DCC_MODE.
conn = euc.Connection()
if not rec_ids:
# Then get them from input file
fh = open(infile)
for line in fh:
line = line.strip()
if not line or line.startswith("#"):
continue
rec_ids.append(line)
gms = []
for i in rec_ids:
rec = conn.get(i)
for rep in rec["replicates"]:
for gm in rep["library"]["biosample"]["genetic_modifications"]:
gm = gm.strip("/").split("/")[-1]
if gm not in gms:
print(gm)
gms.append(gm)
fout = open(outfile, "w")
for i in gms:
fout.write(i)
fout.close()
if __name__ == "__main__":
main()