string filename,expername,experlist,str_resol,str_width,st,st2,delim,gelname; FILE fp; integer i,ct1,ct2,idx_dye,idx_samplefile,idx_size,idx_h,ok,resol; integer pk_count,keysfromsample,dyenr,lanenr,maptosingleexper; string pk_dye[],pk_samplefile[],key; float pk_size[],pk_h[],width; integer dyecount,lanecount; string dyenames[],dyefpr[],lanenames[]; INDEX dyeidx,laneidx,finder; DIALOG dlg; CRFPRINT fpr[],fpr0; for i=1 to DbGetExperCount do if DbGetExperClass(i)="FPR" then experlist=experlist+DbGetExperName(i)+" "; expername=experlist;expername=splitstring(expername," "); if expername="" then { message("The database does not contain a fingerprint experiment.~nPlease create a fingerprint experiment with a valid reference system first"); stop; } //prompt for file name if not(FilePromptName("Select the GeneScan file you want to import",filename,0)) then stop; //scan first line & collect information if not(FileOpenRead(fp,filename)) then { message("Unable to read file"); stop; } st=fileread(fp,9999); //determine delimiter character for i=1 to length(st) do { if substring(st,i,i)=" " then ct1=ct1+1; if substring(st,i,i)=";" then ct2=ct2+1; } if (ct1<1) and (ct2<1) then { FileClose(fp); message("Invalid file format: no valid separator found"); stop; } if ct1>ct2 then delim=" "; else delim=";"; ct1=0; //determint required column positions idx_dye=0;idx_samplefile=0;idx_size=0;idx_h=0; while st<>"" do { st2=splitstring(st,delim); while substring(st2,length(st2),length(st2))=" " do st2=substring(st2,1,length(st2)-1); ct1=ct1+1; if st2="Dye/Sample Peak" then idx_dye=ct1; if st2="Sample File Name" then idx_samplefile=ct1; if st2="Size" then idx_size=ct1; if st2="Height" then idx_h=ct1; } if idx_dye=0 then { FileClose(fp);message("'Dye/Sample Peak' colum not found"); stop; } if idx_samplefile=0 then { FileClose(fp);message("'Sample File Name' column not found"); stop; } if idx_size=0 then { FileClose(fp);message("'Size' column not found"); stop; } if idx_h=0 then { FileClose(fp);message("'Height' column not found"); stop; } //read data setbusy("Loading data..."); pk_count=0; while not(FileIsEnd(fp)) do { st=fileread(fp,9999);ct1=0; if (length(st)>3) then { pk_count=pk_count+1; while st<>"" do { st2=splitstring(st,delim); while substring(st2,length(st2),length(st2))=" " do st2=substring(st2,1,length(st2)-1); if (substring(st2,1,1)="~"") and (substring(st2,length(st2),length(st2))="~"") then st2=substring(st2,2,length(st2)-1); ct1=ct1+1; if ct1=idx_dye then { pk_dye[pk_count]=splitstring(st2,","); if IdxGet(dyeidx,pk_dye[pk_count])<=0 then { dyecount=dyecount+1;dyenames[dyecount]=pk_dye[pk_count];IdxSet(dyeidx,pk_dye[pk_count],dyecount); } dyenr=IdxGet(dyeidx,pk_dye[pk_count]); } if ct1=idx_samplefile then { pk_samplefile[pk_count]=splitstring(st2,".fsa"); if IdxGet(laneidx,pk_samplefile[pk_count])<=0 then { lanecount=lanecount+1;lanenames[lanecount]=pk_samplefile[pk_count];IdxSet(laneidx,pk_samplefile[pk_count],lanecount); } lanenr=pk_samplefile[pk_count]; } if ct1=idx_size then pk_size[pk_count]=val(st2); if ct1=idx_h then pk_h[pk_count]=val(st2); } } } FileClose(fp); setbusy(""); for i=1 to dyecount do dyefpr[i]=expername; if (lanecount>=199) then { message("This file contains too much lanes. Please split it before reading"); stop; } str_resol="1000"; str_width="5"; gelname=filename; keysfromsample=1; while find(gelname,"\",1)>0 do splitstring(gelname,"\"); if find(gelname,".",1) then gelname=splitstring(gelname,"."); DlgAddText(dlg,"Gel file name in BioNumerics",200,20,150,15); DlgAddEdit(dlg,gelname,200,40,150,22); DlgAddText(dlg,"Curve resolution",200,70,150,15); DlgAddEdit(dlg,str_resol,200,90,70,22); DlgAddText(dlg,"Band width",200,120,150,15); DlgAddEdit(dlg,str_width,200,140,70,22); DlgAddCheck(dlg,"Take keys from 'sample file name'",keysfromsample,200,180,190,22); for i=1 to dyecount do { DlgAddText(dlg,"Map dye '"+dyenames[i]+"' into:",15,20+45*(i-1),150,15); DlgAddList(dlg,experlist,dyefpr[i],15,35+45*(i-1),150,150,"DROP"); } ok=0; while not(ok) do { if not(DlgShow(dlg,"Import GeneScan file",400,330)) then stop; ok=1; if expername="" then { ok=0; message("You should select an experiment!"); } resol=val(str_resol); width=val(str_width); } //determine if mapped to different experiment types according to dye maptosingleexper=1; if dyecount>1 then if dyefpr[1]<>dyefpr[2] then maptosingleexper=0; setbusy("Importing data..."); if maptosingleexper then { CrFprCreate(fpr0,gelname,dyefpr[1]); for i=1 to pk_count do { st=pk_samplefile[i]; if dyecount>1 then st=st+"_"+pk_dye[i]; lanenr=IdxGet(finder,st); if lanenr<=0 then { key=""; if keysfromsample then key=st; lanenr=CrFprAddLane(fpr0,dyefpr[1],key); if (key<>"") and (not(DbIsKeyPresent(key))) then DbAddEntry(key); IdxSet(finder,st,lanenr); } CrFprAddBand(fpr0,lanenr,pk_size[i],pk_h[i],width); } CrFprBandsToCurve(fpr0,resol); CrFprSave(fpr0); } if not(maptosingleexper) then { //create gels & lanes for dyenr=1 to dyecount do { st=gelname+"_"+dyenames[dyenr]; CrFprCreate(fpr[dyenr],st,dyefpr[1]); for i=1 to lanecount do { key=""; if keysfromsample then key=lanenames[i]; if (key<>"") and (not(DbIsKeyPresent(key))) then DbAddEntry(key); CrFprAddLane(fpr[dyenr],dyefpr[dyenr],key); } } for i=1 to pk_count do { dyenr=IdxGet(dyeidx,pk_dye[i]); lanenr=IdxGet(laneidx,pk_samplefile[i]); CrFprAddBand(fpr[dyenr],lanenr,pk_size[i],pk_h[i],width); } //save gels for dyenr=1 to dyecount do { CrFprBandsToCurve(fpr[dyenr],resol); CrFprSave(fpr[dyenr]); } } setbusy("");