Mercurial > repos > yating-l > regtools_junctions_extract
comparison validator.py @ 0:2626c5b4c665 draft
planemo upload commit db634d933827ebc78981c7a0aa18205a85fa42e6-dirty
| author | yating-l |
|---|---|
| date | Mon, 19 Dec 2016 13:07:32 -0500 |
| parents | |
| children | cf258ca024ff |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:2626c5b4c665 |
|---|---|
| 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() |
