import sys
def test_bed_bindings():
print("Testing BED bindings...")
try:
import biometal
print(" ✓ Bed3Stream class exists:", hasattr(biometal, 'Bed3Stream'))
print(" ✓ Bed3Stream.from_path exists:", hasattr(biometal.Bed3Stream, 'from_path'))
print(" ✓ Bed6Stream class exists:", hasattr(biometal, 'Bed6Stream'))
print(" ✓ Bed6Stream.from_path exists:", hasattr(biometal.Bed6Stream, 'from_path'))
print(" ✓ Bed12Stream class exists:", hasattr(biometal, 'Bed12Stream'))
print(" ✓ Bed12Stream.from_path exists:", hasattr(biometal.Bed12Stream, 'from_path'))
print(" ✓ Bed3Record exists:", hasattr(biometal, 'Bed3Record'))
print(" ✓ Bed6Record exists:", hasattr(biometal, 'Bed6Record'))
print(" ✓ Bed12Record exists:", hasattr(biometal, 'Bed12Record'))
print(" ✅ BED bindings OK")
return True
except Exception as e:
print(f" ❌ BED bindings failed: {e}")
return False
def test_gfa_bindings():
print("\nTesting GFA bindings...")
try:
import biometal
print(" ✓ GfaStream class exists:", hasattr(biometal, 'GfaStream'))
print(" ✓ GfaStream.from_path exists:", hasattr(biometal.GfaStream, 'from_path'))
print(" ✓ GfaSegment exists:", hasattr(biometal, 'GfaSegment'))
print(" ✓ GfaLink exists:", hasattr(biometal, 'GfaLink'))
print(" ✓ GfaPath exists:", hasattr(biometal, 'GfaPath'))
print(" ✅ GFA bindings OK")
return True
except Exception as e:
print(f" ❌ GFA bindings failed: {e}")
return False
def test_vcf_bindings():
print("\nTesting VCF bindings...")
try:
import biometal
print(" ✓ VcfStream class exists:", hasattr(biometal, 'VcfStream'))
print(" ✓ VcfStream.from_path exists:", hasattr(biometal.VcfStream, 'from_path'))
print(" ✓ VcfHeader exists:", hasattr(biometal, 'VcfHeader'))
print(" ✓ VcfRecord exists:", hasattr(biometal, 'VcfRecord'))
print(" ✅ VCF bindings OK")
return True
except Exception as e:
print(f" ❌ VCF bindings failed: {e}")
return False
def test_gff3_bindings():
print("\nTesting GFF3 bindings...")
try:
import biometal
print(" ✓ Gff3Stream class exists:", hasattr(biometal, 'Gff3Stream'))
print(" ✓ Gff3Stream.from_path exists:", hasattr(biometal.Gff3Stream, 'from_path'))
print(" ✓ Gff3Record exists:", hasattr(biometal, 'Gff3Record'))
print(" ✅ GFF3 bindings OK")
return True
except Exception as e:
print(f" ❌ GFF3 bindings failed: {e}")
return False
def test_actual_parsing():
print("\nTesting actual file parsing...")
try:
import biometal
print(" Testing BED6 parsing (gzipped)...")
stream = biometal.Bed6Stream.from_path("tests/data/real_world/encode_peaks.bed.gz")
count = 0
for record in stream:
count += 1
assert hasattr(record, 'chrom')
assert hasattr(record, 'start')
assert hasattr(record, 'end')
assert hasattr(record, 'name')
assert hasattr(record, 'score')
assert hasattr(record, 'strand')
print(f" ✓ Parsed {count} BED6 records from .gz file")
print(" Testing GFA parsing...")
stream = biometal.GfaStream.from_path("tests/data/real_world/lambda_phage.gfa")
segments = 0
links = 0
paths = 0
for record in stream:
if isinstance(record, biometal.GfaSegment):
segments += 1
elif isinstance(record, biometal.GfaLink):
links += 1
elif isinstance(record, biometal.GfaPath):
paths += 1
print(f" ✓ Parsed {segments} segments, {links} links, {paths} paths")
print(" Testing VCF parsing (gzipped)...")
stream = biometal.VcfStream.from_path("tests/data/real_world/synthetic_1000g.vcf.gz")
header = stream.header()
print(f" ✓ Parsed VCF header: {header.fileformat}")
count = 0
for record in stream:
count += 1
assert hasattr(record, 'chrom')
assert hasattr(record, 'pos')
assert hasattr(record, 'reference') assert hasattr(record, 'alternate') print(f" ✓ Parsed {count} VCF records from .gz file")
print(" Testing GFF3 parsing (gzipped)...")
stream = biometal.Gff3Stream.from_path("tests/data/real_world/ensembl_chr21.gff3.gz")
count = 0
genes = 0
for record in stream:
count += 1
assert hasattr(record, 'seqid')
assert hasattr(record, 'feature_type')
assert hasattr(record, 'start')
assert hasattr(record, 'end')
if record.feature_type == "gene":
genes += 1
if count >= 1000: break
print(f" ✓ Parsed {count} GFF3 records ({genes} genes) from .gz file")
print(" ✅ File parsing OK")
return True
except Exception as e:
print(f" ❌ File parsing failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
print("=" * 60)
print("Python Bindings Verification for Format Library")
print("=" * 60)
results = []
results.append(("BED bindings", test_bed_bindings()))
results.append(("GFA bindings", test_gfa_bindings()))
results.append(("VCF bindings", test_vcf_bindings()))
results.append(("GFF3 bindings", test_gff3_bindings()))
results.append(("File parsing", test_actual_parsing()))
print("\n" + "=" * 60)
print("SUMMARY")
print("=" * 60)
passed = sum(1 for _, result in results if result)
total = len(results)
for name, result in results:
status = "✅ PASS" if result else "❌ FAIL"
print(f"{name:20s}: {status}")
print(f"\nTotal: {passed}/{total} tests passed")
if passed == total:
print("\n🎉 All Python bindings working correctly!")
return 0
else:
print(f"\n⚠️ {total - passed} test(s) failed")
return 1
if __name__ == "__main__":
sys.exit(main())