예제 #1
0
func TranslateQuerySeqs(
	query *bytes.Reader, action SearchOperator) (*bytes.Reader, error) {

	buf := new(bytes.Buffer)
	f := fasta.NewWriter(buf)
	reader := fasta.NewReader(query)
	for i := 0; true; i++ {
		sequence, err := reader.Read()
		if err == io.EOF {
			break
		}
		if err != nil {
			return nil, err
		}
		origSeq := sequence.Bytes()
		n := sequence.Name
		// generate 6 ORFs
		transSeqs := Translate(origSeq)
		for _, s := range transSeqs {
			result := seq.NewSequenceString(n, string(Reduce(s)))
			f.Write(result)
		}

	}

	return bytes.NewReader(buf.Bytes()), nil
}
예제 #2
0
파일: main.go 프로젝트: ndaniels/cablastp2
func translateQueries(reader *fasta.Reader, f *fasta.Writer) error {

	sequence, err := reader.Read()
	if err == io.EOF {
		return nil
	}
	if err != nil {
		fatalf("Could not read input fasta query: %s\n", err)
	}

	origSeq := sequence.Bytes()
	n := sequence.Name
	// generate 6 ORFs
	transSeqs := cablastp.Translate(origSeq)

	for _, s := range transSeqs {
		// reduce each one
		result := seq.NewSequenceString(n, string(cablastp.Reduce(s)))

		f.Write(result)

	}
	f.Flush()
	return nil
}
예제 #3
0
파일: fasta.go 프로젝트: ndaniels/cablastp2
func ReduceQuerySeqs(
	query *bytes.Reader) (*bytes.Reader, error) {
	buf := new(bytes.Buffer)
	f := fasta.NewWriter(buf)
	reader := fasta.NewReader(query)
	for i := 0; true; i++ {
		sequence, err := reader.Read()
		if err == io.EOF {
			break
		}
		if err != nil {
			return nil, err
		}
		rs := Reduce(sequence.Bytes())
		n := sequence.Name

		result := seq.NewSequenceString(n, string(rs))
		f.Write(result)
	}
	f.Flush()

	return bytes.NewReader(buf.Bytes()), nil
}
예제 #4
0
파일: main.go 프로젝트: ndaniels/cablastp2
func processCompressedQueries(db *cablastp.DB, queryDBConf *cablastp.DBConf, inputQueryFilename string, searchBuf *bytes.Buffer) error {
	cablastp.Vprintln("Compressing queries into a database...")
	dbDirLoc := "./tmp_query_database" // TODO this should be a parameter
	qDBDirLoc, err := compressQueries(inputQueryFilename, queryDBConf, dbDirLoc)
	handleFatalError("Error compressing queries", err)
	cablastp.Vprintln("Opening DB for reading")
	qDB, err := cablastp.NewReadDB(qDBDirLoc)
	handleFatalError("Error opening query database", err)
	cablastp.Vprintln("Opening compressed queries for search...")
	compQueryFilename := qDB.CoarseFastaLocation()
	compQueries, err := getInputFasta(compQueryFilename)
	handleFatalError("Error opening compressed query file", err)

	queryBuf := new(bytes.Buffer)
	f := fasta.NewWriter(queryBuf)
	reader := fasta.NewReader(compQueries)

	for origSeqID := 0; true; origSeqID++ {

		sequence, err := reader.Read()
		if err == io.EOF {
			break
		}

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

		origSeq := sequence.Bytes()
		n := sequence.Name
		// generate 6 ORFs
		transSeqs := cablastp.Translate(origSeq)
		for _, s := range transSeqs {
			// reduce each one
			result := seq.NewSequenceString(n, string(cablastp.Reduce(s)))

			f.Write(result)

		}

		f.Flush()
		transCoarseQueries := bytes.NewReader(queryBuf.Bytes())

		cablastp.Vprintln("\nBlasting query on coarse database...")
		err = blastCoarse(db, transCoarseQueries, searchBuf)
		handleFatalError("Error blasting coarse database", err)

		cablastp.Vprintln("Decompressing coarse blast hits...")
		expandedSequences, err := expandBlastHits(db, searchBuf)
		handleFatalError("Error decompressing coarse blast hits", err)
		if len(expandedSequences) == 0 {
			cablastp.Vprintln("No results from coarse search")
		} else {
			cablastp.Vprintln("Making FASTA from coarse blast hits...")
			searchBuf.Reset()
			err = writeFasta(expandedSequences, searchBuf)
			handleFatalError("Could not create FASTA input from coarse hits", err)

			cablastp.Vprintln("Expanding coarse query...")
			expQuery, err := expandCoarseSequence(qDB, origSeqID, &sequence)
			handleFatalError("Could not expand coarse queries", err)

			fineQueryBuf := new(bytes.Buffer)
			fineWriter := fasta.NewWriter(fineQueryBuf)
			for _, fineQuery := range expQuery {
				fineQueryBytes := fineQuery.FastaSeq().Bytes() // <- Is This the same as fineQuery.Residues()?
				fineName := fineQuery.Name
				writeSeq := seq.NewSequenceString(fineName, string(fineQueryBytes))
				fineWriter.Write(writeSeq)
			}
			fineWriter.Flush()
			transFineQueries := bytes.NewReader(fineQueryBuf.Bytes())

			cablastp.Vprintln("Building fine BLAST target database...")
			targetTmpDir, err := makeFineBlastDB(db, searchBuf)
			handleFatalError("Could not create fine database to search on", err)

			cablastp.Vprintln("Blasting original query on fine database...")
			err = blastFine(db, targetTmpDir, transFineQueries)
			handleFatalError("Error blasting fine database", err)
			err = os.RemoveAll(targetTmpDir)
			handleFatalError("Could not remove fine database", err)
		}
		queryBuf.Reset()
	}
	cablastp.Vprintln("Cleaning up...")
	err = os.RemoveAll(dbDirLoc)
	handleFatalError("Could not remove query database", err)
	return nil
}