Mercurial > repos > yating-l > rename_scaffolds
comparison rename.py @ 0:1a0e39acb62f draft
planemo upload commit 3431b38459716fd36c193c1035ede040f7ca2e87-dirty
author | yating-l |
---|---|
date | Mon, 19 Dec 2016 17:14:55 -0500 |
parents | |
children | 148e353417e7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1a0e39acb62f |
---|---|
1 """ | |
2 Call rename to rename scaffolds in reference genome so that the sequence names are less than 31 characters. Rename all scaffolds to scaffold_1, scaffold_2, ..., scaffold_N and provide a name mapping file | |
3 """ | |
4 import sys | |
5 from collections import OrderedDict | |
6 | |
7 def rename(inputfile, outputfile, indexfile): | |
8 namemap = OrderedDict() | |
9 with open(outputfile, 'w') as out: | |
10 with open(inputfile, 'r') as rf: | |
11 lines = rf.readlines() | |
12 i = 1 | |
13 for line in lines: | |
14 if ">" in line: | |
15 oldname = line[1:].rstrip() | |
16 newname = "scaffold_" + str(i) | |
17 line = ">" + newname + "\n" | |
18 i = i+1 | |
19 namemap[oldname] = newname | |
20 out.write(line) | |
21 with open(indexfile, 'w') as index: | |
22 for k in namemap: | |
23 index.write(k + "=>" + namemap[k] + "\n") | |
24 | |
25 def main(): | |
26 inputfile = str(sys.argv[1]) | |
27 outputfile = str(sys.argv[2]) | |
28 indexfile = str(sys.argv[3]) | |
29 rename(inputfile, outputfile, indexfile) | |
30 | |
31 if __name__ == "__main__": | |
32 main() | |
33 | |
34 |