Mercurial > repos > abims-sbr > pairwise
comparison scripts/S03_run_second_blast.py @ 0:90b57ab0bd1d draft default tip
planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 3c7982d775b6f3b472f6514d791edcb43cd258a1-dirty
| author | abims-sbr |
|---|---|
| date | Fri, 01 Feb 2019 10:23:16 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:90b57ab0bd1d |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 # coding: utf-8 | |
| 3 # Author : Victor Mataigne | |
| 4 | |
| 5 import itertools, argparse, os | |
| 6 | |
| 7 def main(): | |
| 8 parser = argparse.ArgumentParser() | |
| 9 parser.add_argument('query_file', help='fasta file (to translate) for query') | |
| 10 parser.add_argument('db_file', help='fasta files (already translated) for db') | |
| 11 parser.add_argument('file_subname', help='keyword for output file name') | |
| 12 parser.add_argument('evalue', help='evalue for blast') | |
| 13 parser.add_argument('method', choices=['tblastx', 'diamond'], help='alignment tool (tblastx or diamond)') | |
| 14 args = parser.parse_args() | |
| 15 | |
| 16 if args.method == 'diamond': | |
| 17 from Bio.Seq import Seq | |
| 18 from Bio.Alphabet import IUPAC | |
| 19 # Traduire les best hits | |
| 20 f_name = 'translated_{}'.format(args.query_file) | |
| 21 translated_file = open(f_name, 'w') | |
| 22 with open(args.query_file, 'r') as file: | |
| 23 for name, seq in itertools.izip_longest(*[file]*2): | |
| 24 s = Seq(seq.strip('\n').upper(), IUPAC.ambiguous_dna) | |
| 25 translated_file.write(name.strip('\n')+'_orf_1\n') | |
| 26 translated_file.write(s.translate()._data+'\n') | |
| 27 translated_file.write(name.strip('\n')+'_orf_2\n') | |
| 28 translated_file.write(s[1:].translate()._data+'\n') | |
| 29 translated_file.write(name.strip('\n')+'_orf_3\n') | |
| 30 translated_file.write(s[2:].translate()._data+'\n') | |
| 31 translated_file.close() | |
| 32 | |
| 33 os.system('diamond makedb --in %s -d %s >> log_diamond.log' %(args.db_file, args.db_file.split('_')[1])) | |
| 34 os.system('diamond blastp -q %s -d %s --max-target-seqs 1 -o matches_blast2_%s -e %s --more-sensitive >> log_diamond.log' %(f_name, args.db_file.split('_')[1], args.file_subname, args.evalue)) | |
| 35 | |
| 36 elif args.method == 'tblastx': | |
| 37 os.system('formatdb -i %s -p F -o T >> log_tblastx.log' %(args.db_file)) | |
| 38 os.system('blastall -p tblastx -d %s -i %s -o matches_blast2_%s -T F -e %s -F "mS" -b1 -v1 -K 1 -m 8 >> log_tblastx.log' %(args.db_file, args.query_file, args.file_subname, args.evalue)) | |
| 39 | |
| 40 else : | |
| 41 print 'Mispecified alignment tool' | |
| 42 exit() | |
| 43 | |
| 44 if __name__ == "__main__": | |
| 45 main() |
