Commits

Lan Zagar committed 2e2c671

Replaced split(\n) with splitlines (closes #1160).

  • Participants
  • Parent commits d8249ba

Comments (0)

Files changed (9)

_bioinformatics/obiBioMart.py

     
 
 def de_tab(text, sep="\t"):
-    return [line.split(sep) for line in text.split("\n") if line.strip()]
+    return [line.split(sep) for line in text.splitlines() if line.strip()]
 
 
 def cached(func):

_bioinformatics/obiGO.py

 
     def ParseStanza(self, stanza):
         intern_tags = set(self._INTERN_TAGS)
-        for line in stanza.split("\n"):
+        for line in stanza.splitlines():
             if ":" not in line:
                 continue
             tag, rest = line.split(":", 1)
     def GetDefinedSlimsSubsets(self):
         """ Return a list of defined subsets.
         """
-        return [line.split()[1] for line in self.header.split("\n") if line.startswith("subsetdef:")]
+        return [line.split()[1] for line in self.header.splitlines() if line.startswith("subsetdef:")]
 
     def SetSlimsSubset(self, subset):
         """ Set the slims term subset to subset. If subset is a string it
                 f = open(os.path.join(file, "gene_association"))
         else:
             f = file
-        lines = [line for line in f.read().split("\n") if line.strip()]
+        lines = [line for line in f.read().splitlines() if line.strip()]
         from Orange.orng import orngMisc
         milestones = orngMisc.progressBarMilestones(len(lines), 100)
         for i,line in enumerate(lines):

_bioinformatics/obiGene.py

 
         fname = orngServerFiles.localpath_download("NCBI_geneinfo", "gene_info.%s.db" % self.taxid)
         file = open(fname, "rb")
-        self.update(dict([(line.split("\t", 3)[1], line) for line in file.read().split("\n") if line.strip() and not line.startswith("#")]))
+        self.update(dict([(line.split("\t", 3)[1], line) for line in file.read().splitlines() if line.strip() and not line.startswith("#")]))
 
         # NOTE orig init time for gene matcher: 2.5s, new 4s: investigate the slowdown
         # NOTE matches are not the same because aliases are build a bit
         if getattr(self, "_history", None) is None:
             fname = orngServerFiles.localpath_download("NCBI_geneinfo", "gene_history.%s.db" % self.taxid)
             try:
-                self._history = dict([(line.split("\t")[2], GeneHistory(line)) for line in open(fname, "rb").read().split("\n")])
+                self._history = dict([(line.split("\t")[2], GeneHistory(line)) for line in open(fname, "rb").read().splitlines()])
                 
             except Exception, ex:
                 print >> sys.srderr, "Loading NCBI gene history failed.", ex
         """
         if type(file) in [str, unicode]:
             file = open(file, "rb")
-        return cls((line.split("\t", 3)[1], line) for line in file.read().split("\n") if line.strip() and not line.startswith("#"))
+        return cls((line.split("\t", 3)[1], line) for line in file.read().splitlines() if line.strip() and not line.startswith("#"))
         
     def get_info(self, gene_id, def_=None):
         """ Search and return the GeneInfo object for gene_id

_bioinformatics/obiHomoloGene.py

     
     def load(self):
         path = orngServerFiles.localpath_download(self.DOMAIN, self.FILENAME)
-        lines = open(path, "rb").read().split("\n")[:-1]
+        lines = open(path, "rb").read().splitlines()[:-1]
         self._homologs = {} 
         self._homologs = dict([((h.taxonomy_id, h.gene_symbol), h) for h in [_homolog(line) for line in lines]])
         self._homologs_by_group = reduce(lambda dict, h: dict[h.group_id].append(h) or dict, self._homologs.values(), defaultdict(list))

_bioinformatics/obiKEGG.py

     @classmethod
     def to_dict(cls, text, field):
         text = cls.deindent(text, field).replace("\n ", " ")
-        lines = [t.split(": ",1) for t in text.split("\n")]
+        lines = [t.split(": ",1) for t in text.splitlines()]
         return dict([(key, [t.strip() for t in value.split(" ") if t]) for key, value in lines])
     
     @classmethod
     def to_ids(cls, text, field):
-        lines = [line.split(" ", 2)[:2] for line in cls.deindent(text, field).split("\n") if ":" in line.split(" ", 1)[0]]
+        lines = [line.split(" ", 2)[:2] for line in cls.deindent(text, field).splitlines() if ":" in line.split(" ", 1)[0]]
         return [db.lower() + id for db, id in lines] 
-#        ids = reduce(lambda col, line:1, text.split("\n"), [])
+#        ids = reduce(lambda col, line:1, text.splitlines(), [])
         return ids
     default = deindent
 #    entry = classmethod(lambda cls, text, field: cls.deindent(text, field).split()[0])
     def __init__(self, entrytext, index=None):
         self.entrytext = entrytext
         if not self.FIELDS:
-            self.FIELDS = set([line.split()[0] for line in entrytext.split("\n") if line.strip() and not line.startswith(" ")])
+            self.FIELDS = set([line.split()[0] for line in entrytext.splitlines() if line.strip() and not line.startswith(" ")])
         self._index(index)
         
     def _indices(self, field):

_bioinformatics/obiKEGG2/entry/fields.py

         
     def _convert(self):
         # Some dblinks can span multiple lines but are always 'indented' 
-        links = DBSimpleField._convert(self).replace("\n ", "").split("\n")
+        links = DBSimpleField._convert(self).replace("\n ", "").splitlines()
         links = [tuple(link.split(": ", 1)) for link in links]
         links = [(key, [v for v in values.split(" ") if v]) \
                  for key, values in links]

_bioinformatics/obiOMIM.py

     
     def load(self, filename):
         file = open(filename, "rb")
-        lines = file.read().split("\n")
+        lines = file.read().splitlines()
         self._disease_dict = dict([(disease(line), line) for line in lines if line])
         
     def diseases(self):

_bioinformatics/obiPPI.py

     def load(self):
         text = open(orngServerFiles.localpath_download("PPI", "BIOGRID-ALL.tab"), "rb").read()
         text = text.split("SOURCE\tPUBMED_ID\tORGANISM_A_ID\tORGANISM_B_ID\n", 1)[-1]
-        self.interactions = [BioGRIDInteraction(line) for line in text.split("\n") if line.strip()]
+        self.interactions = [BioGRIDInteraction(line) for line in text.splitlines() if line.strip()]
         
         self.protein_interactions = defaultdict(set)
         self.protein_names = {}

docs/reference-html/obiGO-yeast.py

 """
 
 def proces_david(dav):
-    lines = [line.split("\t") for line in dav.split("\n") if line]
+    lines = [line.split("\t") for line in dav.splitlines() if line]
     keys = lines[0]
     return dict([(line[1].split("~")[0], dict(zip(keys, line))) for line in lines])