Example #1
0
File: cr.go Project: mingzhi/pileup
func (cmd *cmdCr) runOne(gPiChan genomePiChan) {
	// Obtain codon table for identifying four-fold degenerate sites.
	codonTable := taxonomy.GeneticCodes()[cmd.codonTableID]
	// Profiling genome using reference sequence and protein feature data.
	ref := gPiChan.genome
	fnaFile := filepath.Join(cmd.genomeDir, ref+".fna")
	gffFile := filepath.Join(cmd.genomeDir, ref+".gff")
	gffs := readGff(gffFile)
	genome := readGenome(fnaFile)
	profile := profiling.ProfileGenome(genome, gffs, codonTable)
	posType := convertPosType(cmd.pos)
	piChunckChan := cmd.split(gPiChan.piChan)
	covsChan := cmd.calc(piChunckChan, profile, posType, cmd.maxl)
	covMVs, xMVs, yMVs := cmd.collect(covsChan)

	cmd.write(ref, covMVs, xMVs, yMVs)
}
Example #2
0
File: ct.go Project: mingzhi/pileup
// Run is the main function.
func (cmd *cmdCt) Run() {
	// The input of pileup can be from standard input,
	// or from a file.
	var f *os.File
	if cmd.pileupFile == "" {
		f = os.Stdin
	} else {
		f = openFile(cmd.pileupFile)
	}
	defer f.Close()

	// Prepare genome position profile.
	genome := readGenome(cmd.fastaFile)
	gffs := readGff(cmd.gffFile)
	codonTable := taxonomy.GeneticCodes()[cmd.codonTableID]
	profile := profiling.ProfileGenome(genome, gffs, codonTable)
	if cmd.regionEnd <= 0 {
		cmd.regionEnd = len(profile)
	}

	// Convert pos from int to byte.
	posType := convertPosType(cmd.pos)

	// Read SNP from pileup input.
	snpChan := readPileup(f, cmd.regionStart, cmd.regionEnd, cmd.pileupFormat)

	// Apply filters.
	filteredSNPChan := cmd.filterSNP(snpChan, profile, posType)

	// Split SNPs into different chuncks.
	snpChanChan := cmd.splitChuncks(filteredSNPChan)

	// For each chunck, do the calculation.
	covsChan := cmd.doCalculation(snpChanChan)

	// Collect results from each chunck.
	csMeanVars, crMeanVars, ctMeanVars := cmd.collect(covsChan, cmd.maxl)

	// And finally, write results into the output file.
	cmd.write(csMeanVars, crMeanVars, ctMeanVars, cmd.outFile)
}