root/galaxy-central/tools/filters/axt_to_fasta.py

リビジョン 2, 1.1 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#!/usr/bin/env python
2"""
3Adapted from bx/scripts/axt_to_fasta.py
4"""
5from galaxy import eggs
6import pkg_resources
7pkg_resources.require( "bx-python" )
8
9import sys
10import bx.align.axt
11
12def usage(s=None):
13        message = """
14axt_to_fasta species1 species2 < axt_file > fasta_file
15"""
16        if (s == None): sys.exit (message)
17        else:           sys.exit ("%s\n%s" % (s,message))
18
19
20def main():
21
22        # check the command line
23        species1 = sys.argv[1]
24        species2 = sys.argv[2]
25
26        # convert the alignment blocks
27
28        reader = bx.align.axt.Reader(sys.stdin,support_ids=True,\
29                                     species1=species1,species2=species2)
30
31        for a in reader:
32                if ("id" in a.attributes): id = a.attributes["id"]
33                else:                      id = None
34                print_component_as_fasta(a.components[0],id)
35                print_component_as_fasta(a.components[1],id)
36                print
37
38
39# $$$ this should be moved to a bx.align.fasta module
40
41def print_component_as_fasta(c,id=None):
42        header = ">%s_%s_%s" % (c.src,c.start,c.start+c.size)
43        if (id != None): header += " " + id
44        print header
45        print c.text
46
47
48if __name__ == "__main__": main()
49
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。