PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/filters/axt_to_concat_fasta.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 51 lines | 45 code | 2 blank | 4 comment | 0 complexity | 092cc0e5bdf15eba96d536326996f17f MD5 | raw file
 1#!/usr/bin/env python
 2"""
 3Adapted from bx/scripts/axt_to_concat_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	sp1text = list()
31	sp2text = list()
32	for a in reader:
33		sp1text.append(a.components[0].text)
34		sp2text.append(a.components[1].text)
35	sp1seq = "".join(sp1text)
36	sp2seq = "".join(sp2text)
37	print_component_as_fasta(sp1seq,species1)
38	print_component_as_fasta(sp2seq,species2)
39		
40
41
42# $$$ this should be moved to a bx.align.fasta module
43
44def print_component_as_fasta(text,src):
45	header = ">" + src
46	print header
47	print text
48
49
50if __name__ == "__main__": main()
51