Skip to content

Commit

Permalink
Merge pull request #9 from Syntist/updated-to-proteorift
Browse files Browse the repository at this point in the history
Added changes to run on proteorift, more robust intsallation
  • Loading branch information
Prof-S authored Oct 22, 2024
2 parents 0b26dbc + 8c0e2c6 commit a6b1e36
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 19 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ __pycache__

run_search.build
run_search.dist
run_search.onefile-build
run_search.onefile-build
ProteoRift-main
config.ini
env.json
maestro-*
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Download installer.bin from release
Require Dependencies >= Ubuntu 20.04
```
sudo apt install build-essential fuse
```

Now Run the Installer
```
chmod +x installer.bin
./installer.bin
Expand Down
5 changes: 0 additions & 5 deletions electron-app/env.json

This file was deleted.

4 changes: 2 additions & 2 deletions electron-app/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ if (fs.existsSync(path.resolve(process.cwd(), '../../env.json'))) {
configPath = path.resolve(process.cwd(), '../../env.json')
} else if (fs.existsSync(path.resolve(process.cwd(), './env.json'))) {
configPath = path.resolve(process.cwd(), './env.json')
} else if (fs.existsSync(path.resolve(process.cwd(), '../env.json'))) {
configPath = path.resolve(process.cwd(), '../env.json')
} else {
console.log('env.json can not be found, exiting')
process.exit()
}

console.log(configPath)

const rawData = fs.readFileSync(configPath, 'utf-8')
const config = JSON.parse(rawData)

Expand Down
6 changes: 3 additions & 3 deletions electron-app/src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { Runner } from './components/Runner'

const specollate = `${await window.electron.getEnvVariable('SPECOLLATE')} -c ${await window.electron.getEnvVariable('SPECOLLATE_CONFIG')}`

console.log(specollate)
const proteorift = `${await window.electron.getEnvVariable('PROTEORIFT')} -c ${await window.electron.getEnvVariable('SPECOLLATE_CONFIG')}`

function App(): JSX.Element {
const [show, setShow] = useState(false)

const runCommand = (gpu: boolean) => {
setShow(true)
if (gpu) {
window.electron.runCmd(`${specollate} -u gpu`)
window.electron.runCmd(`${proteorift} -u gpu`)
} else {
window.electron.runCmd(specollate)
window.electron.runCmd(proteorift)
}
}

Expand Down
4 changes: 2 additions & 2 deletions electron-app/src/renderer/src/components/ConfigForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Checkbox
} from '@mui/material'
import FolderSelector from '../FolderSelector'
import { configBuilder } from '@renderer/utils/helper'
import { configBuilder, configBuilderV2 } from '@renderer/utils/helper'
import { useState } from 'react'

const ConfigForm = ({ run }: any) => {
Expand Down Expand Up @@ -44,7 +44,7 @@ const ConfigForm = ({ run }: any) => {

console.log(errors)
const onSubmit = (data) => {
configBuilder(data)
configBuilderV2(data)
run()
}

Expand Down
138 changes: 136 additions & 2 deletions electron-app/src/renderer/src/utils/helper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const MODEL = import.meta.env.VITE_MODEL
const CONFIG = import.meta.env.VITE_CONFIG
const MODEL = await window.electron.getEnvVariable('MODEL')
const MODEL_2 = await window.electron.getEnvVariable('MODEL_2')
const CONFIG = await window.electron.getEnvVariable('SPECOLLATE_CONFIG')

export const configBuilder = async (data: any) => {
const config = `
Expand Down Expand Up @@ -102,3 +103,136 @@ batch_size : 1024
`
await window.electron.ipcRenderer.invoke('write-file', CONFIG, config)
}


export const configBuilderV2 = async (data: any) => {
const config = `
[preprocess]
# For raptor
# in_tensor_dir : ./data/train-ready/pred-full/
# For comet
# in_tensor_dir : /scratch/mtari008/37154933/pred-full-deepnovo/
# For expanse
in_tensor_dir : /lclhome/mtari008/job_2436627/nist_massiv_80k_ch_graymass/
############ INPUT PARAMETERS ############
[input]
# file paths
mgf_dir : /lclhome/mtari008/data/spectra/labeled/fruitfly.PXD004120
prep_dir: sample_data/preprocess_files
; val_dir : /lclhome/mtari008/data/deepatles/train_ready/nist-masive-deepnovo-5k-ch1-3-len7-30-200-mod-mass
# The array size to store a spectrum.
spec_size : 50000
# Max charge value to be used to read spectrum files.
charge : 5
# Whether to use modifications or not.
use_mods : True
# Max mods per peptide
num_mods: 5
# Number of species the training dataset contains.
num_species : 9
master_port : 12347
rank : 1
############ DATABASE SEARCH PARAMETERS ############
[search]
mgf_dir: ${data.mgf_dir}
prep_path: ${data.prep_dir}
pep_dir: ${data.pep_dir}
out_pin_dir : ${data.out_pin_dir}
model_name : ${MODEL_2}
specollate_model_path: ${MODEL}
# Batch sizes for forward pass through the network
spec_batch_size : ${data.spec_batch_size}
pep_batch_size : ${data.pep_batch_size}
# Batch size for database search
search_spec_batch_size : ${data.search_spec_batch_size}
precursor_tolerance : ${data.precursor_tolerance} # Precursor tolerance to use during database search (Da or ppm)
precursor_tolerance_type : ${data.precursor_tolerance_type} # either ppm or Da
keep_psms : ${data.keep_psms} # Number of top scoring psms to keep
# Number of modified peptides to be generated to search against.
# Different than the one in input section
num_mods : ${data.num_mods}
charge: ${data.charge} # charge to be used during search
############ FILTERING PARAMETERS ############
[filter]
length_filter: True
len_tol_neg: -1
len_tol_pos: 1
missed_cleavages_filter: True
modification_filter: True
############### OUT OF CORE PARAMETERS ##############
[ooc]
chunk_size: 10000000
############ MACHINE LEARNING PARAMETERS ############
[ml]
batch_size : 1024
test_size : 0.2
max_spec_len : 200
min_pep_len: 7
max_pep_len : 30
# slightly larger than max_pep_len to account for modifications
pep_seq_len : 36
max_clvs : 2
embedding_dim : 1024
encoder_layers : 4
num_heads : 16
train_count : 0
ce_weight_clv : 1
ce_weight_mod : 1
mse_weight : 3
dropout : 0.3
lr : 0.0001
weight_decay : 0.0001
epochs : 5
margin : 0.2
read_split_listing : False
############ DEFAULT VALUES ############
# DO NOT CHANGE
[default]
msp_file : /data/human_consensus_final_true_lib.msp
mgf_files : /data/
spec_size : 8000
charge : 2
use_mods : False
batch_size : 1024
`
await window.electron.ipcRenderer.invoke('write-file', CONFIG, config)
}
3 changes: 2 additions & 1 deletion electron-app/tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"src/renderer/src/env.d.ts",
"src/renderer/src/**/*",
"src/renderer/src/**/*.tsx",
"src/preload/*.d.ts"
"src/preload/*.d.ts",
"types"
],
"compilerOptions": {
"composite": true,
Expand Down
11 changes: 11 additions & 0 deletions electron-app/types/electron-api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// electron-api.d.ts
import { ElectronAPI } from '@electron-toolkit/preload'

declare module '@electron-toolkit/preload' {
interface ElectronAPI {
getEnvVariable: (key: string) => string | undefined
runCmd: any
onCmdOutput: any
terminateCmd: any
}
}
35 changes: 32 additions & 3 deletions installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import requests
import glob
from zipfile import ZipFile
import argparse

MODEL_URL = "https://github.com/pcdslab/ProteoRift/releases/download/V1.0.0/specollate_model_weights.pt"
MODEL_2_URL = "https://github.com/pcdslab/ProteoRift/releases/download/V1.0.0/proteorift_model_weights.pt"


url = f'https://api.github.com/repos/pcdslab/MAESTRO/releases/latest'
Expand Down Expand Up @@ -67,6 +69,7 @@ def main():
# Copy SpeCollate to electron-app
electron_app_dir = Path(path)
spe_collate_dest = Path(path) / "SpeCollate"
proteo_dest = Path(path) / "ProteoRift-main"
app_name = ""

if spe_collate_dest.exists():
Expand All @@ -78,6 +81,16 @@ def main():
run_command(f"cd *-MAESTRO* && cp -r SpeCollate {electron_app_dir}")
run_command(f"rm -rf {file}")
run_command(f"rm -rf *-MAESTRO*")

if proteo_dest.exists():
print("ProteoRift Exist")
else:
print("ProteoRift Doesn't Exist, Downloading")
file = download_file("https://github.com/pcdslab/ProteoRift/archive/refs/heads/main.zip", electron_app_dir)
extract_zip(file, electron_app_dir)

print(file)
run_command(f"rm -rf {file}")

if check_for_electron_app():
app_name = check_for_electron_app()[0]
Expand All @@ -87,6 +100,7 @@ def main():

# Download the model file
model_filepath = download_file(MODEL_URL, models_dir)
model_2_filepath = download_file(MODEL_2_URL, models_dir)

# Install Python if not installed
python_bin = python_dir / "bin/python3"
Expand Down Expand Up @@ -115,17 +129,32 @@ def main():
with env_file.open("a") as f:
f.write("{\n")
f.write(f'"SPECOLLATE":"{python_bin} {spe_collate_dest}/run_search.py",\n')
f.write(f'"PROTEORIFT":"{python_bin} {proteo_dest}/run_search.py",\n')
f.write(f'"MODEL":"{model_filepath}",\n')
f.write(f'"MODEL_2":"{model_2_filepath}",\n')
f.write(f'"SPECOLLATE_CONFIG":"{Path(path)}/config.ini"\n')
f.write("}")

print(f"Environment variables written to {env_file}")

# Install npm dependencies and start the Electron app
os.chdir(electron_app_dir)

run_command(f"chmod +x {electron_app_dir}/{app_name}" )
run_command(f"{electron_app_dir}/{app_name}")

parser = argparse.ArgumentParser(description="Script with --dev flag")
parser.add_argument(
'--dev',
action='store_true',
help='Run the script in development mode'
)

args = parser.parse_args()

if args.dev:
os.chdir(f"{electron_app_dir}/electron-app")
run_command(f"npm run dev" )
else:
run_command(f"chmod +x {electron_app_dir}/{app_name}" )
run_command(f"{electron_app_dir}/{app_name}")

if __name__ == "__main__":
main()

0 comments on commit a6b1e36

Please sign in to comment.