Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating DNA2Vec to work with Python 3.7, and to work on Windows 10. #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

LightenedLimited
Copy link

A slight issue that I haven't gotten around to yet is fixing the memory usage, as the packages "resource" is a Unix specific package.

@kclejeune
Copy link

A slight issue that I haven't gotten around to yet is fixing the memory usage, as the packages "resource" is a Unix specific package.

Could you elaborate on the memory issue? I'm looking into using this in a unix environment and might be able to help.

@LightenedLimited
Copy link
Author

LightenedLimited commented May 21, 2020 via email

Copy link
Owner

@pnpnpn pnpnpn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more specific about what's incompatible in python 3.7?

@@ -1,6 +1,6 @@
import random
import string
import resource
# import resource
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of commenting this out, you can use the try and catch ImportError pattern: https://stackoverflow.com/questions/3131217/error-handling-when-importing-modules

You can move this within memory_usage

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll work on it when I get the chance.

requirements.txt Outdated
tox==2.7.0
tox-pyenv==1.0.3
virtualenv==15.1.0
arrow
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please pin the versions. This will install the latest versions, which may break the code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was one of the issues when moving up to Python 3.7. Several of the older versions of the libraries were incompatible with Python 3.7, so installing the latest versions would definitely reduce incompatibilities.

Copy link
Owner

@pnpnpn pnpnpn May 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that these older versions are incompatible with python 3.7. A couple of months from now, when there are upgrades to these libraries, the API for the new versions may not be backward-compatible to the current code.

Pinning the versions to new version numbers ensure that this is at least compatible to the version you tested on, which is python 3.7. You can see the versions of your current environment with pip freeze

@kclejeune
Copy link

kclejeune commented May 21, 2020

Can you be more specific about what's incompatible in python 3.7?

The existing version of requirements.txt does not correctly install dependencies and causes an error when building with wheels. I think I've mostly resolved this in my pull request.

class SingleKModel:
def __init__(self, model):
self.model = model
self.vocab_lst = sorted(model.vocab.keys())

class MultiKModel:
def __init__(self, filepath):
self.aggregate = word2vec.Word2Vec.load_word2vec_format(filepath, binary=False)
self.aggregate = gensim.models.KeyedVectors.load_word2vec_format(filepath, binary=False)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pnpnpn I'm not sure if this is actually broken in python 3.7, but Word2Vec has definitely been deprecated so this is probably still a good idea.

@@ -52,7 +52,7 @@ def train(self, kmer_seq_generator):

def write_vec(self):
out_filename = '{}.w2v'.format(self.out_fileroot)
self.model.wv.save_word2vec_format(out_filename, binary=False)
self.model.wv.save_word2vec_format("."+out_filename, binary=False)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you prepend with .? This would make it a hidden file in linux.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must've not noticed that change as I was working on Windows. I'll change it in the latest push.

requirements.txt Outdated
tox==2.7.0
tox-pyenv==1.0.3
virtualenv==15.1.0
arrow
Copy link
Owner

@pnpnpn pnpnpn May 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that these older versions are incompatible with python 3.7. A couple of months from now, when there are upgrades to these libraries, the API for the new versions may not be backward-compatible to the current code.

Pinning the versions to new version numbers ensure that this is at least compatible to the version you tested on, which is python 3.7. You can see the versions of your current environment with pip freeze

from gensim import matutils

import gensim
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The train_dna2vec.py also imports word2vec. Would the upgrade of gensim break the training of that file? Have you try training?

@@ -132,7 +132,7 @@ def main():
args.kmer_fragmenter))

out_txt_filename = '{}.txt'.format(out_fileroot)
with open(out_txt_filename, 'w') as summary_fptr:
with open(out_txt_filename, 'w+') as summary_fptr:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the w+ change?

print(header_str, file=fptr)
for vocab in vocabs:
vec_str = ' '.join("%f" % val for val in self.aggregate[vocab])
print('{} {}'.format(vocab, vec_str), file=fptr)
fptr.flush()
return SingleKModel(word2vec.Word2Vec.load_word2vec_format(fptr.name, binary=False))
open(fptr.name, "rb")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose for this?

@@ -25,6 +27,7 @@ def __init__(self, filepath):
self.data = {}
for k in range(self.k_low, self.k_high + 1):
self.data[k] = self.separate_out_model(k)
print(len(self.data))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for debugging? Please remove.

@@ -4,17 +4,19 @@
import tempfile
import numpy as np

from gensim.models import word2vec
# from gensim.models import word2vec
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just delete this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants