Skip to content

Instantly share code, notes, and snippets.

@knmkr
Last active October 15, 2022 14:59
Show Gist options
  • Save knmkr/5393474 to your computer and use it in GitHub Desktop.
Save knmkr/5393474 to your computer and use it in GitHub Desktop.
How to use blast from command-line, on Mac OS X.

#How to use blast from command-line, on Mac OS X.

Install blast

Download executables (binary) of blast-commands for Mac OS X.

$ curl -O ftp://ftp.ncbi.nih.gov/blast/executables/blast+/2.2.28/ncbi-blast-2.2.28+.dmg
or
$ wget ftp://ftp.ncbi.nih.gov/blast/executables/blast+/2.2.28/ncbi-blast-2.2.28+.dmg

Install via ncbi-blast-2.2.28+.dmg

Then, you can use folowing commands,

$ blastp -version
blastp: 2.2.28+
Package: blast 2.2.28, build Mar 13 2013 10:25:37
$ makeblastdb -version
makeblastdb: 2.2.28+
Package: blast 2.2.28, build Mar 13 2013 10:25:37

Next, download fasta-file to create database for blast. In this example, we use Swissprot.

$ curl -O ftp://ftp.ncbi.nih.gov/blast/db/FASTA/swissprot.gz
$ gunzip swissprot.gz
$ head swissprot
>gi|13878750|sp|Q9CDN0.1|RS18_LACLA RecName: Full=30S ribosomal protein S18gi|122939895|sp|Q02VU1.1|RS18_LACLS RecName: Full=30S ribosomal protein S18gi|166220956|sp|A2RNZ2.1|RS18_LACLM RecName: Full=30S ribosomal protein S18
MAQQRRGGFKRRKKVDFIAANKIEVVDYKDTELLKRFISERGKILPRRVTGTSAKNQRKVVNAIKRARVMALLPFVAEDQ
N
>gi|1705556|sp|P54670.1|CAF1_DICDI RecName: Full=Calfumirin-1; Short=CAF-1
MASTQNIVEEVQKMLDTYDTNKDGEITKAEAVEYFKGKKAFNPERSAIYLFQVYDKDNDGKITIKELAGDIDFDKALKEY
KEKQAKSKQQEAEVEEDIEAFILRHNKDDNTDITKDELIQGFKETGAKDPEKSANFILTEMDTNKDGTITVKELRVYYQK
VQKLLNPDQ
>gi|30172867|sp|Q8G5F3.1|ARLY_BIFLO RecName: Full=Argininosuccinate lyase; Short=ASAL; AltName: Full=Arginosuccinasegi|238692068|sp|B3DSY6.1|ARLY_BIFLD RecName: Full=Argininosuccinate lyase; Short=ASAL; AltName: Full=Arginosuccinase
MTENNEHLALWGGRFTSGPSPELARLSKSTQFDWRLADDDIAGSRAHARALGRAGLLTADELQRMEDALDTLQRHVDDGS
FAPIEDDEDEATALERGLIDIAGDELGGKLRAGRSRNDQIACLIRMWLRRHSRVIAGLLLDLVNALIEQSEKAGRTVMPG

Then, create databese for blast form this fasta-file.

$ mv swissprot swissprot.fa
$ mkdir -p db/blast/
$ makeblastdb -in swissprot.fa -dbtype prot -out db/blast/swissprot -hash_index
$ ls db/blast/
swissprot.phd swissprot.phi swissprot.phr swissprot.pin swissprot.pog swissprot.psd swissprot.psi swissprot.psq

Use blast from command-line

In this example, we will use blastp. blastp is for,

query: protein, database: protein.

Use like following,

$ cat test.fa 
>test
GGG
$ blastp -query test.fa -db /path/to/swissprot/swissprot
BLASTP 2.2.28+
...

Query= test

Length=3


***** No hits found *****
...

Notice: For option -db, you have to write /path/to/db/<db-name>, e.g.,

$ ls /Users/numa/blast/db/swissprot
swissprot.fa  swissprot.phd swissprot.phi swissprot.phr swissprot.pin swissprot.pog swissprot.psd swissprot.psi swissprot.psq
$ blastp -query test.fa -db /Users/numa/blast/db/swissprot/swissprot

Otherwise (setting just path to db directory /path/to/db/), you will get foloowing error.

$ blastp -query test.fa -db /Users/numa/blast/db/swissprot
BLAST Database error: No alias or index file found for protein database [/Users/numa/blast/db/swissprot] in search path [/Users/numa/blast/db::]
@edgingtonn1
Copy link

Thanks, your comments helped me get blastp working!

@Worarado
Copy link

Worarado commented May 8, 2018

Hello,

Could I asks? why when I run ; makeblastdb -in swissprot.fa -dbtype prot -out db/blast/swissprot -hash_index
This showed ; bash: makeblastdb: command not found...

I try to install swissprot in Linux base and my ncbi-blast program ver 2.3.0

Thank you

@anatori
Copy link

anatori commented Aug 5, 2019

Is it possible to use -subject instead of -db to test a single fasta file? For example:
blastn -query test.fasta -subject aclamedb.fasta -outfmt '7 delim=,' -out output.csv
or does this effect how BLAST is performed?

@bioinfonext
Copy link

Hi

I have installed the NCBI blast by using ncbi-blast-2.2.28+.dmg and at the end it says that installation is successful but when I am running the below command it says command not found?

admins-imac-3:tools ygupta$ blastp -version
-bash: blastp: command not found
admins-imac-3:tools ygupta$ ls
ncbi-blast-2.2.28+.dmg
admins-imac-3:tools ygupta$ makeblastdb -version
-bash: makeblastdb: command not found
admins-imac-3:tools ygupta$

could you please help me with this?

thanks
Yogesh

@VeronicaValencia
Copy link

@yogeshgupt

I know this question is quite old but maybe my answer could help someone. I think it may be a problem with $PATH. I had the same issues, so I installed Bioconda from:

[https://bioconda.github.io/user/install.html]

Then I installed Blast using conda with:

conda install -c bioconda blast
or
conda install -c bioconda/label/cf201901 blast

This fixed it. I hope this is helpful.

-VRK

@zhiyongliu1
Copy link

your comments help me a lot! thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment