Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions hub/utils/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,61 @@ def validate_gff(content):

return True

def validate_gtf(content):
if not content:
return False
lines = content.strip().split('\n')
for line in lines:
if line.startswith('#') or not line.strip():
continue
fields = line.split('\t')
if len(fields) != 9:
return False
seqid, source, type_, start, end, score, strand, frame, attributes = fields
if not start.isdigit() or not end.isdigit():
return False
if strand not in ['+', '-', '.']:
return False
if frame not in ['0', '1', '2', '.']:
return False
# GTF attribute column uses key "value"; quoted-value pairs separated by ';'
if 'gene_id' not in attributes and 'transcript_id' not in attributes:
return False
return True

def validate_paf(content):
if not content:
return False
lines = content.strip().split('\n')
for line in lines:
if not line.strip():
continue
fields = line.split('\t')
# PAF requires at least 12 mandatory columns
if len(fields) < 12:
return False
# Numeric fields: query_len, query_start, query_end, target_len,
# target_start, target_end, matching_bases, alignment_block_len, mapq
for idx in (1, 2, 3, 6, 7, 8, 9, 10, 11):
if not fields[idx].lstrip('-').isdigit():
return False
if fields[4] not in ('+', '-'):
return False
return True

def validate_gfa(content):
if not content:
return False
lines = content.strip().split('\n')
for line in lines:
if not line.strip():
continue
# GFA record types: H (header), S (segment), L (link), C (containment),
# P (path), W (walk), J (jump), # (comment)
if line[0] not in 'HSLCPWJ#':
return False
return True

def validate_list(content):
if not content.strip():
return False
Expand Down Expand Up @@ -236,6 +291,9 @@ def validate_fai(content):
{'type': 'BED', 'validator': validate_bed},
{'type': 'LIST', 'validator': validate_list},
{'type': 'GFF', 'validator': validate_gff},
{'type': 'GTF', 'validator': validate_gtf},
{'type': 'PAF', 'validator': validate_paf},
{'type': 'GFA', 'validator': validate_gfa},
{'type': 'JSON', 'validator': validate_json},
{'type': 'FAI', 'validator': validate_fai},
{'type': 'TEXT', 'validator': lambda x: True}, # Default fallback
Expand Down
18 changes: 18 additions & 0 deletions hub/utils/type_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@
"output": True,
"example": "seq\t.\tgene\t1\t30\t.\t+\t.\tID=gene1\nseq\t.\tmRNA\t1\t30\t.\t+\t.\tID=tx1;Parent=gene1\nseq\t.\texon\t1\t30\t.\t+\t.\tParent=tx1\nseq\t.\tCDS\t1\t30\t.\t+\t0\tParent=tx1",
},
{
"id": "GTF",
"input": True,
"output": True,
"example": 'seq\tStringTie\ttranscript\t1\t30\t1000\t+\t.\tgene_id "gene1"; transcript_id "tx1"; FPKM "12.34";\nseq\tStringTie\texon\t1\t30\t1000\t+\t.\tgene_id "gene1"; transcript_id "tx1"; exon_number "1";',
},
{
"id": "PAF",
"input": True,
"output": True,
"example": "queryA\t500\t10\t490\t+\ttargetA\t1000\t100\t580\t470\t480\t60\nqueryB\t300\t0\t300\t-\ttargetA\t1000\t650\t950\t290\t300\t60",
},
{
"id": "GFA",
"input": True,
"output": True,
"example": "H\tVN:Z:1.0\nS\ts1\tACGTACGTACGT\nS\ts2\tTTACGTACGTAC\nL\ts1\t+\ts2\t+\t4M\nP\tp1\ts1+,s2+\t*",
},
{
"id": "LIST",
"input": True,
Expand Down