#! /usr/bin/python3 # -*- coding: utf-8 -*- last_edit = "Last edited on 2026-09-12 09:26:07 by stolfi" import sys, re, os, string, glob from sys import stderr as err import html_gen as h from process_funcs import bash, run_command, basic_line_loop import html_report_funcs as hr import bencao_starps_report_funcs as repf from math import sqrt, hypot, exp, log, floor, ceil, isfinite, isnan, inf, nan def get_clean_normalized_starps_text_wc(loc_ec, del_qo, exp_irm): ivt_file = "res/starps-gd-wc-par.ivt" rawtx_wc, nlin = fetch_starps_line(ivt_file, loc_ec) assert rawtx_wc != None, f"** cannot find {loc_ec} in the starps file" def data_error(msg): file_line_error(ivt_file, nlin, msg, f"<{loc_ec}> {rawtx_wc}") assert False # .................................................................. utype = "wc" text_wc, head, tail = spf.convert_starps_raw_text(rawtx_wc, utype, data_error) text_wc = spf.normalize_starps_text(text_wc, utype, del_qo, exp_irm, data_error) return text_wc # ---------------------------------------------------------------------- def fetch_starps_line(ivt_file, loc_starps): # Reads fle {ivt_file} (assumed to be UTF-8) and looks for a line with # locus ID "<{loc_starps}>". Returns that line, minus the locus D, stripped. # Also returns the line number (from 1). # # If the {loc_starps} is not found, returns {None,None}. # Just in case: loc_starps = re.sub(r"[<>]", "", loc_starps) loc_pat = f"<{loc_starps}>" rd = open(ivt_file, "r") rd.reconfigure(encoding='utf-8') text = None nlin = 0 for line in rd: nlin += 1 if re.match(loc_pat, line): text = re.sub(loc_pat, "", line) text = text.strip() break rd.close() return text, nlin # ---------------------------------------------------------------------- def test_stuff(): err.write("BEGIN TESTING\n") err.write("----------------------------------------\n") err.write("END TESTING\n") return # ---------------------------------------------------------------------- if len(sys.argv) == 2 and sys.argv[1] == "R72.TEST": test_stuff()