Skip to content

Commit

Permalink
build step implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
proost committed May 10, 2017
1 parent 9513c4e commit ed537af
Showing 1 changed file with 62 additions and 3 deletions.
65 changes: 62 additions & 3 deletions detector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import click

import os
import tempfile

import subprocess
import shlex


BLAST_MODULE = 'biotools/ncbi-blast-2.3.0+'

BUILD_DB_CMD = 'makeblastdb -dbtype prot -in %s -out %s'


@click.group()
def cli():
Expand All @@ -18,13 +29,61 @@ def cli():

@cli.command()
@click.argument('path', type=click.Path())
def build(path):
@click.argument('db', type=click.Path())
def build(path, db):
"""
Builds the blast database.
usage: detector build PATH (the directory with .fasta files to build the database)
usage: detector build PATH DB
Fasta files in PATH should have the extension .fasta !
The output from makeblastdb will be written to DB.
"""
click.echo("Building the database ... ")
click.echo("Building the database from FASTA files... ")
click.echo("Input path: %s" % path)

full_fasta = tempfile.mktemp()
fasta_count = 0

# find fasta files and concatenate them to a temporary file
with open(full_fasta, 'w') as f_out:
for file in os.listdir(path):
if file.lower().endswith('.fasta'):
click.echo("\tFound file: %s" % file)
fasta_count += 1
with (open(os.path.join(path, file), 'r')) as f_in:
for line in f_in:
f_out.write(line)

click.echo("Concatenated %d fasta files in temporary file %s" % (fasta_count, full_fasta))
click.echo("\nCreating Blast database")

cmd = BUILD_DB_CMD % (full_fasta, db)
click.echo("Executing command: %s" % cmd)
subprocess.call(shlex.split(cmd))

# delete temporary file
os.remove(full_fasta)

# done
click.echo("All done!")


@cli.command()
@click.argument('db', type=click.Path())
@click.argument('output', type=click.Path())
def blast(db, output):
"""
Runs Blast
"""
pass


@cli.command()
@click.argument('input', type=click.Path())
def analyze(intput):
"""
Analyzes blast output
"""
pass

0 comments on commit ed537af

Please sign in to comment.