Skip to content

Commit

Permalink
add pept2go
Browse files Browse the repository at this point in the history
  • Loading branch information
bmesuere committed Aug 6, 2024
1 parent 42fe0bf commit d7fffcd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/commands/unipept.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseCommand } from './base_command.js';
import { Pept2ec } from './unipept/pept2ec.js';
import { Pept2funct } from './unipept/pept2funct.js';
import { Pept2go } from './unipept/pept2go.js';
import { Pept2lca } from './unipept/pept2lca.js';

export class Unipept extends BaseCommand {
Expand All @@ -23,6 +24,7 @@ The command will give priority to the first way the input is passed, in the orde
.description(this.description)
.addCommand(new Pept2ec().command)
.addCommand(new Pept2funct().command)
.addCommand(new Pept2go().command)
.addCommand(new Pept2lca().command);
}

Expand Down
38 changes: 38 additions & 0 deletions lib/commands/unipept/pept2go.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Option } from "commander";
import { UnipeptSubcommand } from "./unipept_subcommand.js";

export class Pept2go extends UnipeptSubcommand {

readonly description = `For each tryptic peptide the unipept pept2ec command retrieves from Unipept the set of GO terms from all UniProt entries whose protein sequence contains an exact matches to the tryptic peptide. The command expects a list of tryptic peptides that are passed
- as separate command line arguments
- in a text file that is passed as an argument to the -i option
- to standard input
The command will give priority to the first way tryptic peptides are passed, in the order as listed above. Text files and standard input should have one tryptic peptide per line.`;

constructor() {
super("pept2go");

this.command
.summary("Fetch GO terms of UniProt entries that match tryptic peptides.")
.description(this.description)
.option("-e, --equate", "equate isoleucine (I) and leucine (L) when matching peptides")
.option("-a, --all", "Also return the names of the GO terms. Note that this may have a performance penalty.")
.addOption(new Option("-s --select <fields...>", "select the information fields to return. Selected fields are passed as a comma separated list of field names. Multiple -s (or --select) options may be used."))
.argument("[peptides...]", "optionally, 1 or more peptides")
.action((args, options) => this.run(args, options));
}

requiredFields(): string[] {
return ["peptide"];
}

defaultBatchSize(): number {
if (this.options.all) {
return 100;
} else {
return 1000;
}
}
}
27 changes: 27 additions & 0 deletions tests/commands/unipept/pept2go.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { jest } from '@jest/globals';
import { Pept2go } from "../../../lib/commands/unipept/pept2go";

let output: string[];
jest
.spyOn(process.stdout, "write")
.mockImplementation((data: unknown) => { output.push(data as string); return true; });

beforeEach(() => {
output = [];
});

test('test with default args', async () => {
const command = new Pept2go();
await command.run(["AALTER"], { header: true, format: "csv" });
expect(output[0].startsWith("peptide,total_protein_count,go_term,go_protein_count")).toBeTruthy();
expect(output[1].startsWith("AALTER,3310,GO:0003677")).toBeTruthy();
expect(output.length).toBe(2);
});

test('test with fasta', async () => {
const command = new Pept2go();
await command.run([">test", "AALTER"], { header: true, format: "csv" });
expect(output[0].startsWith("fasta_header,peptide,total_protein_count,go_term,go_protein_count")).toBeTruthy();
expect(output[1].startsWith(">test,AALTER,3310,GO:0003677")).toBeTruthy();
expect(output.length).toBe(2);
});

0 comments on commit d7fffcd

Please sign in to comment.