Skip to content

Commit

Permalink
Add mmCIF support
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed May 9, 2024
1 parent 39941ac commit 65433bf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
54 changes: 54 additions & 0 deletions backend/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,35 @@ func execCommandSync(verbose bool, parameters ...string) error {

var fasta3DiInput = regexp.MustCompile(`^>.*?\n.*?\n>3DI.*?\n.*?\n`).MatchString

func ismmCIFFile(filePath string) (bool, error) {
file, err := os.Open(filePath)
if err != nil {
return false, err
}
defer file.Close()

scanner := bufio.NewScanner(file)
for scanner.Scan() {
firstLine := scanner.Text()
if strings.TrimSpace(firstLine) != "" {
break
}
}

if err := scanner.Err(); err != nil {
return false, err
}
if !scanner.Scan() {
return false, errors.New("empty file")
}

firstLine := scanner.Text()
if strings.HasPrefix(firstLine, "# ") || strings.HasPrefix(firstLine, "data_") {
return true, nil
}
return false, nil
}

func RunJob(request JobRequest, config ConfigRoot) (err error) {
switch job := request.Job.(type) {
case SearchJob:
Expand Down Expand Up @@ -282,6 +311,18 @@ mv -f -- "${BASE}/query.lookup_tmp" "${BASE}/query.lookup"
if err != nil {
return &JobExecutionError{err}
}
} else {
isCif, err := ismmCIFFile(inputFile)
if err != nil {
return &JobExecutionError{err}
}
if isCif {
newFilePath := filepath.Join(resultBase, "job.cif")
if err := os.Rename(inputFile, newFilePath); err != nil {
return &JobExecutionError{err}
}
inputFile = newFilePath
}
}

for index, database := range job.Database {
Expand Down Expand Up @@ -446,6 +487,19 @@ mv -f -- "${BASE}/query.lookup_tmp" "${BASE}/query.lookup"
semaphore := make(chan struct{}, max(1, maxParallel))

inputFile := filepath.Join(resultBase, "job.pdb")

isCif, err := ismmCIFFile(inputFile)
if err != nil {
return &JobExecutionError{err}
}
if isCif {
newFilePath := filepath.Join(resultBase, "job.cif")
if err := os.Rename(inputFile, newFilePath); err != nil {
return &JobExecutionError{err}
}
inputFile = newFilePath
}

for index, database := range job.Database {
wg.Add(1)
semaphore <- struct{}{}
Expand Down
2 changes: 1 addition & 1 deletion frontend/LoadAcessionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default {
this.loading = false;
};
if (source == "PDB") {
url = "https://files.rcsb.org/download/" + accession.toUpperCase() + ".pdb";
url = "https://files.rcsb.org/download/" + accession.toUpperCase() + ".cif";
fun = simpleFetch;
} else if (source == "AlphaFoldDB") {
url = "https://alphafold.ebi.ac.uk/api/search?q=(text:*" + accession + " OR text:" + accession + "*)&type=main&start=0&rows=1"
Expand Down

0 comments on commit 65433bf

Please sign in to comment.