File size: 2,108 Bytes
23078ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb408b6
 
c5eee7b
 
fb408b6
23078ef
 
c5eee7b
23078ef
 
 
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
from pathlib import Path
import base64,json,gzip
ROOT=Path(__file__).parent
D=json.loads((ROOT/'data/tree-data.json').read_text()); meta=json.loads((ROOT/'data/human-metadata.json').read_text());genes=[];last=None;count=0
with gzip.open(ROOT/'data/human-annotations.gff3.gz','rt') as f:
 for line in f:
  if line.startswith('#'):continue
  r=line.rstrip().split('\t')
  if r[2]=='gene':count+=1
  if r[0]!='CM000663.2' or int(r[3])>1000000:continue
  if r[2]=='gene':
   attr=dict(x.split('=',1) for x in r[8].split(';') if '=' in x)
   last={'id':attr['ID'],'start':int(r[3]),'end':int(r[4]),'strand':r[6],'cds':[]};genes.append(last)
  if r[2]=='CDS' and last:last['cds'].append([int(r[3]),int(r[4])])
assert count==meta['gene_count'],(count,meta['gene_count'])
D['example']={'accession':meta['genbank_accession'],'gene_count':meta['gene_count'],'genes':genes}
counts=json.loads((ROOT/'data/locus-counts.json').read_text())
D['loci']={'counts':{a:v['loci'] for a,v in counts['records'].items()},'summary':counts['summary'],'source_field':'gene_count','retrieved_at':counts['retrieved_at']}
D['loci']['paths']={a:v['path'].rsplit('/',1)[0] for a,v in counts['records'].items()}
D['loci']['bucket']=counts['source_bucket']
D['icons']=json.loads((ROOT/'data/atlas-icons.json').read_text())
css=''.join(f"@font-face{{font-family:{n};src:url(data:font/ttf;base64,{base64.b64encode((ROOT.parent/'assets'/f'{n}.ttf').read_bytes()).decode()}) format('truetype');font-weight:100 900;font-display:swap}}" for n in ['Inter','Manrope'])
payload=base64.b64encode(gzip.compress(json.dumps(D,separators=(',',':'),ensure_ascii=False).encode(),mtime=0)).decode()
s=(ROOT/'template.html').read_text().replace('__FONTS__',css).replace('__DATA__',payload).replace('__SCRIPT__',(ROOT/'theme.js').read_text()+'\n'+(ROOT/'layers.js').read_text()+'\n'+(ROOT/'sweep.js').read_text()+'\n'+(ROOT/'access.js').read_text()+'\n'+(ROOT/'app.js').read_text())
(ROOT/'index.html').write_text(s)
(ROOT/'data/example-genes.json').write_text(json.dumps(D['example'],indent=2))
print('html',len(s),'real genes',count,'window loci',len(genes))