コード例 #1
0
ファイル: main.go プロジェクト: yesimon/MICA
func main() {

	if flag.NArg() != 2 {
		flag.Usage()
	}

	// If the quiet flag isn't set, enable verbose output.
	if !flagQuiet {
		mica.Verbose = true
	}

	db, err := mica.NewReadDB(flag.Arg(0))
	if err != nil {
		fatalf("Could not open '%s' database: %s\n", flag.Arg(0), err)
	}

	inputFastaQueryName := flag.Arg(1)
	aaQueryFile, err := os.Open(inputFastaQueryName)
	if err != nil {
		fatalf("Could not open '%s' query file: %s\n", inputFastaQueryName, err)
	}

	mica.Vprintln("\nProcessing Queries...")
	err = processQueries(db, aaQueryFile)
	if err != nil {
		fatalf("Error processing queries: %s\n", err)
	}

	cleanup(db)
}
コード例 #2
0
ファイル: main.go プロジェクト: Rinoahu/MICA
func main() {
	if flag.NArg() < 2 {
		flag.Usage()
	}

	// If the quiet flag isn't set, enable verbose output.
	if !flagQuiet {
		mica.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 := mica.NewReadDB(flag.Arg(0))
	if err != nil {
		fatalf("Could not open '%s' database: %s\n", flag.Arg(0), err)
	}
	mica.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 {
			mica.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)
	}
}
コード例 #3
0
ファイル: main.go プロジェクト: Rinoahu/MICA
func main() {

	if flag.NArg() != 2 {
		flag.Usage()
	}

	// If the quiet flag isn't set, enable verbose output.
	if !flagQuiet {
		mica.Verbose = true
	}

	db, err := mica.NewReadDB(flag.Arg(0))
	if err != nil {
		fatalf("Could not open '%s' database: %s\n", flag.Arg(0), err)
	}

	inputFastaQueryName := flag.Arg(1)

	if flagCompressQuery {
		fatalf("Query compression is currently unsupported.\nExiting.\n", "")
		mica.Vprintln("\nProcessing queries with query-side compression...")
		err = processCompressedQueries(db, inputFastaQueryName)
		if err != nil {
			fatalf("Error processing queries with query-side compression: %s\n", err)
		}
	} else {

		mica.Vprintln("\nProcessing queries...")
		err = processQueries(db, inputFastaQueryName)
		if err != nil {
			fatalf("Error processing queries: %s\n", err)
		}
	}

	cleanup(db)
}
コード例 #4
0
ファイル: main.go プロジェクト: Rinoahu/MICA
func main() {
	buf := new(bytes.Buffer)

	if flag.NArg() < 2 {
		flag.Usage()
	}

	// If the quiet flag isn't set, enable verbose output.
	if !flagQuiet {
		mica.Verbose = true
	}

	inputFastaQuery, err := getInputFasta()
	if err != nil {
		fatalf("Could not read input fasta query: %s\n", err)
	}

	db, err := mica.NewReadDB(flag.Arg(0))
	if err != nil {
		fatalf("Could not open '%s' database: %s\n", flag.Arg(0), err)
	}

	mica.Vprintln("\nBlasting query on coarse database...")
	if err := blastCoarse(db, inputFastaQuery, buf); err != nil {
		fatalf("Error blasting coarse database: %s\n", err)
	}

	mica.Vprintln("Decompressing blast hits...")
	expandedSequences, err := expandBlastHits(db, buf)
	if err != nil {
		fatalf("%s\n", err)
	}

	// Clear the buffer and write the fasta file to it.
	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
	mica.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...
	mica.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)
}
コード例 #5
0
ファイル: query-compression.go プロジェクト: Rinoahu/MICA
func processCompressedQueries(db *mica.DB, nuclQueryFileLoc string) error {

	queryDbLoc, err := compressQueries(nuclQueryFileLoc)
	if err != nil {
		return fmt.Errorf("Error compressing queries: %s\n", err)
	}

	queryDb, err := mica.NewReadDB(queryDbLoc)
	if err != nil {
		return fmt.Errorf("Error opening newly created compressed query db: %s\n", err)
	}

	mica.Vprintln("\nBlasting with diamond query on coarse database...")
	dmndOutDaaFilename, err := dmndBlastXCoarse(db, queryDb.CoarseDB.FileFasta.Name())
	if err != nil {
		return fmt.Errorf("Error blasting with diamond on coarse database from compressed queries: %s\n", err)
	}

	dmndOutFile, err := convertDmndToBlastTabular(dmndOutDaaFilename)
	if err != nil {
		return fmt.Errorf("Error converting diamond output to blast tabular: %s\n")
	}

	mica.Vprintln("Decompressing diamond hits...")
	dmndOutArr, err := ioutil.ReadAll(dmndOutFile)

	// nuclQueryFile, err := os.Open(nuclQueryFileLoc)
	// if err != nil {
	// 	fatalf("Could not open '%s' query file for fine search: %s\n", nuclQueryFileLoc, err)
	// }

	if !flagNoCleanup {
		err := os.RemoveAll(dmndOutFile.Name())
		handleFatalError("Could not delete diamond output from coarse search", err)
		err = os.RemoveAll(dmndOutDaaFilename)
		handleFatalError("Could not delete diamond output from coarse search", err)
		err = os.RemoveAll(queryDbLoc)
		handleFatalError("Could not delete diamond output from coarse search", err)
	}

	if err != nil {
		return fmt.Errorf("Could not read diamond output: %s", err)
	}
	if len(dmndOutArr) == 0 {
		return fmt.Errorf("No coarse hits. %s", "Aborting.")
	}
	mica.Vprintln("Expanding diamond hits (queries and targets)...")
	dmndOut := bytes.NewBuffer(dmndOutArr)
	expandedSequences, expandedQueries, err := expandDmndHitsAndQuery(db, queryDb, dmndOut)
	if err != nil {
		return fmt.Errorf("%s\n", err)
	}

	// Write the contents of the expanded sequences to a fasta file.
	// It is then indexed using makeblastdb.
	searchBuf := new(bytes.Buffer)
	if err := writeFasta(expandedSequences, searchBuf); err != nil {
		fatalf("Could not create FASTA input from coarse hits: %s\n", err)
	}

	qSearchBuf := new(bytes.Buffer)
	if err := writeFasta(expandedQueries, qSearchBuf); err != nil {
		fatalf("Could not create FASTA input from coarse QUERY hits: %s\n", err)
	}
	fineQueryFile, err := ioutil.TempFile(flagTempFileDir, "fine-query-sequences")
	if err != nil {
		fatalf("Could not create temporary QUERY sequence file: %s\n", err)
	}
	err = ioutil.WriteFile(fineQueryFile.Name(), qSearchBuf.Bytes(), 0666)
	if err != nil {
		fatalf("Could not write to temporary QUERY sequence file: %s\n", err)
	}

	if flagDmndFine != "" {

		mica.Vprintln("Building fine DIAMOND database...")
		tmpFineDB, err := makeFineDmndDB(searchBuf)
		handleFatalError("Could not create fine diamond database to search on", err)

		err = dmndBlastXFine(fineQueryFile.Name(), flagDmndFine, tmpFineDB)
		handleFatalError("Error diamond-blasting (x-search) fine database", err)

		// Delete the temporary fine database.
		if !flagNoCleanup {
			err := os.RemoveAll(tmpFineDB)
			err = os.RemoveAll(tmpFineDB + ".dmnd")
			handleFatalError("Could not delete fine DIAMOND database", err)
		}

	} else {

		// Create the fine blast db in a temporary directory
		mica.Vprintln("Building fine BLAST database...")
		tmpFineDB, err := makeFineBlastDB(db, searchBuf)
		handleFatalError("Could not create fine blast database to search on", err)

		// retrieve the cluster members for the original representative query seq

		// pass them to blastx on the expanded (fine) db

		// Finally, run the query against the fine fasta database and pass on the
		// stdout and stderr...
		bs, err := ioutil.ReadAll(fineQueryFile)
		if err != nil {
			return fmt.Errorf("Could not read input fasta query: %s", err)
		}
		nuclQueryReader := bytes.NewReader(bs)

		err = blastFine(db, tmpFineDB, nuclQueryReader)
		handleFatalError("Error blasting fine database (x-search):", err)

		// Delete the temporary fine database.
		if !flagNoCleanup {
			err := os.RemoveAll(tmpFineDB)
			handleFatalError("Could not delete fine BLAST database", err)
		}
	}

	return nil
}