func main() { buf := new(bytes.Buffer) if flag.NArg() < 2 { flag.Usage() } // If the quiet flag isn't set, enable verbose output. if !flagQuiet { cablastp.Verbose = true } inputFastaQuery, err := getInputFasta() if err != nil { fatalf("Could not read input fasta query: %s\n", err) } db, err := cablastp.NewReadDB(flag.Arg(0)) if err != nil { fatalf("Could not open '%s' database: %s\n", flag.Arg(0), err) } cablastp.Vprintln("\nBlasting query on coarse database...") if err := blastCoarse(db, inputFastaQuery, buf); err != nil { fatalf("Error blasting coarse database: %s\n", err) } cablastp.Vprintln("Decompressing blast hits...") expandedSequences, err := expandBlastHits(db, buf) if err != nil { fatalf("%s\n", err) } // Write the contents of the expanded sequences to a fasta file. // It is then passed as the "-subject" parameter to blastp. var tmpFine string if tmpFine, err = writeFasta(expandedSequences); err != nil { fatalf("Could not create FASTA input from coarse hits: %s\n", err) } // Finally, run the query against the fine fasta database and pass on the // stdout and stderr... cablastp.Vprintln("Blasting query on fine database...") if _, err := inputFastaQuery.Seek(0, os.SEEK_SET); err != nil { fatalf("Could not seek to start of query fasta input: %s\n", err) } if err := blastFine(db, tmpFine, inputFastaQuery); err != nil { fatalf("Error blasting fine database: %s\n", err) } // Delete the temporary fine database. if !flagNoCleanup { if err := os.Remove(tmpFine); err != nil { fatalf("Could not delete fine fasta database: %s\n", err) } } cleanup(db) }
func main() { if flag.NArg() < 2 { flag.Usage() } // If the quiet flag isn't set, enable verbose output. if !flagQuiet { cablastp.Verbose = true } // Open the fasta file specified for writing. outFasta, err := os.Create(flag.Arg(1)) if err != nil { fatalf("Could not write to '%s': %s\n", flag.Arg(1), err) } fastaWriter := fasta.NewWriter(outFasta) fastaWriter.Asterisk = true // Create a new database for writing. If we're appending, we load // the coarse database into memory, and setup the database for writing. db, err := cablastp.NewReadDB(flag.Arg(0)) if err != nil { fatalf("Could not open '%s' database: %s\n", flag.Arg(0), err) } cablastp.Vprintln("") // Start the CPU profile after all of the data has been read. if len(flagCpuProfile) > 0 { f, err := os.Create(flagCpuProfile) if err != nil { fatalf("%s\n", err) } pprof.StartCPUProfile(f) } numSeqs := db.ComDB.NumSequences() for orgSeqId := 0; orgSeqId < numSeqs; orgSeqId++ { oseq, err := db.ComDB.ReadSeq(db.CoarseDB, orgSeqId) if err != nil { fatalf("Error reading seq id '%d': %s\n", orgSeqId, err) } if err := fastaWriter.Write(oseq.FastaSeq()); err != nil { cablastp.Vprintf("Error writing seq '%s': %s\n", oseq.Name, err) } } cleanup(db) if err = fastaWriter.Flush(); err != nil { fatalf("%s\n", err) } if err = outFasta.Close(); err != nil { fatalf("%s\n", err) } }
func main() { buf := new(bytes.Buffer) if flag.NArg() < 2 { flag.Usage() } if len(flagRPSPath) == 0 { fmt.Fprintln(os.Stderr, "The '--rpspath' flag must be set.") flag.Usage() } // If the quiet flag isn't set, enable verbose output. if !flagQuiet { cablastp.Verbose = true } inputFastaQuery, err := getInputFasta() if err != nil { fatalf("Could not read input fasta query: %s\n", err) } db, err := cablastp.NewReadDB(flag.Arg(0)) if err != nil { fatalf("Could not open '%s' database: %s\n", flag.Arg(0), err) } cablastp.Vprintln("\nBlasting query on coarse database...") if err := blastCoarse(db, inputFastaQuery, buf); err != nil { fatalf("Error blasting coarse database: %s\n", err) } cablastp.Vprintln("Decompressing blast hits...") expandedSequences, err := expandBlastHits(db, buf) if err != nil { fatalf("%s\n", err) } // Write the contents of the expanded sequences to a fasta file. // It is then passed as the "-subject" parameter to blastp. buf.Reset() if err := writeFasta(expandedSequences, buf); err != nil { fatalf("Could not create FASTA input from coarse hits: %s\n", err) } // Create the fine blast db in a temporary directory cablastp.Vprintln("Building fine BLAST database...") tmpDir, err := makeFineBlastDB(db, buf) if err != nil { fatalf("Could not create fine database to search on: %s\n", err) } // Finally, run the query against the fine fasta database and pass on // stdout and stderr... cablastp.Vprintln("Blasting query on fine database...") if _, err := inputFastaQuery.Seek(0, os.SEEK_SET); err != nil { fatalf("Could not seek to start of query fasta input: %s\n", err) } if err := blastFine(db, tmpDir, inputFastaQuery); err != nil { fatalf("Error blasting fine database: %s\n", err) } // Delete the temporary fine database. if !flagNoCleanup { if err := os.RemoveAll(tmpDir); err != nil { fatalf("Could not delete fine BLAST database: %s\n", err) } } cleanup(db) }