-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPS_rename_assemblies.py
More file actions
37 lines (32 loc) · 1.28 KB
/
GPS_rename_assemblies.py
File metadata and controls
37 lines (32 loc) · 1.28 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
"""Replace the name of downloaded GPS assemblies and assembly metadata with the lane ID"""
import glob
import os
import sys
def get_options():
import argparse
description = 'Download reads of interest by accession ID'
parser = argparse.ArgumentParser(description=description,
prog='extract_entrez_reads')
io_opts = parser.add_argument_group('input')
io_opts.add_argument("--input-dir",
dest="input_dir",
required=True,
help='directory containing files to rename',
type=str)
args = parser.parse_args()
return (args)
def main():
args = get_options()
retieved_files = glob.glob(os.path.join(args.input_dir, "*"))
for file in retieved_files:
dirname = os.path.dirname(file)
newFilename = ".".join(file.split(".")[1:]).split("_")[1:]
newFilename = os.path.join(dirname, "_".join(newFilename[:2]) + "#" + newFilename[2])
if "_additionalAssemblyStats.txt" in file:
newFilename += "_additionalAssemblyStats.txt"
if "_assembly_stats.txt" in file:
newFilename += "_assembly_stats.txt"
os.rename(file, newFilename)
sys.exit(0)
if __name__ == '__main__':
main()