Pytry
Python
code posted
by
scvr
created at 28 Aug 16:15
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#!/opt/local/bin/python # -*- coding: utf-8 -*- import os import math import csv import sys # Lire le fichier de ranges... with open(sys.argv[1], "rb") as infile, open("IRanges.txt", "wb") as outfile: reader = csv.reader(infile) writer = csv.writer(outfile, quoting=False) writer.writerow(["Start\tEnd\tLength"]) #Initialize variables IRval_s=0 IRval_e=0 idx=0 lgth=0 for i, line in enumerate(reader): print "Processing line " + str(i) + " : " + ''.join(line) + "\n" # skip first line corresponding to comments if i < 1: continue #if i > 20: break IRrange = line[0].split() # traitement des lignes paires (le +1 est parce qu'on a skippé la premiere ligne) if (i+1) % 2 == 0: IRval_s=int(IRrange[1])+1 else: IRval_e=int(IRrange[0])-1 lgth=IRval_e - IRval_s + 1 newline=str(IRval_s) + "\t" + str(IRval_e) + "\t" + str(lgth) print "Ici c'est: " + newline writer.writerow([newline]) #Reset variables IRval_s=0 IRval_e=0 lgth=0 infile.close() outfile.close() |
1.21 KB in 5 ms with coderay