Mercurial > repos > yating-l > regtools_junctions_extract
comparison validator.py @ 0:01ed8e112f2a draft
planemo upload commit 6bf6d4ec8ff2ec6bd45b5f483ff2f83b6229d57d
author | yating-l |
---|---|
date | Wed, 12 Apr 2017 17:44:58 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:01ed8e112f2a |
---|---|
1 import sys | |
2 | |
3 """ | |
4 Call checkAndFixBed, check the integrity of bed file. If the strand is not "+" or "-" truncate that line and report to users | |
5 create a column and move the score column to that column. | |
6 """ | |
7 def checkAndFixBed(bedfile, revised_file): | |
8 # Store the lines that have been removed | |
9 removedLines = [] | |
10 # Remove the lines with invalid strand, create a score column to store the original scores and change scores in the original score column all to 1000 | |
11 with open(revised_file, 'w') as tmp: | |
12 with open(bedfile, 'r') as f: | |
13 lines = f.readlines() | |
14 i = 1 | |
15 for line in lines: | |
16 fields = line.split() | |
17 strand = fields[5] | |
18 score = fields[4] | |
19 fields[4] = '1000' | |
20 fields.append(score) | |
21 if (strand == '+' or strand == '-'): | |
22 tmp.write('\t'.join(map(str, fields))) | |
23 tmp.write("\n") | |
24 else: | |
25 removedLines.append("line" + str(i) + ": " + line) | |
26 i = i+1 | |
27 | |
28 return removedLines | |
29 | |
30 def main(): | |
31 inputfile = str(sys.argv[1]) | |
32 outputfile = str(sys.argv[2]) | |
33 removed = checkAndFixBed(inputfile, outputfile) | |
34 if (removed != []): | |
35 print "\nRemoved invalid lines: \n" | |
36 print "\n".join(removed) | |
37 | |
38 if __name__ == "__main__": | |
39 main() |