Beispiel #1
0
func (g *FastJInfo) EmitAlignedInterleave(ref, alt0, alt1 []byte, out *bufio.Writer) {
	length_bound := 10000

	if len(ref) == 0 {
		return
	}

	p0 := make([]byte, 0, len(ref))
	p1 := make([]byte, 0, len(ref))

	// We can bypass doing a string alignment if they're equal, so test
	// for equal (considering 'n' (nocall) entries as wildcards).
	//
	if !_noc_eq(ref, alt0) {

		if (len(ref) > length_bound) || (len(alt0) > length_bound) {
			ref0, algn0 := g.ClumsyAlign(ref, alt0)
			for ii := 0; ii < len(ref0); ii++ {
				p0 = append(p0, pasta.SubMap[ref0[ii]][algn0[ii]])
			}
		} else {
			ref0, algn0, sc0 := memz.Hirschberg(ref, alt0)
			_ = sc0
			for ii := 0; ii < len(ref0); ii++ {
				p0 = append(p0, pasta.SubMap[ref0[ii]][algn0[ii]])
			}
		}

	} else {
		for ii := 0; ii < len(ref); ii++ {
			p0 = append(p0, pasta.SubMap[ref[ii]][alt0[ii]])
		}
	}

	if !_noc_eq(ref, alt1) {

		if (len(ref) > length_bound) || (len(alt1) > length_bound) {
			ref1, algn1 := g.ClumsyAlign(ref, alt1)
			for ii := 0; ii < len(ref1); ii++ {
				p1 = append(p1, pasta.SubMap[ref1[ii]][algn1[ii]])
			}
		} else {
			ref1, algn1, sc1 := memz.Hirschberg(ref, alt1)
			_ = sc1
			for ii := 0; ii < len(ref1); ii++ {
				p1 = append(p1, pasta.SubMap[ref1[ii]][algn1[ii]])
			}
		}

	} else {
		for ii := 0; ii < len(ref); ii++ {
			p1 = append(p1, pasta.SubMap[ref[ii]][alt1[ii]])
		}
	}

	r0 := bytes.NewReader(p0)
	r1 := bytes.NewReader(p1)

	g.Out = out
	pasta.InterleaveStreams(r0, r1, g)
}
Beispiel #2
0
func _main(c *cli.Context) {
	var e error
	action := "echo"

	msg_slice := c.StringSlice("Message")
	msg_str := ""
	for i := 0; i < len(msg_slice); i++ {
		msg_str += ">" + msg_slice[i]
	}

	//if c.String("action") != "" { action = c.String("action") }
	if len(c.String("action")) == 0 {
		cli.ShowAppHelp(c)
		return
	}

	action = c.String("action")

	if action == "diff-rotini" {
		_main_diff_to_rotini(c)
		return
	} else if action == "gff-rotini" {
		_main_gff_to_rotini(c)
		return
	} else if action == "gff-pasta" {
		_main_gff_to_pasta(c)
		return
	} else if action == "gvcf-rotini" {
		_main_gvcf_to_rotini(c)
		return
	} else if action == "cgivar-pasta" {
		_main_cgivar_to_pasta(c)
		return
	} else if action == "cgivar-rotini" {
		_main_cgivar_to_rotini(c)
		return
	} else if action == "fasta-pasta" {
		_main_fasta_to_pasta(c)
		return
	}

	infn_slice := c.StringSlice("input")

	var stream *bufio.Reader
	var stream_b *bufio.Reader

	g_debug = c.Bool("debug")

	gFullRefSeqFlag = c.Bool("full-sequence")
	gFullNocSeqFlag = c.Bool("full-nocall-sequence")

	n_inp_stream := 0

	if len(infn_slice) > 0 {
		fp := os.Stdin
		if infn_slice[0] != "-" {
			fp, e = os.Open(infn_slice[0])
			if e != nil {
				fmt.Fprintf(os.Stderr, "%v", e)
				os.Stderr.Sync()
				os.Exit(1)
			}
			defer fp.Close()
		}
		stream = bufio.NewReader(fp)

		n_inp_stream++
	}

	if len(infn_slice) > 1 {
		fp, e := os.Open(infn_slice[1])
		if e != nil {
			fmt.Fprintf(os.Stderr, "%v", e)
			os.Stderr.Sync()
			os.Exit(1)
		}
		defer fp.Close()
		stream_b = bufio.NewReader(fp)

		n_inp_stream++

		action = "interleave"
	}

	aout, err := autoio.CreateWriter(c.String("output"))
	_ = aout
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v", err)
		os.Stderr.Sync()
		os.Exit(1)
	}
	defer func() { aout.Flush(); aout.Close() }()

	if c.Bool("pprof") {
		gProfileFlag = true
		gProfileFile = c.String("pprof-file")
	}

	if c.Bool("mprof") {
		gMemProfileFlag = true
		gMemProfileFile = c.String("mprof-file")
	}

	gVerboseFlag = c.Bool("Verbose")

	if c.Int("max-procs") > 0 {
		runtime.GOMAXPROCS(c.Int("max-procs"))
	}

	if gProfileFlag {
		prof_f, err := os.Create(gProfileFile)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Could not open profile file %s: %v\n", gProfileFile, err)
			os.Stderr.Sync()
			os.Exit(2)
		}

		pprof.StartCPUProfile(prof_f)
		defer pprof.StopCPUProfile()
	}

	if (action != "ref-rstream") && (action != "rstream") && (n_inp_stream == 0) {

		if action == "interleave" {
			fmt.Fprintf(os.Stderr, "Provide input stream")
			cli.ShowAppHelp(c)
			os.Stderr.Sync()
			os.Exit(1)
		}

		stream = bufio.NewReader(os.Stdin)
	}

	//---

	if action == "echo" {
		echo_stream(stream)
	} else if action == "filter-pasta" {
		out := bufio.NewWriter(os.Stdout)
		pasta_filter(stream, out, c.Int("start"), c.Int("n"))
		out.Flush()
	} else if action == "filter-rotini" {
		out := bufio.NewWriter(os.Stdout)
		interleave_filter(stream, out, c.Int("start"), c.Int("n"))
		out.Flush()
	} else if action == "interleave" {
		pasta.InterleaveStreams(stream, stream_b, os.Stdout)
	} else if action == "ref-rstream" {

		r_ctx := random_stream_context_from_param(c.String("param"))
		random_ref_stream(r_ctx)

	} else if action == "rstream" {

		r_ctx := random_stream_context_from_param(c.String("param"))
		random_stream(r_ctx)

		//FASTA
	} else if action == "pasta-fasta" {

		fi := FASTAInfo{}
		fi.Init()

		out := bufio.NewWriter(os.Stdout)
		fi.Header(out)
		e := fi.Stream(stream, out)
		if e != nil {
			fmt.Fprintf(os.Stderr, "\nERROR: %v\n", e)
			os.Stderr.Sync()
			os.Exit(1)
		}
		fi.PrintEnd(out)

	} else if action == "diff-rotini" {

		//e:=diff_to_interleave(&stream)
		//if e!=nil { fmt.Fprintf(os.Stderr, "%v\n", e); return }

	} else if action == "rotini-diff" {

		e := interleave_to_diff(stream, simple_refvar_printer)
		if e != nil {
			fmt.Fprintf(os.Stderr, "%v\n", e)
			return
		}
	} else if action == "rotini" {
	} else if action == "pasta-ref" {
		e := pasta_to_haploid(stream, -1)
		if e != nil {
			fmt.Fprintf(os.Stderr, "\nERROR: %v\n", e)
			os.Stderr.Sync()
			os.Exit(1)
		}
	} else if action == "rotini-ref" {
		e := interleave_to_haploid(stream, -1)
		if e != nil {
			fmt.Fprintf(os.Stderr, "\nERROR: %v\n", e)
			os.Stderr.Sync()
			os.Exit(1)
		}
	} else if action == "rotini-alt0" {
		interleave_to_haploid(stream, 0)
	} else if action == "rotini-alt1" {
		interleave_to_haploid(stream, 1)
	} else if action == "rotini-gff" {

		gff := GFFRefVar{}
		gff.Init()

		e := interleave_to_diff_iface(stream, &gff, os.Stdout)
		if e != nil {
			fmt.Fprintf(os.Stderr, "%v\n", e)
			return
		}

	} else if action == "rotini-gvcf" {

		g := gvcf.GVCFRefVar{}
		g.Init()

		// We need the full reference sequence for beginning and ending bases
		//
		gFullRefSeqFlag = true

		e := interleave_to_diff_iface(stream, &g, os.Stdout)
		if e != nil {
			fmt.Fprintf(os.Stderr, "%v\n", e)
			return
		}

	} else if action == "rotini-cgivar" {

		cgivar := CGIRefVar{}
		cgivar.Init()

		e := interleave_to_diff_iface(stream, &cgivar, os.Stdout)
		if e != nil {
			fmt.Fprintf(os.Stderr, "%v\n", e)
			return
		}

	} else if action == "fastj-rotini" {

		//
		// FastJ to rotini
		//

		fp := os.Stdin
		if c.String("refstream") != "-" {
			fp, e = os.Open(c.String("refstream"))
			if e != nil {
				fmt.Fprintf(os.Stderr, "ERROR: opening reference stream: %v", e)
				os.Stderr.Sync()
				os.Exit(1)
			}
			defer fp.Close()
		}
		ref_stream := bufio.NewReader(fp)

		assembly_fp, e := os.Open(c.String("assembly"))
		if e != nil {
			fmt.Fprintf(os.Stderr, "ERROR: opening assembly stream: %v", e)
			os.Stderr.Sync()
			os.Exit(1)
		}
		defer assembly_fp.Close()
		assembly_stream := bufio.NewReader(assembly_fp)

		out := bufio.NewWriter(os.Stdout)

		fji := FastJInfo{}
		fji.RefPos = c.Int("start")
		fji.Chrom = c.String("chrom")

		e = fji.Pasta(stream, ref_stream, assembly_stream, out)
		if e != nil {
			fmt.Fprintf(os.Stderr, "ERROR: processing PASTA stream: %v\n", e)
			os.Stderr.Sync()
			os.Exit(1)
		}

	} else if action == "rotini-fastj" {

		//
		// rotini to FastJ
		//

		tag_fp, e := os.Open(c.String("tag"))
		if e != nil {
			fmt.Fprintf(os.Stderr, "%v", e)
			os.Stderr.Sync()
			os.Exit(1)
		}
		defer tag_fp.Close()

		assembly_fp, e := os.Open(c.String("assembly"))
		if e != nil {
			fmt.Fprintf(os.Stderr, "%v", e)
			os.Stderr.Sync()
			os.Exit(1)
		}
		defer assembly_fp.Close()

		tag_reader := bufio.NewReader(tag_fp)
		assembly_reader := bufio.NewReader(assembly_fp)

		fji := FastJInfo{}
		fji.RefPos = c.Int("start")
		fji.RefBuild = c.String("build")
		fji.Chrom = c.String("chrom")

		_tilepath, e := strconv.ParseUint(c.String("tilepath"), 16, 64)
		if e != nil {
			fmt.Fprintf(os.Stderr, "%v", e)
			os.Stderr.Sync()
			os.Exit(1)
		}
		fji.TagPath = int(_tilepath)

		out := bufio.NewWriter(os.Stdout)

		err := fji.Convert(stream, tag_reader, assembly_reader, out)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%v", err)
			os.Stderr.Sync()
			os.Exit(1)
		}

	} else {
		fmt.Printf("invalid action (%s)\n", action)
		os.Stderr.Sync()
		os.Exit(1)
	}

}