view alignments-to-links.py @ 6:740057a5126d draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit 1584882716a1d2c598e8485da9d73bcf80d9b29a"
author iuc
date Fri, 01 May 2020 07:28:50 -0400
parents 014a21767ac4
children
line wrap: on
line source

import itertools
import sys

from Bio import AlignIO


format_mapping = {
    "xmfa": "mauve",
    "maf": "maf",
    "nex": "nexus",
    # 'phylip': 'phylip-relaxed',
    "stockholm": "stockholm",
}

for aln in AlignIO.parse(sys.argv[1], format_mapping.get(sys.argv[2], "maf")):

    for (a, b) in itertools.combinations(aln, 2):
        a_s = a.annotations["start"]
        b_s = b.annotations["start"]

        if "size" in a.annotations:
            a_l = a.annotations["size"]
            b_l = b.annotations["size"]
            a_e = a_l + a_s
            b_e = b_l + b_s
        else:
            a_e = a.annotations["end"]
            b_e = b.annotations["end"]

        sys.stdout.write("%s\t%s\t%s\t%s\t%s\t%s\n" % (a.id, a_s, a_e, b.id, b_s, b_e))