コード例 #1
0
ファイル: pasta.go プロジェクト: abeconnelly/pasta
func _main_gvcf_to_rotini(c *cli.Context) {
	var e error

	infn_slice := c.StringSlice("input")
	if len(infn_slice) < 1 {
		infn_slice = append(infn_slice, "-")
	}

	ain, err := autoio.OpenReadScanner(infn_slice[0])
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v", err)
		os.Stderr.Sync()
		os.Exit(1)
	}
	defer ain.Close()

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

	out := bufio.NewWriter(os.Stdout)

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

	line_no := 0
	g.PastaBegin(out)
	for ain.ReadScan() {
		gvcf_line := ain.ReadText()
		line_no++

		if len(gvcf_line) == 0 || gvcf_line == "" {
			continue
		}
		e := g.Pasta(gvcf_line, ref_stream, out)
		if e != nil {
			fmt.Fprintf(os.Stderr, "ERROR: %v at line %v\n", e, line_no)
			return
		}
	}
	g.PastaEnd(out)

	out.Flush()

}
コード例 #2
0
ファイル: pasta.go プロジェクト: abeconnelly/pasta
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)
	}

}