Skip to content

Instantly share code, notes, and snippets.

@SJShaw
SJShaw / convert_openms_feature_version.py
Created May 28, 2024 14:14
Convert newer OpenMS feature tables to a format accepted by older GNPS
#!/usr/bin/env python3
import argparse
import sys
def convert_lines(lines):
new_lines = []
for line in lines:
# check the modifications are necessary in the first place
@SJShaw
SJShaw / as_json_to_tsv.sh
Last active April 19, 2024 14:10
Build simple regions TSV from antiSMASH JSON
#!/bin/bash
#
# Requires JQ, on debian/ubuntu derivatives, this can be installed with "apt install jq"
#
# Either provide an antiSMASH JSON results file as the argument or pipe it in
jq -r '.records[].areas[] | [.start, .end, (.products | join(","))] | flatten | @tsv' "$@"
@SJShaw
SJShaw / rotate_genbank.py
Created February 8, 2024 08:55
Rotate genbank, inserting optional padding
#!/usr/bin/env python3
import os
import sys
from Bio.SeqFeature import FeatureLocation, CompoundLocation
from Bio.Seq import Seq
from helperlibs.bio import seqio
def split_location_on_cut(location, cut_point):
@SJShaw
SJShaw / check_gene_ids.py
Created November 27, 2023 13:15
MIBiG gene reference checker
#!/usr/bin/env python
import json
import os
import sys
from mibig_html.common.secmet import Record
def check(json_file, gbk_dir):
@SJShaw
SJShaw / pre-commit
Created November 9, 2023 09:54
MIBiG JSON commit hook
#!/bin/bash
for line in `git diff --cached --name-only --diff-filter=ACM | grep -v retired | grep -e json`; do
if [[ "$line" != *.json ]] ; then
continue
fi
test `tail -c 1 $line`
if [ "$?" == "1" ] ; then
truncate -s -1 $line
echo "Aborting commit due to trailing newline; add changes and recommit"
exit 1
@SJShaw
SJShaw / remove_results.py
Last active September 1, 2023 13:15
Script to remove specific module(s) results from antiSMASH results JSON
#!/usr/bin/env python
"""
Removes specific module(s) results from antiSMASH results JSON
Modules are expected to be named as per a python `__name__` result,
e.g. "antismash.modules.clusterblast"
"""
@SJShaw
SJShaw / ontology_builder.py
Created August 1, 2023 11:15
Convert a file using simple whitespace (1 char per level) indents to a numbered system
#!/usr/bin/env python
import argparse
class Item:
def __init__(self, name, depth):
self.name = name
self.depth = depth
self.children = []
@SJShaw
SJShaw / pull_hmm.py
Created June 15, 2023 08:10
Extract an HMM profile from a set
#!/usr/bin/env python3
import argparse
import os
import sys
from typing import IO
def _main(accession: str, source: IO, destination: IO) -> int:
if not accession:
@SJShaw
SJShaw / combiner.py
Created July 9, 2019 13:07
Combine antiSMASH 5 result JSON files
#!/usr/bin/env python3
import json
import sys
def merge(inputs):
""" Merges the data in the given input handles and returns the result """
assert len(inputs) > 1
record_ids = set()
@SJShaw
SJShaw / strip_as4_annotations.py
Created April 5, 2018 14:39
Strip AS4 annotations from a genbank file
#!/usr/bin/env python
from __future__ import print_function, division
import sys
from helperlibs.bio import seqio
def strip_record(seq_record):
new_features = []