Ejemplo n.º 1
0
func makeFineDmndDB(seqBuf *bytes.Buffer) (string, error) {
	tmpSeqFile, err := ioutil.TempFile(".", "fine-sequences-")
	if err != nil {
		return "", fmt.Errorf("Could not create temporary sequence file: %s\n", err)
	}
	err = ioutil.WriteFile(tmpSeqFile.Name(), seqBuf.Bytes(), 0666)
	if err != nil {
		return "", fmt.Errorf("Could not write to temporary sequence file: %s\n", err)
	}
	tmpDmndFile, err := ioutil.TempFile(".", "fine-dmnd-db-")
	if err != nil {
		return "", fmt.Errorf("Could not create temporary diamond file: %s\n", err)
	}
	cmd := exec.Command(
		flagDmnd,
		"makedb",
		"--in", tmpSeqFile.Name(),
		"-d", tmpDmndFile.Name())

	err = mica.Exec(cmd)
	if err != nil {
		return "", fmt.Errorf("Could not create fine diamond database: %s\n", err)
	}

	err = os.RemoveAll(tmpSeqFile.Name())
	if err != nil {
		return "", fmt.Errorf("Could not remove temporary sequence file: %s\n", err)
	}

	return tmpDmndFile.Name(), nil

}
Ejemplo n.º 2
0
func convertDmndToBlastTabular(daa *os.File) (*os.File, error) {
	dmndOutFile, err := ioutil.TempFile(".", "dmnd-out-tab-")
	if err != nil {
		return nil, fmt.Errorf("Could not build temporary file for diamond output: %s", err)
	}

	cmd := exec.Command(
		flagDmnd,
		"view",
		"-o", dmndOutFile.Name(),
		"-a", daa.Name())

	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout

	err = mica.Exec(cmd)
	if err != nil {
		return nil, fmt.Errorf("Error converting daa file to blast tabular: %s", err)
	}
	// err = os.Remove(daa.Name())
	// if err != nil {
	// 	return nil, fmt.Errorf("Error destroying .daa file: %s", err)
	// }
	return dmndOutFile, nil
}
Ejemplo n.º 3
0
func dmndBlastXFine(queries *os.File, outFilename, fineFilename string) error {

	cmd := exec.Command(
		flagDmnd,
		"blastx",
		"--sensitive",
		"-d", fineFilename,
		"-q", queries.Name(),
		"--threads", s(flagGoMaxProcs),
		"-a", outFilename,
		"--compress", "0",
		"-c", "1",
		"--top", s(flagFineDmndMatch))
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout

	err := mica.Exec(cmd)
	if err != nil {
		return fmt.Errorf("Error using diamond to blast coarse db: %s\n", err)
	}
	if !flagDmndOutput {
		daaFile, err := os.Open(outFilename)
		if err != nil {
			return fmt.Errorf("Error opening diamond output: %s\n", err)
		}
		tabularFile, err := convertDmndToBlastTabular(daaFile)
		if err != nil {
			return fmt.Errorf("Error converting diamond output: %s\n", err)
		}
		os.Rename(tabularFile.Name(), outFilename)

	}

	return nil
}
Ejemplo n.º 4
0
func dmndBlastPCoarse(db *mica.DB, queries *os.File) (*os.File, error) {
	// diamond blastp -d nr -q reads.fna -a matches -t <temporary directory>

	dmndOutFile, err := ioutil.TempFile(".", "dmnd-out-")
	if err != nil {
		return nil, fmt.Errorf("Could not build temporary file for diamond output: %s", err)
	}

	cmd := exec.Command(
		flagDmnd,
		"blastp",
		"--sensitive",
		"-d", path.Join(db.Path, mica.FileDmndCoarse),
		"-q", queries.Name(),
		"--threads", s(flagGoMaxProcs),
		"-o", dmndOutFile.Name(),
		"--compress", "0",
		"-c", "1",
		"--top", s(flagCoarseDmndMatch))
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout

	err = mica.Exec(cmd)
	if err != nil {
		return nil, fmt.Errorf("Error using diamond to blast coarse db: %s", err)
	}

	return dmndOutFile, nil
}
Ejemplo n.º 5
0
func dmndBlastXCoarse(db *mica.DB, queryFilename string) (string, error) {
	// diamond blastp -d nr -q reads.fna -a matches -t <temporary directory>

	dmndOutFilename := flagTempFileDir + "/dmnd-blastx-out-temp"

	cmd := exec.Command(
		flagDmnd,
		"blastx",
		"--sensitive",
		"-d", path.Join(db.Path, mica.FileDmndCoarse),
		"-q", queryFilename,
		"--threads", s(flagGoMaxProcs),
		"-a", dmndOutFilename,
		"--compress", "0",
		"--top", s(flagCoarseDmndMatch),
		"--tmpdir", flagTempFileDir)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout

	err := mica.Exec(cmd)
	if err != nil {
		return "", fmt.Errorf("Error using diamond to blast coarse db: %s", err)
	}

	dmndOutFilename = dmndOutFilename + ".daa"

	return dmndOutFilename, nil
}
Ejemplo n.º 6
0
Archivo: main.go Proyecto: Rinoahu/MICA
func blastCoarse(
	db *mica.DB, stdin *bytes.Reader, stdout *bytes.Buffer) error {
	flags := []string{"-db", path.Join(db.Path, mica.FileBlastCoarse),
		"-outfmt", "5", "-num_iterations", s(flagIters),
		"-dbsize", su(db.BlastDBSize)}

	cmd := exec.Command(flagPsiBlast, flags...)
	cmd.Stdin = stdin
	cmd.Stdout = stdout
	return mica.Exec(cmd)
}
Ejemplo n.º 7
0
func blastCoarse(
	db *mica.DB, stdin *bytes.Reader, stdout *bytes.Buffer) error {

	cmd := exec.Command(
		flagBlastp,
		"-db", path.Join(db.Path, mica.FileBlastCoarse),
		"-num_threads", s(flagGoMaxProcs),
		"-outfmt", "5", "-dbsize", su(db.BlastDBSize))
	cmd.Stdin = stdin
	cmd.Stdout = stdout
	return mica.Exec(cmd)
}
Ejemplo n.º 8
0
Archivo: main.go Proyecto: Rinoahu/MICA
func blastCoarse(
	db *mica.DB, stdin *bytes.Reader, stdout *bytes.Buffer) error {

	cmd := exec.Command(
		flagDeltaBlast,
		"-db", path.Join(db.Path, mica.FileBlastCoarse),
		"-rpsdb", flagRPSPath,
		"-outfmt", "5", "-dbsize", su(db.BlastDBSize))
	cmd.Stdin = stdin
	cmd.Stdout = stdout
	return mica.Exec(cmd)
}
Ejemplo n.º 9
0
Archivo: main.go Proyecto: Rinoahu/MICA
func blastFine(
	db *mica.DB, blastFineDir string, stdin *bytes.Reader) error {

	// We pass our own "-db" flag to blastp, but the rest come from user
	// defined flags.
	flags := []string{"-db", path.Join(blastFineDir, mica.FileBlastFine),
		"-num_iterations", s(flagIters),
		"-dbsize", su(db.BlastDBSize)}
	flags = append(flags, blastArgs...)

	cmd := exec.Command(flagPsiBlast, flags...)
	cmd.Stdin = stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	return mica.Exec(cmd)
}
Ejemplo n.º 10
0
func makeFineBlastDB(db *mica.DB, stdin *bytes.Buffer) (string, error) {
	tmpDir, err := ioutil.TempDir("", "mica-fine-search-db")
	if err != nil {
		return "", fmt.Errorf("Could not create temporary directory: %s\n", err)
	}

	cmd := exec.Command(
		flagMakeBlastDB, "-dbtype", "prot",
		"-title", mica.FileBlastFine,
		"-in", "-",
		"-out", path.Join(tmpDir, mica.FileBlastFine))
	cmd.Stdin = stdin

	mica.Vprintf("Created temporary fine BLAST database in %s\n", tmpDir)

	return tmpDir, mica.Exec(cmd)
}
Ejemplo n.º 11
0
Archivo: main.go Proyecto: Rinoahu/MICA
func blastFine(
	db *mica.DB, blastFineDir string, stdin *bytes.Reader) error {

	// We pass our own "-db" flag to blastp, but the rest come from user
	// defined flags.
	// deltablast needs a rpsdb path
	flags := []string{
		"-db", path.Join(blastFineDir, mica.FileBlastFine),
		"-rpsdb", flagRPSPath,
		"-dbsize", su(db.BlastDBSize),
		"-num_threads", s(flagGoMaxProcs),
	}
	flags = append(flags, blastArgs...)

	cmd := exec.Command(flagDeltaBlast, flags...)
	cmd.Stdin = stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	return mica.Exec(cmd)
}