Skip to content

Commit

Permalink
plex create deprecated (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
acashmoney committed Aug 31, 2023
1 parent 397beb5 commit e3faea2
Show file tree
Hide file tree
Showing 42 changed files with 4,008 additions and 713 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

- name: Run Equibind
run: |
result_dir=$(./plex create -t tools/equibind.json -i testdata/binding/pdbbind_processed_size1 --autoRun=true -a test -a ci | grep 'Finished processing, results written to' | sed -n 's/^.*Finished processing, results written to //p' | sed 's/\/io.json//')
result_dir=$(./plex init -t tools/equibind.json -i '{"protein": ["testdata/binding/abl/7n9g.pdb"], "small_molecule": ["testdata/binding/abl/ZINC000003986735.sdf"]}' --scatteringMethod=dotProduct --autoRun=true -a test -a ci | grep 'Finished processing, results written to' | sed -n 's/^.*Finished processing, results written to //p' | sed 's/\/io.json//')
cd "$result_dir/entry-0/outputs"
if [ "$(find . -name '*docked.sdf' | grep 'docked.sdf')" == "" ]; then
echo "No docked files found"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:

- name: Run Equibind
run: |
result_dir=$(./plex create -t tools/equibind.json -i testdata/binding/pdbbind_processed_size1 -a test -a ci --autoRun=true | grep 'Finished processing, results written to' | sed -n 's/^.*Finished processing, results written to //p' | sed 's/\/io.json//')
result_dir=$(./plex init -t tools/equibind.json -i '{"protein": ["testdata/binding/abl/7n9g.pdb"], "small_molecule": ["testdata/binding/abl/ZINC000003986735.sdf"]}' --scatteringMethod=dotProduct --autoRun=true -a test -a ci | grep 'Finished processing, results written to' | sed -n 's/^.*Finished processing, results written to //p' | sed 's/\/io.json//')
cd "$result_dir/entry-0/outputs"
if [ "$(find . -name '*docked.sdf' | grep 'docked.sdf')" == "" ]; then
echo "No docked files found"
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,6 @@ yarn-error.log
yarn-debug.log*
.pnpm-debug.log*
!./gateway/frontend/lib/

# gorm
gateway/gorm.db
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/lab

2. Submit an example plex job
```
./plex create -t tools/equibind.json -i testdata/binding/abl --autoRun=True
./plex init -t tools/equibind.json -i '{"protein": ["testdata/binding/abl/7n9g.pdb"], "small_molecule": ["testdata/binding/abl/ZINC000003986735.sdf"]}' --scatteringMethod=dotProduct --autoRun=true
```

![Getting Started](./readme-getting-started-2x.gif)
Expand Down
103 changes: 0 additions & 103 deletions cmd/create.go

This file was deleted.

158 changes: 14 additions & 144 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"

"github.com/labdao/plex/internal/ipfs"
"github.com/labdao/plex/internal/ipwl"
"github.com/labdao/plex/internal/web3"
"github.com/spf13/cobra"
)

var (
inputs string
scatteringMethod string
toolPath string
inputs string
scatteringMethod string
autoRun bool
annotationsForAutoRun *[]string
)

var initCmd = &cobra.Command{
Expand All @@ -34,7 +34,7 @@ var initCmd = &cobra.Command{
log.Fatal("Invalid inputs JSON:", err)
}

ioJson, err := InitilizeIo(toolPath, scatteringMethod, kwargs)
ioJson, err := ipwl.InitializeIo(toolPath, scatteringMethod, kwargs)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -69,153 +69,23 @@ var initCmd = &cobra.Command{
if err := tempFile.Close(); err != nil {
log.Fatalf("Failed to close the temporary file: %v", err)
}
},
}

func InitilizeIo(toolPath string, scatteringMethod string, inputVectors map[string][]string) ([]ipwl.IO, error) {
// Open the file and load its content
tool, toolInfo, err := ipwl.ReadToolConfig(toolPath)
if err != nil {
return nil, err
}

// Check if all kwargs are in the tool's inputs
for inputKey := range inputVectors {
if _, exists := tool.Inputs[inputKey]; !exists {
log.Printf("The argument %s is not in the tool inputs.\n", inputKey)
log.Printf("Available keys: %v\n", tool.Inputs)
return nil, fmt.Errorf("the argument %s is not in the tool inputs", inputKey)
}
}

// Handle scattering methods and create the inputsList
var inputsList [][]string
switch scatteringMethod {
case "dotProduct":
// check if all lists have the same length
var vectorLength int
for _, v := range inputVectors {
if vectorLength == 0 {
vectorLength = len(v)
continue
}
if len(v) != vectorLength {
return nil, fmt.Errorf("all input arguments must have the same length for dot_product scattering method")
}
vectorLength = len(v)
}
for i := 0; i < vectorLength; i++ {
tmp := []string{}
for _, v := range inputVectors {
tmp = append(tmp, v[i])
}
inputsList = append(inputsList, tmp)
}
case "crossProduct":
cartesian := func(arrs ...[]string) [][]string {
result := [][]string{{}}

for _, arr := range arrs {
var temp [][]string

for _, res := range result {
for _, str := range arr {
product := append([]string{}, res...)
product = append(product, str)
temp = append(temp, product)
}
}

result = temp
}

return result
}

keys := make([]string, 0, len(inputVectors))
for k := range inputVectors {
keys = append(keys, k)
}
arrays := make([][]string, len(inputVectors))
for i, k := range keys {
arrays[i] = inputVectors[k]
}
inputsList = cartesian(arrays...)
default:
return nil, fmt.Errorf("invalid scattering method: %s", scatteringMethod)
}

var userId string

if web3.IsValidEthereumAddress(os.Getenv("RECIPIENT_WALLET")) {
userId = os.Getenv("RECIPIENT_WALLET")
} else {
fmt.Print("Invalid wallet address detected. Using empty string for user ID.\n")
userId = ""
}

// populate ioJSONGraph based on inputsList
var ioJSONGraph []ipwl.IO
for _, inputs := range inputsList {
io := ipwl.IO{
Tool: toolInfo,
Inputs: make(map[string]ipwl.FileInput),
Outputs: make(map[string]ipwl.Output),
State: "created",
ErrMsg: "",
UserID: userId,
}

inputKeys := make([]string, 0, len(inputVectors))
for k := range inputVectors {
inputKeys = append(inputKeys, k)
}

for i, inputValue := range inputs {
inputKey := inputKeys[i]

if strings.Count(inputValue, "/") == 1 {
parts := strings.Split(inputValue, "/")
cid := parts[0]
fileName := parts[1]
if !ipfs.IsValidCID(cid) {
return nil, fmt.Errorf("invalid CID: %s", cid)
}
io.Inputs[inputKey] = ipwl.FileInput{
Class: tool.Inputs[inputKey].Type,
FilePath: fileName,
IPFS: cid,
}
} else {
cid, err := ipfs.WrapAndPinFile(inputValue) // Pin the file and get the CID
if err != nil {
return nil, err
}
io.Inputs[inputKey] = ipwl.FileInput{
Class: tool.Inputs[inputKey].Type,
FilePath: filepath.Base(inputValue), // Use the respective input value from inputsList
IPFS: cid, // Use the CID returned by WrapAndPinFile
}
}
}

for outputKey := range tool.Outputs {
io.Outputs[outputKey] = ipwl.FileOutput{
Class: tool.Outputs[outputKey].Type,
FilePath: "", // Assuming filepath is empty, adapt as needed
IPFS: "", // Assuming IPFS is not provided, adapt as needed
if autoRun {
_, _, err := PlexRun(cid, outputDir, verbose, showAnimation, concurrency, *annotationsForAutoRun)
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
}
ioJSONGraph = append(ioJSONGraph, io)
}

return ioJSONGraph, nil
},
}

func init() {
initCmd.Flags().StringVarP(&toolPath, "toolPath", "t", "", "Path of the Tool config (can be a local path or an IPFS CID)")
initCmd.Flags().StringVarP(&inputs, "inputs", "i", "{}", "Inputs in JSON format")
initCmd.Flags().StringVarP(&scatteringMethod, "scatteringMethod", "", "{}", "Inputs in JSON format")
initCmd.Flags().BoolVarP(&autoRun, "autoRun", "", false, "Auto submit the IO to plex run")
annotationsForAutoRun = initCmd.Flags().StringArrayP("annotations", "a", []string{}, "Annotations to add to Bacalhau job")

rootCmd.AddCommand(initCmd)
}
2 changes: 1 addition & 1 deletion cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var upgradeCmd = &cobra.Command{
}

const (
CurrentPlexVersion = "v0.9.1"
CurrentPlexVersion = "v0.10.0"
ReleaseURL = "https://api.github.com/repos/labdao/plex/releases/latest"
ToolsURL = "https://api.github.com/repos/labdao/plex/contents/tools?ref=main"
)
Expand Down

0 comments on commit e3faea2

Please sign in to comment.