Created
April 5, 2016 06:00
-
-
Save philippbayer/b36b46ab9ed5d8e343f220cf448cc1e0 to your computer and use it in GitHub Desktop.
This tiny script takes bedtools (or similar) output and prints the first and last 10 rows for a contig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Queue | |
| import sys | |
| # prints first 10 and last 10 rows for each contig | |
| # does NOT guarantee that the first and 10 don't overlap (use uniq) | |
| fh = open(sys.argv[1]) | |
| header = fh.readline() | |
| q = Queue.Queue(10) # for the last elements | |
| current_contig = "" | |
| for line in fh: | |
| ll = line.split() | |
| contig = ll[0] | |
| if contig != current_contig: | |
| # print last queue | |
| while not q.empty(): | |
| print q.get(), | |
| # now make new one | |
| current_contig = contig | |
| seen_counter = 1 | |
| print line, | |
| continue | |
| seen_counter += 1 | |
| if seen_counter <= 10: | |
| print line, | |
| try: | |
| q.put(line, block=False) | |
| except Queue.Full: | |
| # throw away one | |
| q.get() | |
| q.put(line, block=False) | |
| # print last queue | |
| while not q.empty(): | |
| print q.get(), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment