Skip to content

Commit

Permalink
port to python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-t committed Oct 29, 2019
1 parent 34513a8 commit cf879dd
Show file tree
Hide file tree
Showing 89 changed files with 845 additions and 848 deletions.
2 changes: 1 addition & 1 deletion c/test_librgt/viactypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import os.path
from ctypes import *
from rgt.GenomicRegionSet import GenomicRegionSet
Expand Down
2 changes: 1 addition & 1 deletion data/setupBinaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
###################################################################################################

# Import
from __future__ import print_function


from optparse import OptionParser
from os import system, path, mkdir
Expand Down
6 changes: 3 additions & 3 deletions data/setupGenomicData.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
###################################################################################################

# Import
from __future__ import print_function

import gzip
from optparse import OptionParser
from os import system, path, remove, mkdir
Expand Down Expand Up @@ -110,7 +110,7 @@ def download(url, prefix, output=None):
print("OK")
else:
gen_root_url = "http://hgdownload.cse.ucsc.edu/goldenPath/hg19/chromosomes/"
chr_list = ["chr" + str(e) for e in range(1, 23) + ["X", "Y", "M"]]
chr_list = ["chr" + str(e) for e in list(range(1, 23)) + ["X", "Y", "M"]]
output_genome_file = open(output_genome_file_name, "w")
to_remove = []
for chr_name in chr_list:
Expand Down Expand Up @@ -219,7 +219,7 @@ def download(url, prefix, output=None):
print("OK")
else:
gen_root_url = "http://hgdownload.cse.ucsc.edu/goldenPath/mm9/chromosomes/"
chr_list = ["chr" + str(e) for e in range(1, 20) + ["X", "Y", "M"]]
chr_list = ["chr" + str(e) for e in list(range(1, 20)) + ["X", "Y", "M"]]
output_genome_file = open(output_genome_file_name, "w")
to_remove = []
for chr_name in chr_list:
Expand Down
2 changes: 1 addition & 1 deletion data/setupLogoData.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
###################################################################################################

# Import
from __future__ import print_function


import argparse
from os import path, mkdir, listdir, walk
Expand Down
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
master_doc = 'index'

# General information about the project.
project = u'RGT'
copyright = u'2016, Manuel Allhoff, Joseph C.C. Kuo, Eduardo G. Gusmao, Ivan G. Costa'
project = 'RGT'
copyright = '2016, Manuel Allhoff, Joseph C.C. Kuo, Eduardo G. Gusmao, Ivan G. Costa'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -217,8 +217,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'RGT.tex', u'RGT Documentation',
u'Manuel Allhoff, Joseph C.C. Kuo, Eduardo G. Gusmao, Ivan G. Costa', 'manual'),
('index', 'RGT.tex', 'RGT Documentation',
'Manuel Allhoff, Joseph C.C. Kuo, Eduardo G. Gusmao, Ivan G. Costa', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -247,8 +247,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'rgt', u'RGT Documentation',
[u'Manuel Allhoff, Joseph C.C. Kuo, Eduardo G. Gusmao, Ivan G. Costa'], 1)
('index', 'rgt', 'RGT Documentation',
['Manuel Allhoff, Joseph C.C. Kuo, Eduardo G. Gusmao, Ivan G. Costa'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -261,8 +261,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'RGT', u'RGT Documentation',
u'Manuel Allhoff, Joseph C.C. Kuo, Eduardo G. Gusmao, Ivan G. Costa', 'RGT', 'One line description of project.',
('index', 'RGT', 'RGT Documentation',
'Manuel Allhoff, Joseph C.C. Kuo, Eduardo G. Gusmao, Ivan G. Costa', 'RGT', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
10 changes: 5 additions & 5 deletions rgt/AnnotationSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

# Python 3 compatibility
from __future__ import print_function


# Python
import os
Expand Down Expand Up @@ -231,13 +231,13 @@ def load_gene_list(self, file_name, filter_havana=True, protein_coding=False, kn
pass

addt_list = line_list[8].split(";")
addt_list = filter(None, addt_list)
addt_list = [_f for _f in addt_list if _f]

# Processing additional list of options
addt_dict = dict()
for addt_element in addt_list:
addt_element_list = addt_element.split(" ")
addt_element_list = filter(None, addt_element_list)
addt_element_list = [_f for _f in addt_element_list if _f]
# Removing " symbol from string options
addt_element_list[1] = addt_element_list[1].replace("\"", "")
addt_dict[addt_element_list[0]] = addt_element_list[1]
Expand Down Expand Up @@ -487,11 +487,11 @@ def get(self, query=None, list_type=DataType.GENE_LIST, return_type=ReturnType.A
if isinstance(query, dict):

# Iterating over query elements
for query_key in query.keys():
for query_key in list(query.keys()):

# O(n) operation if a single value is being queried.
if not isinstance(query[query_key], list):
current_list = filter(lambda k: k[query_key] == query[query_key], current_list)
current_list = [k for k in current_list if k[query_key] == query[query_key]]

# O(n log n) operation if multiple values are being queried.
else:
Expand Down
12 changes: 6 additions & 6 deletions rgt/CoverageSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"""

# Python 3 compatibility
from __future__ import print_function
from __future__ import division



# Python
from functools import reduce
Expand Down Expand Up @@ -568,14 +568,14 @@ def index2coordinates(self, index, regions):
"""
r = regions
iter = r.__iter__()
r = iter.next()
r = next(iter)
sum = r.final
last = 0
i = 0
while sum <= index * self.stepsize:
last += len(self.coverage[i])
try:
r = iter.next()
r = next(iter)
except StopIteration:
sum += r.final
i += 1
Expand Down Expand Up @@ -706,7 +706,7 @@ def _map(self, x):
# get first chromosome, typically chr1
# for s in FastaReader(genome_path):
# chromosomes.append(s.name)
tmp = chrom_sizes_dict.keys()
tmp = list(chrom_sizes_dict.keys())
# tmp = map(lambda x: x.replace('chr',''), chromosomes)
tmp.sort()
genome_fasta = pysam.Fastafile(genome_path)
Expand Down Expand Up @@ -739,7 +739,7 @@ def _map(self, x):
content._compute()
r = []
for l in gc_content_cov:
tmp = map(content._map, l)
tmp = list(map(content._map, l))
r.append(tmp)

return r, content.g, content.g_gc
12 changes: 6 additions & 6 deletions rgt/ExperimentalMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

# Python
from __future__ import print_function


import os

Expand Down Expand Up @@ -179,7 +179,7 @@ def read(self, file_path, is_bedgraph=False, verbose=False, test=False, add_regi
if add_region_len:
for i, bed in enumerate(self.get_regionsnames()):
l = str(len(self.get_regionsets()[i]))
for k in self.fieldsDict["factor"].keys():
for k in list(self.fieldsDict["factor"].keys()):
if bed in self.fieldsDict["factor"][k]:
self.fieldsDict["factor"][k + "(" + l + ")"] = self.fieldsDict["factor"][k]
del self.fieldsDict["factor"][k]
Expand Down Expand Up @@ -315,7 +315,7 @@ def match_ms_tags(self, field, test=False):
"""

# check regions or reads have empty tag
altypes = self.fieldsDict[field].keys()
altypes = list(self.fieldsDict[field].keys())
if "ALL" in altypes:
altypes.remove("ALL")
for name in self.fieldsDict[field]["ALL"]:
Expand Down Expand Up @@ -364,14 +364,14 @@ def remove_empty_regionset(self):

def load_bed_url(self, temp_dir):
"""Load the BED files which contains url as file path to temporary directory."""
import urllib
for key, value in self.files.items():
import urllib.request, urllib.parse, urllib.error
for key, value in list(self.files.items()):
if self.types[self.names.index(key)] == "regions" and "http" in value:
tmpfile = os.path.join(temp_dir, value.split('/')[-1])
dest_name = tmpfile.partition(".gz")[0]
if not os.path.isfile(dest_name):
if not os.path.isfile(tmpfile):
urllib.urlretrieve(value, tmpfile)
urllib.request.urlretrieve(value, tmpfile)
if value.endswith(".gz"):
import gzip
with gzip.open(tmpfile, 'rb') as infile:
Expand Down
2 changes: 1 addition & 1 deletion rgt/GeneSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
###############################################################################

# Python
from __future__ import print_function


# Internal
from .Util import GenomeData
Expand Down
Loading

0 comments on commit cf879dd

Please sign in to comment.