# -*- coding: utf-8 -*- #Luc Abate IRD URM224 MIVEGEC 05/02/2013 #fixFAS.py info sur l'auteur pour FSAconverter #Plateforme Seq-Gen Erick Desmarais et Frédérique Cerqueira from Tkinter import * from tkFileDialog import * from re import * import os ######fonctions de base def selectfolder(): global foldername foldername = askdirectory(parent=root, title='Please select a directory') if foldername: print "Folder selected : " print foldername return foldername def selectfile(): global filename filename = askopenfilename(parent=root, title='Please select a file') if filename: print "File selected : " print filename return filename def saveas(): global filenameout myFormats=[ ('Text','*.txt') ] filenameout = asksaveasfilename(parent=root,filetypes=myFormats,title="Save output as...") if len(filenameout) > 0: print "Now saving as %s" % (filenameout) if search('.txt$',filenameout): return filenameout else: filenameout=filenameout+".txt" return filenameout ######Pour menu sous fenetre def help1(): filewin = Toplevel(root) filewin.title('Help') tex = Label(filewin, text='******AB1converter utility :******\nConvert .ab1 files (from ABI3500xl sequencer)\nfor compatibillty with seqscape version previous to 2.7\nNew files will be created in AB1converter folder\nwithin the folder selected\n') tex.pack() button = Button(filewin, text="Close window", command=filewin.destroy) button.pack() def about(): filewin = Toplevel(root) filewin.title('About') tex = Label(filewin, text='pyAB1converter is a python program\nderived from fixFSA.py script\nwritten by Jean Peccoud\nand modified by Luc Abate\n\nMore info at :\nSeqGen platform - UMII\nBat 24 1°étage\ncc 63 - Pl. E Bataillon\n34095 Montpellier Cedex 5') tex.pack() button = Button(filewin, text="Close window", command=filewin.destroy) button.pack() ######pour AB1converter def findAddress(mystring): """convertit les octets lus en decimal""" result = 0 n=len(mystring) taille=range(n) taille.reverse() for i in taille: result=result+ord(mystring[i])*(16**(2*n-2*i-2))#ord() pour obtenir code Ascii d'un caractere puis convertit en decimal return result ###### def AB1converter(): print "" print " ABconverter" print " AB1converter v.1 (2013-03)" print "" print " Convert .ab1 files from ABI3500xl for" print " compatibility with seqscape version" print " previous to 2.7" print "" selectfolder() if foldername: liste=os.listdir(foldername) print '%i file(s) in selected folder' % (len(liste)) tbl_ab1=[] compteurab1=0 for s in liste: if search('\.ab1', s): tbl_ab1.append(s) compteurab1=compteurab1+1 if compteurab1==0: print "No ab1 file found!" else: if compteurab1==1: print "in which ", compteurab1, "is a .ab1 file!" else: print "in which ", compteurab1, "are .ab1 files!" try: os.mkdir(foldername+"\AB1converted") except OSError: pass i=0 while i offset data (32-bit integer at byte 26) myaddress2=0 mybool=0 while rawdata[myaddress:myaddress+4] != 'SVER': myaddress=myaddress+28#pour passer au suivant if rawdata[myaddress:myaddress+4] == 'HCFG': mybool=mybool+1 if mybool==1:#pour sauvegarder position du premier HCFG myaddress2 myaddress2=myaddress-28 elif rawdata[myaddress:myaddress+4] == 'MCHN': ###pour machine name### a=findAddress(rawdata[myaddress+20:myaddress+24]) #print rawdata[a+1:a+16] fout.seek(a+1) fout.write('3130XL-17217-02')#manque 0 à la fin car trop long elif rawdata[myaddress:myaddress+4] == 'MODL': ###attention ici pas offset mais directement caracteres### #print rawdata[myaddress+20:myaddress+24] fout.seek(myaddress+20) fout.write('3100')#au lieu de 3500 elif rawdata[myaddress:myaddress+4] == 'PDMF':#comme 2x PDMF fera 2x a=findAddress(rawdata[myaddress+20:myaddress+24]) #print rawdata[a+1:a+23] fout.seek(a+1) fout.write('KB_3130_POP7_BDTv3.mob')#au lieu de KB_3500_POP7_BDTv3.mob elif rawdata[myaddress:myaddress+4] == 'SVER': ###pour data collection sw version### a=findAddress(rawdata[myaddress+20:myaddress+24]) #print rawdata[a+1:a+48] fout.seek(a+1) fout.write('3.0 ')#y a des espaces car pour ecrire dessus 3500 instrument etc. ###pour KB version### b=findAddress(rawdata[myaddress+48:myaddress+52]) #print rawdata[b+1:b+11] fout.seek(b+1) fout.write('KB 1.4.0 ') ###pour firmware version number### c=findAddress(rawdata[myaddress+76:myaddress+80]) #print rawdata[c+1:c+11] fout.seek(c+1) fout.write('6258005-00')#au lieu de 6228001-05 if myaddress2 != 0 : #offset item pour instrument familly a=findAddress(rawdata[myaddress2+76:myaddress2+80]) #print rawdata[a:a+4] fout.seek(a) fout.write('31')#31XX au lieu de 35XX #offset item pour instrument name b=findAddress(rawdata[myaddress2+104:myaddress2+108]) #print rawdata[b:b+4] fout.seek(b) fout.write('3130 UnitID=7;CPUBoard=ECPU550;ArraySize=16;SerialNumber=17217-020; ')#au lieu de 3500 !!! attention si met xl le l va sur le parametre #fout.write('3130xl') #fout.write('3130') #modif item size et num element pour name instrument (pour rajout xl) #fout.seek(myaddress2+103) #fout.write(chr(7))#7 au lieu de 5 #fout.seek(myaddress2+99) #fout.write(chr(7)) #modif offset item (+2), item size (-2) et num element (-2) pour parameters instrument (car impacté par modif instrument name #c=findAddress(rawdata[myaddress2+132:myaddress2+136]) #cbis=c+2 #print "#", c, "-", cbis #fout.seek(myaddress2+132)#pour changer offset +2 #fout.write(chr(cbis)) #fout.seek(c+2)# #fout.write('UnitID=7;CPUBoard=ECPU550;ArraySize=16;SerialNumber=17217-020;') #pour changer item size & num element #fout.seek(myaddress2+128) #fout.write(chr(63)) #fout.seek(myaddress2+124) #fout.write(chr(63)) #print "item size", findAddress(rawdata[myaddress2+128:myaddress2+132]) #print "nm element", findAddress(rawdata[myaddress2+124:myaddress2+128]) #print "tag size", findAddress(rawdata[myaddress2+120:myaddress2+124]) print tbl_ab1[i], "patched!" f.close() fout.close() i=i+1 print " ************************************************" print " job fini" #print " ************************************************" ###### print " ___________________________________________________" print "" print " Seq-Gen Platform - UMII Bat 24 etage 1" print " cc 63 - Pl. E Bataillon - 34095 Montpellier Cedex 5" print " ___________________________________________________" print "" ###### root = Tk() root.title('pyAB1converter (beta version)') menubar = Menu(root) filemenu = Menu(menubar, tearoff=0) filemenu.add_command(label="Choose folder", command=AB1converter) filemenu.add_separator() filemenu.add_command(label="Exit", command=root.quit) menubar.add_cascade(label="AB1converter", menu=filemenu) #utilitiesmenu = Menu(menubar, tearoff=0) #utilitiesmenu.add_command(label="G2G (béta)", command=g2g) #utilitiesmenu.add_command(label="G2S (béta)", command=g2s) #menubar.add_cascade(label="Utilities", menu=utilitiesmenu) helpmenu = Menu(menubar, tearoff=0) helpmenu.add_command(label="Help", command=help1) helpmenu.add_command(label="About...", command=about) menubar.add_cascade(label="Help", menu=helpmenu) root.config(menu=menubar) root.mainloop() root.destroy()