Skip to content

Instantly share code, notes, and snippets.

@adamrp
Created March 6, 2015 21:53
Show Gist options
  • Save adamrp/cc337b63e7ac33160f4b to your computer and use it in GitHub Desktop.
Save adamrp/cc337b63e7ac33160f4b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from sys import argv
with open(argv[1], 'U') as input_f, open(argv[2], 'w') as output_f:
for line in input_f:
# Write comment/header line(s) to output file unmodified
if line.startswith('#'):
output_f.write(line)
continue
sample_id, other = line.split('\t', 1)
# Check if this ID is just a number or a number with a decimal point
try:
test = float(sample_id)
except ValueError:
# If not, then it's a BLANK or something, so write it unmodified
output_f.write(line)
continue
# If it has a dot, then it should be 15 digits long (9 for barcode,
# dot, and 5-digit unique number from old database)
if '.' in sample_id:
sample_id = sample_id.zfill(15)
else:
# If it's just a number, then it should be a 9-digit number
sample_id = sample_id.zfill(9)
output_f.write(sample_id + '\t' + other)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment