github.com/vertgenlab/gonomics@v1.0.0/cmd/gsw/axtHelper.go (about) 1 package main 2 3 import ( 4 "github.com/vertgenlab/gonomics/axt" 5 "github.com/vertgenlab/gonomics/exception" 6 "github.com/vertgenlab/gonomics/fasta" 7 "github.com/vertgenlab/gonomics/fileio" 8 "github.com/vertgenlab/gonomics/genomeGraph" 9 "github.com/vertgenlab/gonomics/vcf" 10 ) 11 12 func convertAxt(axtFile, format, targetFa, output string) { 13 switch format { 14 case "vcf": 15 vcfChannel := goChannelAxtVcf(axtFile) 16 file := fileio.EasyCreate(output) 17 header := vcf.NewHeader() 18 vcf.NewWriteHeader(file, header) 19 var ans []vcf.Vcf 20 for i := range vcfChannel { 21 ans = append(ans, i) 22 } 23 vcf.Sort(ans) 24 vcf.WriteVcfToFileHandle(file, ans) 25 err := file.Close() 26 exception.PanicOnErr(err) 27 case "gg": 28 genomeGraph.Write(output, axtToGenomeGraph(axtFile, targetFa)) 29 default: 30 ggToolsUsage() 31 errorMessage() 32 } 33 } 34 35 func goChannelAxtVcf(axtFile string) <-chan vcf.Vcf { 36 axtChannel, _ := axt.GoReadToChan(axtFile) 37 38 ans := make(chan vcf.Vcf, 2408) 39 go workThreadAxtVcf(axtChannel, ans) 40 return ans 41 } 42 43 func axtToGenomeGraph(axtFile, faFile string) *genomeGraph.GenomeGraph { 44 vcfChannel := goChannelAxtVcf(axtFile) 45 chrVcfMap := make(map[string][]vcf.Vcf) 46 for i := range vcfChannel { 47 chrVcfMap[i.Chr] = append(chrVcfMap[i.Chr], i) 48 } 49 ref := fasta.GoReadToChan(faFile) 50 var gg *genomeGraph.GenomeGraph = &genomeGraph.GenomeGraph{} 51 gg = genomeGraph.VariantGraph(ref, chrVcfMap) 52 return gg 53 }