May-22-2021, 07:35 AM
(This post was last modified: May-22-2021, 07:40 AM by Gribouillis.)
You would get a better structured code with a function to handle each line
def is_vcf_line(line): columns = line.split('\t') return bool( re.match(r"^chr(?:[1-9][0-9]?|[XYM])$", columns[0]) and re.match(r"^[1-9][0-9]*$", columns[1]) and re.match(r"^[ATGC]$", columns[3]) and re.match(r"^[ATGC]$", columns[4])) def is_vcf(filename): with open(filename) as lines: return all(is_vcf_line(line) for line in lines)