Skip to content

Commit

Permalink
implemented blast
Browse files Browse the repository at this point in the history
  • Loading branch information
proost committed May 10, 2017
1 parent 70e97af commit cd2fa4a
Show file tree
Hide file tree
Showing 2 changed files with 799 additions and 4 deletions.
41 changes: 37 additions & 4 deletions detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
RUN_BLAST_CMD = 'blastp -query %s -db %s -out %s -outfmt 6'


def read_blast_line(line):
"""
Parses a line of tabular blast output, returns a dict with the header
:param line: line from a blast file to parse
:return: dict with field names a keys and values the values from the line
"""
header = ['qseqid', 'sseqid', 'pident', 'length', 'mismatch', 'gapopen', 'qstart', 'qend', 'sstart', 'send',
'evalue', 'bitscore']
types = [str, str, float, int, int, int, int, int, int, int, float, float]

return {h: t(v) for h, v, t in zip(header, line.strip().split(), types)}


@click.group()
def cli():
"""
Expand Down Expand Up @@ -49,7 +63,7 @@ def build(path, db):

# find fasta files and concatenate them to a temporary file
with open(full_fasta, 'w') as f_out:
for file in os.listdir(path):
for file in path:
if file.lower().endswith('.fasta'):
click.echo("\tFound file: %s" % file)
fasta_count += 1
Expand Down Expand Up @@ -95,9 +109,28 @@ def blast(fasta, db, output):


@cli.command()
@click.argument('input', type=click.Path())
def analyze(input):
@click.argument('blast_results', type=click.File())
@click.argument('output', type=click.File(mode='w'))
def analyze(blast_results, output):
"""
Analyzes blast output
"""
pass
click.secho("Analyzing file %s ... " % blast_results.name, fg='green', bold=True)

transposable_elements = set()

for line in blast_results:
data = read_blast_line(line)
if data['pident'] > 70:
transposable_elements.add(data['qseqid'])

if len(transposable_elements) > 0:
click.echo("Found %d potential TEs, writing list to %s ..." % (len(transposable_elements), output.name))

for te in transposable_elements:
print(te, file=output)

# done
click.secho("All done!", fg='green', bold=True)


Loading

0 comments on commit cd2fa4a

Please sign in to comment.