# HG changeset patch # User artbio # Date 1507048913 14400 # Node ID 50c1fa95a07671b79fe93239ec9ccb7f06da4a63 # Parent f3b63b59a1ea63ce84570ac6cadc31aff303ffc8 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_unmatched commit be082f72c8d8c1eebe3f5643da1a73ab0ac9e4b3 diff -r f3b63b59a1ea -r 50c1fa95a076 blast_unmatched.py --- a/blast_unmatched.py Tue Oct 03 07:19:17 2017 -0400 +++ b/blast_unmatched.py Tue Oct 03 12:41:53 2017 -0400 @@ -23,12 +23,11 @@ Get a dictionary of all the queries that got a match """ matched = dict() - blast_file_handle = open(blast_file, 'r') - for line in blast_file_handle.readlines(): - fields = line.split("\t") - query_id = fields[0] - matched[query_id] = 1 - blast_file_handle.close() + with open(blast_file, 'r') as infile: + for line in infile: + fields = line.split("\t") + query_id = fields[0] + matched[query_id] = 1 return matched def get_unmatched(output_file, fasta_file, matched): @@ -36,19 +35,18 @@ Compares matched queries to query fasta file and print unmatched to ouput """ output_file_handle = open(output_file, 'w') - fasta_file_handle = open(fasta_file, 'r') unmatched = False - for line in fasta_file_handle.readlines(): - if line.startswith('>'): - subline = line[1:100].rstrip() #qid are 100chars long in blast - if subline not in matched: + with open(fasta_file, 'r') as infile: + for line in infile: + if line.startswith('>'): + subline = line[1:100].rstrip() #qid are 100chars long in blast + if subline not in matched: + output_file_handle.write(line) + unmatched = True + else: + unmatched = False + elif unmatched: output_file_handle.write(line) - unmatched = True - else: - unmatched = False - elif unmatched: - output_file_handle.write(line) - fasta_file_handle.close() output_file_handle.close() def __main__(): diff -r f3b63b59a1ea -r 50c1fa95a076 blast_unmatched.xml --- a/blast_unmatched.xml Tue Oct 03 07:19:17 2017 -0400 +++ b/blast_unmatched.xml Tue Oct 03 12:41:53 2017 -0400 @@ -1,4 +1,4 @@ - + get query sequences that didn't get a match during a blast