File: 2geneorder.py

package info (click to toggle)
ragout 2.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 72,976 kB
  • sloc: python: 4,624; cpp: 2,314; makefile: 83; sh: 43
file content (42 lines) | stat: -rwxr-xr-x 984 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/python

#(c) 2013-2015 by Authors
#This file is a part of Ragout program.
#Released under the BSD license (see LICENSE file)

"""
This script converts synteny blocks file from Ragout internal format
to one that MLGO recognizes
"""

from __future__ import print_function
from __future__ import absolute_import
import sys
from collections import defaultdict

def main():
    if len(sys.argv) != 2:
        print("Usage: 2geneorder.py genome_permutations")
        return 1

    filename = sys.argv[1]
    blocks = defaultdict(list)
    with open(filename, "r") as f:
        while True:
            name_str = f.readline().strip()
            if not name_str:
                break

            blocks_str = f.readline().strip()
            blocks[name_str[1:].split(".")[0]].append(blocks_str)

    for genome, seqs in blocks.items():
        print(">{0}".format(genome))
        for seq in seqs:
            print(seq)

    return 0


if __name__ == "__main__":
    main()