File size: 1,881 Bytes
7fcf0b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os

os.chdir('/225040511/project/react_code_bioagent_deepseek/runs/evolution_20260522_140917')

# Parse GFF for CDS features to create gene_annotations.csv
cds_entries = []
with open('prokka_annotation/ecoli_ref.gff') as f:
    for line in f:
        if line.startswith('#'):
            continue
        parts = line.strip().split('\t')
        if len(parts) < 9:
            continue
        if parts[2] == 'CDS':
            seqid = parts[0]
            start = int(parts[3])
            end = int(parts[4])
            strand = parts[6]
            attrs = {}
            for attr in parts[8].split(';'):
                if '=' in attr:
                    k, v = attr.split('=', 1)
                    attrs[k] = v
            gene_id = attrs.get('ID', '')
            gene_name = attrs.get('gene', '')
            locus_tag = attrs.get('locus_tag', '')
            product = attrs.get('product', '')
            
            # Use gene name if available, otherwise locus_tag
            display_name = gene_name if gene_name else locus_tag
            
            cds_entries.append({
                'gene_id': display_name,
                'seqid': seqid,
                'start': start,
                'end': end,
                'strand': strand,
                'product': product
            })

# Write gene_annotations.csv
with open('gene_annotations.csv', 'w') as f:
    f.write('gene_id,seqid,start,end,strand,product\n')
    for entry in cds_entries:
        f.write(f"{entry['gene_id']},{entry['seqid']},{entry['start']},{entry['end']},{entry['strand']},{entry['product']}\n")

print(f"Written gene_annotations.csv with {len(cds_entries)} CDS entries")
print(f"File size: {os.path.getsize('gene_annotations.csv')} bytes")

# Verify the variants_shared.csv
print("\n=== variants_shared.csv ===")
with open('variants_shared.csv') as f:
    print(f.read())