comparison xmfa2gff3.py @ 3:97a43bcbf44d draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/progressivemauve commit fc61c9d4850614a6580d25f92e3032dc8edbc10d"
author iuc
date Fri, 26 Jun 2020 05:35:25 -0400
parents bca52822843e
children
comparison
equal deleted inserted replaced
2:bdb752f3c6bb 3:97a43bcbf44d
12 ) 12 )
13 from Bio.SeqRecord import SeqRecord 13 from Bio.SeqRecord import SeqRecord
14 14
15 logging.basicConfig(level=logging.INFO) 15 logging.basicConfig(level=logging.INFO)
16 log = logging.getLogger(__name__) 16 log = logging.getLogger(__name__)
17
18
19 # Patch bcbio gff to work around url encoding issue. This is clearly
20 # sub-optimal but we should transition to the newer library.
21 def _new_format_keyvals(self, keyvals):
22 return ";".join(["%s=%s" % (k, ",".join(v)) for (k, v) in sorted(keyvals.items())])
23
24
25 GFF.GFFOutput.GFF3Writer._format_keyvals = _new_format_keyvals
17 26
18 27
19 def parse_xmfa(xmfa): 28 def parse_xmfa(xmfa):
20 """Simple XMFA parser until https://github.com/biopython/biopython/pull/544 29 """Simple XMFA parser until https://github.com/biopython/biopython/pull/544
21 """ 30 """
110 other['feature'] = SeqFeature( 119 other['feature'] = SeqFeature(
111 FeatureLocation(parent['start'], parent['end'] + 1), 120 FeatureLocation(parent['start'], parent['end'] + 1),
112 type="match", strand=parent['strand'], 121 type="match", strand=parent['strand'],
113 qualifiers={ 122 qualifiers={
114 "source": "progressiveMauve", 123 "source": "progressiveMauve",
115 "target": label_convert.get(other['id'], other['id']), 124 "Target": " ".join(map(str, [label_convert.get(other['id'], other['id']), other['start'], other['end'], '+' if other['strand'] > 0 else '-'])),
116 "ID": label_convert.get(other['id'], 'xmfa_' + other['rid']) 125 "ID": label_convert.get(other['id'], 'xmfa_' + other['rid'])
117 } 126 }
118 ) 127 )
119 128
120 for i in range(0, len(lcb[0]['seq']), window_size): 129 for i in range(0, len(lcb[0]['seq']), window_size):
156 return records 165 return records
157 166
158 167
159 if __name__ == '__main__': 168 if __name__ == '__main__':
160 parser = argparse.ArgumentParser(description='Convert XMFA alignments to gff3', prog='xmfa2gff3') 169 parser = argparse.ArgumentParser(description='Convert XMFA alignments to gff3', prog='xmfa2gff3')
161 parser.add_argument('xmfa_file', type=file, help='XMFA File') 170 parser.add_argument('xmfa_file', type=argparse.FileType('r'), help='XMFA File')
162 parser.add_argument('--window_size', type=int, help='Window size for analysis', default=1000) 171 parser.add_argument('--window_size', type=int, help='Window size for analysis', default=1000)
163 parser.add_argument('--relative_to', type=str, help='Index of the parent sequence in the MSA', default='1') 172 parser.add_argument('--relative_to', type=str, help='Index of the parent sequence in the MSA', default='1')
164 parser.add_argument('--sequences', type=file, nargs='+', 173 parser.add_argument('--sequences', type=argparse.FileType('r'), nargs='+',
165 help='Fasta files (in same order) passed to parent for reconstructing proper IDs') 174 help='Fasta files (in same order) passed to parent for reconstructing proper IDs')
166 parser.add_argument('--version', action='version', version='%(prog)s 1.0') 175 parser.add_argument('--version', action='version', version='%(prog)s 1.0')
167 176
168 args = parser.parse_args() 177 args = parser.parse_args()
169 178