Exemple #1
0
func main() {
	pdbFiles := util.RecursiveFiles(util.FlagPdbDir)
	files := make([]string, 0, flagNum)
	for i := 0; i < flagNum; i++ {
		var index int = -1
		for index == -1 || !util.IsPDB(pdbFiles[index]) {
			// not guaranteed to terminate O_O
			index = rand.Intn(len(pdbFiles))
		}
		files = append(files, pdbFiles[index])
		pdbFiles = append(pdbFiles[:index], pdbFiles[index+1:]...)
	}

	for _, f := range files {
		if flagPaths {
			fmt.Println(f)
		} else {
			e := util.PDBRead(f)
			fmt.Printf("%s%c\n", strings.ToLower(e.IdCode), e.Chains[0].Ident)
		}
	}
}
Exemple #2
0
func readAlignmentDists(dir string) *intern.Table {
	dists := intern.NewTable(11000)
	threads := util.FlagCpu
	addDists := make(chan []pair)
	alignFile := make(chan string)
	done := make(chan struct{})

	go func() {
		for fileDists := range addDists {
			for _, pair := range fileDists {
				a1, a2 := dists.Atom(pair.key[0]), dists.Atom(pair.key[1])
				dists.Set(a1, a2, pair.dist)
			}
		}
		done <- struct{}{}
	}()

	wg := new(sync.WaitGroup)
	for i := 0; i < threads; i++ {
		wg.Add(1)
		go func() {
			for fpath := range alignFile {
				log.Printf("Reading %s (%s)", fpath, time.Now())

				f := util.OpenFile(fpath)
				defer f.Close()

				csvr := csv.NewReader(f)
				csvr.Comma = '\t'
				csvr.TrimLeadingSpace = true
				csvr.FieldsPerRecord = -1 // data is poorly formatted

				records, err := csvr.ReadAll()
				util.Assert(err, "[%s]", fpath)

				fileDists := make([]pair, 0, 100000)
				for _, record := range records {
					if len(record) != 9 {
						continue
					}
					p := recordToDist(record)
					fileDists = append(fileDists, p)
				}
				addDists <- fileDists
			}
			wg.Done()
		}()
	}

	for _, fpath := range util.RecursiveFiles(dir) {
		if strings.HasPrefix(path.Base(fpath), ".") {
			continue
		}
		alignFile <- fpath
	}
	close(alignFile)
	wg.Wait()
	close(addDists)
	<-done
	return dists
}