Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor fname matching #80

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions dataset/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ func (t *Target) SetupHaddock3Scenario(wd string, s input.Scenario) (runner.Job,
}

// Generate the run.toml file - it will handle the restraints
_, _ = t.WriteRunToml(sPath, s.Parameters.General, s.Parameters.Modules)
_, err := t.WriteRunToml(sPath, s.Parameters.General, s.Parameters.Modules)
if err != nil {
return runner.Job{}, err
}

j := runner.Job{
ID: t.ID + "_" + s.Name,
Expand Down Expand Up @@ -252,6 +255,12 @@ func (t *Target) WriteRunToml(projectDir string, general map[string]interface{},
}
runTomlString += "]\n\n"

fnameArray := [][]string{
t.Restraints,
t.Toppar,
t.MiscPDB,
}

// NOTE: THE ORDER OF THE MODULES IS IMPORTANT!!
// Range over the modules in the order they are defined
v := reflect.ValueOf(mod)
Expand Down Expand Up @@ -282,27 +291,19 @@ func (t *Target) WriteRunToml(projectDir string, general map[string]interface{},
}
runTomlString += "[" + m + "]\n"
for k, v := range field.Interface().(map[string]interface{}) {

// Find the file to be used as fname
if strings.Contains(k, "_fname") {
// Identify the fname parameters based on the pattern, considering
// word boundaries
pattern := regexp.MustCompile(`\b` + v.(string) + `\b`)

// Find the restraints that match the pattern
for _, r := range t.Restraints {
if pattern.MatchString(r) {
runTomlString += k + " = \"../data/" + filepath.Base(r) + "\"\n"
}
}
// Find the Toppar that matches the pattern
for _, r := range t.Toppar {
if pattern.MatchString(r) {
runTomlString += k + " = \"../data/" + filepath.Base(r) + "\"\n"
pattern := regexp.MustCompile(v.(string))

for _, fArr := range fnameArray {
fname, err := utils.FindFname(fArr, pattern)
if err != nil {
return "", err
}
}
// Find if a MiscPDB that matches the pattern
for _, r := range t.MiscPDB {
if pattern.MatchString(r) {
runTomlString += k + " = \"../data/" + filepath.Base(r) + "\"\n"
// If fname is not empty, add it to the TOML file
if fname != "" {
runTomlString += k + " = \"../data/" + filepath.Base(fname) + "\"\n"
}
}

Expand Down
18 changes: 17 additions & 1 deletion dataset/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func TestSetupHaddock3Scenario(t *testing.T) {
"some-param": "some-value",
},
Rigidbody: map[string]interface{}{
"ambig_fname": "_ti.tbl",
"ambig_fname": "_ti",
},
},
},
Expand Down Expand Up @@ -576,6 +576,22 @@ func TestSetupHaddock3Scenario(t *testing.T) {
t.Errorf("Scenario was not written to disk")
}

// Fail to setup a scenario in which multiple patterns match
target = Target{
ID: "1abc",
Receptor: []string{"dummy.pdb", "dummy.pdb"},
ReceptorList: "pdb-files.txt",
Ligand: []string{"dummy.pdb", "dummy.pdb"},
LigandList: "pdb-files.txt",
Restraints: []string{"1abc_ti.tbl", "1abc_ti5.tbl"},
Toppar: []string{"custom.top", "custom.param"},
}

_, err = target.SetupHaddock3Scenario(wd, s)
if err == nil {
t.Errorf("Failed to detect wrong scenario")
}

}

func TestTarget_SetupHaddock24Scenario(t *testing.T) {
Expand Down
26 changes: 13 additions & 13 deletions example/example_haddock30.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
general:
executable: /trinity/login/rodrigo/repos/haddock-runner/example/haddock3.sh
executable: /home/rodrigo/repos/haddock-runner/example/haddock3.sh
max_concurrent: 4
haddock_dir: /trinity/login/rodrigo/repos/haddock3
haddock_dir: /home/rodrigo/repos/haddock3
receptor_suffix: _r_u
ligand_suffix: _l_u
input_list: /trinity/login/rodrigo/repos/haddock-runner/example/input_list.txt
work_dir: /trinity/login/rodrigo/repos/haddock-runner/bm-goes-here
input_list: /home/rodrigo/repos/haddock-runner/example/input_list.txt
work_dir: /home/rodrigo/repos/haddock-runner/bm-goes-here

scenarios:
- name: true-interface
Expand All @@ -20,20 +20,20 @@ scenarios:
autohis: true
rigidbody:
sampling: 10
ambig_fname: _ti
unambig_fname: _unambig
ligand_top_fname: _custom_top
ligand_param_fname: _custom_param
ambig_fname: _ti.tbl
unambig_fname: _unambig.tbl
ligand_top_fname: _ligand.top
ligand_param_fname: _ligand.param
seletop:
select: 2
flexref:
ambig_fname: _ti
unambig_fname: _unambig
ligand_top_fname: _custom_top
ligand_param_fname: _custom_param
ambig_fname: _ti.tbl
unambig_fname: _unambig.tbl
ligand_top_fname: _ligand.top
ligand_param_fname: _ligand.param
emref:
caprieval:
reference_fname: _ref
reference_fname: _ref.pdb

- name: center-of-mass
parameters:
Expand Down
17 changes: 17 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,20 @@ func ContainsCG(s string) bool {
s = strings.ToLower(s)
return regexp.MustCompile(`cg`).MatchString(s)
}

// FindFname checks the array of strings for a pattern, returns an error if multiple files match
func FindFname(arr []string, pattern *regexp.Regexp) (string, error) {

var fname string
for _, f := range arr {
if pattern.MatchString(f) {
if fname != "" {
err := errors.New("multiple files match the pattern: `" + pattern.String() + "` please use a more specific pattern")
return "", err
}
fname = f
}
}

return fname, nil
}
18 changes: 18 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"os"
"reflect"
"regexp"
"testing"
)

Expand Down Expand Up @@ -314,3 +315,20 @@ func TestContainsCG(t *testing.T) {
t.Errorf("Failed to detect cg")
}
}

func TestFindFname(t *testing.T) {

testArr := []string{"abc", "bcd", "cde"}
pattern := regexp.MustCompile("abc")
_, err := FindFname(testArr, pattern)
if err != nil {
t.Errorf("Failed to find name: %s", err)
}

pattern = regexp.MustCompile("cd")
_, err = FindFname(testArr, pattern)
if err == nil {
t.Errorf("Failed to detect multiple files")
}

}
Loading