-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpairdist.go
53 lines (46 loc) · 1.35 KB
/
pairdist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"flag"
"fmt"
"math"
"github.com/TuftsBCB/fragbag/bow"
"github.com/TuftsBCB/tools/util"
)
var flagPairdistModels = false
var cmdPairdist = &command{
name: "pairdist",
positionalUsage: "frag-lib bower-file [ bower-file ... ]",
shortHelp: "compute pairwise BOW distances",
help: `
The pairdist command returns the cosine distance between every pair of
Fragbag frequency vectors produced by the given bower files.
Bower files may either be PDB files or FASTA files.
`,
flags: flag.NewFlagSet("pairdist", flag.ExitOnError),
run: pairdist,
addFlags: func(c *command) {
c.flags.BoolVar(&flagPairdistModels, "models", flagPairdistModels,
"When set, the models for each bower file given (if a PDB file)\n"+
"will be used. Otherwise, the first the model from each\n"+
"chain specified will be used.")
},
}
func pairdist(c *command) {
c.assertLeastNArg(2)
flib := util.Library(c.flags.Arg(0))
bowPaths := c.flags.Args()[1:]
bows := make([]bow.Bowed, 0, 1000)
results := util.ProcessBowers(bowPaths, flib, flagPairdistModels,
flagCpu, util.FlagQuiet)
for r := range results {
bows = append(bows, r)
}
for i := 0; i < len(bows); i++ {
b1 := bows[i]
for j := i + 1; j < len(bows); j++ {
b2 := bows[j]
dist := math.Abs(b1.Bow.Cosine(b2.Bow))
fmt.Printf("%s\t%s\t%0.4f\n", b1.Id, b2.Id, dist)
}
}
}