Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Going from python to Julia

$
0
0

@evcon131 wrote:

I really want to learn Julia to replace what I do in python. I was trying to create some basic things and kept getting errors I couldn’t resolve. This is an example of what I do in python:

cd={}
opt=''
oldtime=time.time()
with open(file2) as fh:
	for line in fh:
		if '#' not in line:
			ll=line.split('\t')
			chroosome=ll[0]
			if 'chr' in chroosome:
				chroosome=chroosome.replace('chr','')
			if chroosome not in cd:
				cd[chroosome]=[ll[1]]
			elif chroosome in cd:
				cd[chroosome].append(ll[1])
	with open(file) as fh:
		for line in fh:
			if '#' not in line:
				linecounter+=1
				if linecounter % 100000 == 0:
					newtime=time.time()
					timeelapsed = newtime-oldtime
					minutes=timeelapsed / 60
					displayminutes=format(minutes, '.2f') 
					sys.stdout.write(str(linecounter)+' total SNPs processed, last 100k in '+str(displayminutes)+' minutes\n')
					sys.stdout.flush()
					oldtime=newtime
				ll = line.split('\t')
				if 'chr' in chroosome:
					chroosome=chroosome.replace('chr','')
				if chroosome not in cd:
					opt+=line
				elif ll[1] not in cd[chroosome]:
					opt+=line
with open(outfile,'w') as fh:
	fh.write(opt)

Posts: 6

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 2795