Skip to content

Commit

Permalink
remove xrange
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacovercast committed Sep 12, 2019
1 parent 128d82b commit aaf80ea
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions easySFS.py
Expand Up @@ -73,7 +73,7 @@ def dadi_oneD_sfs_per_pop(dd, pops, proj, unfold, outdir, prefix, dtype):
fsc_oneD_filename = os.path.join(fsc_dir, pop+"_{}AFpop0.obs".format(M_or_D))
with open(fsc_oneD_filename, 'w') as outfile:
outfile.write("1 observation\n")
outfile.write("\t".join(["d0_"+str(x) for x in xrange(proj[i]+1)]) + "\n")
outfile.write("\t".join(["d0_"+str(x) for x in range(proj[i]+1)]) + "\n")
## Grab the fs data from the dadi sfs
with open(dadi_sfs_file) as infile:
outfile.write(infile.readlines()[1])
Expand Down Expand Up @@ -117,20 +117,20 @@ def dadi_twoD_sfs_combinations(dd, pops, proj, unfold, outdir, prefix, dtype, ve
with open(fsc_twoD_filename, 'w') as outfile:
outfile.write("1 observation\n")
## Format column headers (i.e. d0_0 d0_1 d0_2 .. d0_n for deme 0 up to sample size of n)
outfile.write("\t" + "\t".join(["d{}_".format(popidx[pair[0]]) + str(x) for x in xrange(projPairs[i][0]+1)]) + "\n")
outfile.write("\t" + "\t".join(["d{}_".format(popidx[pair[0]]) + str(x) for x in range(projPairs[i][0]+1)]) + "\n")

## Format row headers
row_headers = ["d{}_".format(popidx[pair[1]]) + str(x) for x in xrange(projPairs[i][1]+1)]
row_headers = ["d{}_".format(popidx[pair[1]]) + str(x) for x in range(projPairs[i][1]+1)]
## Read in the joint fs from dadi and format it nice for fsc
with open(dadi_joint_filename) as infile:
## Get the second line of the dadi-style sfs which contains the data
row_data = infile.readlines()[1].split()
## The length of each row is determined by the number of columns which == the size of the projection for pop2
## Have to add 1 to the value of the projection because xrange stops after 'n' elements
## Have to add 1 to the value of the projection because range stops after 'n' elements
## but we want all n+1 elements from 0,1,2,..,n
row_size = projPairs[i][0] + 1
## Slice the row data into evenly sized chunks based on the number of columns
rows = [row_data[i:i + row_size] for i in xrange(0, len(row_data), row_size)]
rows = [row_data[i:i + row_size] for i in range(0, len(row_data), row_size)]
## Sanity check. Make sure the number of rows you got is the same number you're expecting
## to get (# rows should == size of pop0 projection)
if not len(row_headers) == len(rows):
Expand Down

0 comments on commit aaf80ea

Please sign in to comment.