Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add pept2prot
  • Loading branch information
bmesuere committed Aug 6, 2024
commit bb4ed7561b7a6c94ba6254319d836f574c04e2b9
4 changes: 3 additions & 1 deletion lib/commands/unipept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Pept2funct } from './unipept/pept2funct.js';
import { Pept2go } from './unipept/pept2go.js';
import { Pept2interpro } from './unipept/pept2interpro.js';
import { Pept2lca } from './unipept/pept2lca.js';
import { Pept2prot } from './unipept/pept2prot.js';

export class Unipept extends BaseCommand {

Expand All @@ -27,7 +28,8 @@ The command will give priority to the first way the input is passed, in the orde
.addCommand(new Pept2funct().command)
.addCommand(new Pept2go().command)
.addCommand(new Pept2interpro().command)
.addCommand(new Pept2lca().command);
.addCommand(new Pept2lca().command)
.addCommand(new Pept2prot().command);
}

async run(args?: string[]) {
Expand Down
38 changes: 38 additions & 0 deletions lib/commands/unipept/pept2prot.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 Pept2prot extends UnipeptSubcommand {

readonly description = `For each tryptic peptide the unipept pept2prot command retrieves from Unipept 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("pept2prot");

this.command
.summary("Fetch 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 EC numbers. 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 5;
} else {
return 10;
}
}
}
27 changes: 27 additions & 0 deletions tests/commands/unipept/pept2prot.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { jest } from '@jest/globals';
import { Pept2prot } from "../../../lib/commands/unipept/pept2prot";

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 Pept2prot();
await command.run(["AALTER"], { header: true, format: "csv" });
expect(output[0].startsWith("peptide,uniprot_id,protein_name,taxon_id,protein")).toBeTruthy();
expect(output[1].startsWith("AALTER,P78330")).toBeTruthy();
expect(output.length).toBe(2);
});

test('test with fasta', async () => {
const command = new Pept2prot();
await command.run([">test", "AALTER"], { header: true, format: "csv" });
expect(output[0].startsWith("fasta_header,peptide,uniprot_id,protein_name,taxon_id,protein")).toBeTruthy();
expect(output[1].startsWith(">test,AALTER,P78330")).toBeTruthy();
expect(output.length).toBe(2);
});