#!/bin/env python2.6 """ Read lines in BED format (tab-delimited) from STDIN and print out only gene names (4th column). DO NOT pipe any BED header lines to this program! Usage: grep -v ^track sample_data.bed | ./BME_205_Python_lecture_firstProg """ import sys for line in sys.stdin: line = line.rstrip ('\n\r') # not needed here, but generally a good idea fields = line.split ('\t') # split line on tab character if len (fields) < 4: print >> sys.stderr, \ "Bad BED line! Not enough fields. Here is the line:\n", \ line sys.exit (1) else: print fields[3]