Not so much known about, but just bothered with:
Argparse and getopt for python/shell scripting. Something really nice about writing a proper script with proper options rather than relying on sys and shell variables all the time.
Another kind of niche one is that pandas has a 'read fixed width' file function, which when combined with a template allows you to read the otherwise quite verbose outputs that some tools use. In principle, this makes any regularly formatted file interrogable with code in lieu of machine-friendly formats.
template = u"""
---|------|------------------------|----|-------|-------|------|-----|----|---------|--------------|
No Hit Short Desc Prob E-value P-value Score SS Cols Query HMM Template HMM
"""
def hhparse(hhresult_file, verbose):
"""Convert HHpred's text-based output table in to a pandas dataframe"""
pattern = StringIO(template).readlines()[1]
colBreaks = [i for i, ch in enumerate(pattern) if ch == "|"]
widths = [j - i for i, j in zip(([0] + colBreaks)[:-1], colBreaks)]
hhtable = pd.read_fwf(hhresult_file, skiprows=8, nrows=10, header=0, widths=widths)
if verbose is True:
print(hhtable)
top_hit = str(hhtable.loc[0, "Hit"])[0:4]
top_hit_full = hhtable.loc[0, "Hit"]
top_prob = hhtable.loc[0, "Prob"]
top_eval = hhtable.loc[0, "E-value"]
top_pval = hhtable.loc[0, "P-value"]
top_score = hhtable.loc[0, "Score"]
if verbose is True:
print("Your best hit: (PDB ID | Probability | E-Value | P-Value | Score)")
print("\t".join([top_hit, top_prob, top_eval, top_pval, top_score]))
return top_hit, top_hit_full, top_prob, top_eval, top_pval, top_score
https://github.com/jrjhealey/bioinfo-tools/blob/master/tabulateHHpred.py#L41C1-L68C74
I'm also a big fan of one-liners for getting little jobs done, but sometimes you need a little more firepower, so being able to call on modules like BioPython in a shell one liner is a nice extra little boost:
For example, to robustly linearise a fasta file, you can write a shell function like so:
pylinearisefa(){
python3 -c 'import sys;from Bio import SeqIO; [print(f">{r.id}\n{r.seq}") for r in SeqIO.parse(sys.argv[1], "fasta")];' $1
}