importing a function on linux server

9 views
Skip to first unread message

jmarchini

unread,
Jan 3, 2012, 6:53:57 PM1/3/12
to wikipl
Hi,

I discovered wikipl the other day and it's turning out to be very
useful for a task i am doing. I'm new to python but it seems to work
fine on my Mac Pro but i want to get it to work on one of my group's
servers. Here is the error i get when i try to import a function. Can
you help?

Many thanks,

Jonathan

mandarin{marchini}% uname -a
Linux mandarin.stats.ox.ac.uk 2.6.35.14-106.fc14.x86_64 #1 SMP Wed Nov
23 13:07:52 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
mandarin{marchini}% python
Python 2.7 (r27:82500, Sep 16 2010, 18:02:00)
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import wikipl
>>> from wikipl import Convert_impute2_to_PEDMAP
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "wikipl/__init__.py", line 356, in import_hook
import_WPL_article(toImport, 1)
File "wikipl/__init__.py", line 318, in import_WPL_article
wikipl_connect()
File "wikipl/__init__.py", line 72, in wikipl_connect
site = mwclient.Site(siteDomain, path = sitePath)
File "wikipl/mwclient/client.py", line 92, in __init__
self.site_init()
File "wikipl/mwclient/client.py", line 100, in site_init
siprop = 'general|namespaces', uiprop = 'groups|rights')
File "wikipl/mwclient/client.py", line 165, in api
info = self.raw_api(action, **kwargs)
File "wikipl/mwclient/client.py", line 248, in raw_api
json_data = self.raw_call('api', data).read()
File "wikipl/mwclient/client.py", line 223, in raw_call
url, data = data, headers = headers)
File "wikipl/mwclient/http.py", line 226, in post
path, headers, data)
File "wikipl/mwclient/http.py", line 161, in post
return self.request('POST', host, path, headers, data)
File "wikipl/mwclient/http.py", line 94, in request
self._conn.request(method, path, headers = headers)
File "/usr/lib64/python2.7/httplib.py", line 946, in request
self._send_request(method, url, body, headers)
File "/usr/lib64/python2.7/httplib.py", line 986, in _send_request
self.putheader(hdr, value)
File "/usr/lib64/python2.7/httplib.py", line 924, in putheader
str = '%s: %s' % (header, '\r\n\t'.join(values))
TypeError: sequence item 0: expected string, int found

Alexandros Kanterakis

unread,
Jan 4, 2012, 7:02:58 AM1/4/12
to wik...@googlegroups.com
Hi,

I was able to reproduce the error when I installed python 2.7 in Linux

The error is based on a bug of this particular release of Python.

The update to python 2.7.2 (latest) resolves the issue.

The problem according to python 2.7.2 change logs was:

- httplib.HTTPConnection.putheader() now accepts an arbitrary number of values
  for any header, matching what the documentation has claimed for a while.

I updated the WikiPL python library so that it prints a warning when python 2.7 is detected.

A quick n' dirty way to fix is to edit the file:

/usr/lib64/python2.7/httplib.py

and in line 924 change this:
   str = '%s: %s' % (header, '\r\n\t'.join(values))

to this:
   str = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values]))

Moreover:
As you can check from the methods I published so far I am very much interested in imputation. I am using impute2 extensively as part of my involvement in the genome of the Netherlands project (http://www.bbmri.nl/en-gb/activities/projects/131-genome-of-the-netherlands). I also have implemented a method for comparing imputation results published in one of your papers:

I am very happy that you found WikiPL useful. If you have any suggestions or comments I will be grateful to discuss it.

Regards,
Alex

jmarchini

unread,
Jan 4, 2012, 8:26:10 AM1/4/12
to wikipl
Hi Alex,

Thanks for the help. I will update python.

I do now have another question regarding the Convert_impute2_to_PEDMAP
function. Can you describe in more detail how the sample_names
argument works? Looking at the code it seems to allow a way of adding
the sample ids to the ped file but the argument doesn't seem to be
specifying a file with IDs (although that would be very useful). Does
it needs a comma separate list of IDs?

It would be quite useful if the documentation for the wikipl function
arguments was fuller. I can work out most of it but it's always
helpful to have docs.

Regards,

Jonathan

On Jan 4, 12:02 pm, Alexandros Kanterakis
<alexandros.kantera...@gmail.com> wrote:
> Hi,
>
> I was able to reproduce the error when I installed python 2.7 in Linux
>
> The error is based on a bug of this particular release of Python.
>
> The update to python 2.7.2 (latest) resolves the issue.
>
> The problem according to python 2.7.2 change
> logs<http://hg.python.org/cpython/raw-file/eb3c9b74884c/Misc/NEWS>was:
>
> - httplib.HTTPConnection.putheader() now accepts an arbitrary number of
> values
>   for any header, matching what the documentation has claimed for a while.
>
> I updated the WikiPL python library so that it prints a warning when python
> 2.7 is detected.
>
> A quick n' dirty way to fix is to edit the file:
>
> /usr/lib64/python2.7/httplib.py
>
> and in line 924 change this:
>    str = '%s: %s' % (header, '\r\n\t'.join(values))
>
> to this:
>    str = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values]))
>
> Moreover:
> As you can check from the methods I
> published<http://www.wikipl.com/index.php/Category:Genomic_Imputation>so
> far I am very much interested in imputation. I am using impute2
> extensively as part of my involvement in the genome of the Netherlands
> project (http://www.bbmri.nl/en-gb/activities/projects/131-genome-of-the-nethe...).

Alexandros Kanterakis

unread,
Jan 5, 2012, 7:36:44 PM1/5/12
to wik...@googlegroups.com
On Wed, Jan 4, 2012 at 2:26 PM, jmarchini <marc...@stats.ox.ac.uk> wrote:
Hi Alex,

Thanks for the help. I will update python.

I do now have another question regarding the Convert_impute2_to_PEDMAP
function. Can you describe in more detail how the sample_names
argument works? Looking at the code it seems to allow a way of adding
the sample ids to the ped file but the argument doesn't seem to be
specifying a file with IDs (although that would be very useful). Does
it needs a comma separate list of IDs?

It would be quite useful if the documentation for the wikipl function
arguments was fuller. I can work out most of it but it's always
helpful to have docs.

Regards,

Jonathan


Hi,
the sample_names is a python list for example:
sample_names = ["a", "b", "c"]

Alternatively, I added the argument: sample_names_filename which is a file that contains one sample name per line.

I also added the optional arguments: family_id_filename, p_id_filename, m_id_filename, gender_filename and pheno_filename that contain one respective id per line. I didn't have the chance to test it but it was very straightforward to add it. If there is any problem of course you may mail me back.

Not all these should be defined. For example:
 Convert_impute2_to_PEDMAP(
	chromosome = 22,
	legend_file = xxx.legend,
	haplotypes_file = xxx.hap,
	sample_names_filename = sample_names.txt,
	output = xxx.ped,
should do the work. (By using default values for the family, maternal, paternal, gender and pheno ids) 

I also wrote a bit about these parameters in the documentation section: http://www.wikipl.com/index.php/Convert_impute2_to_PEDMAP#Documentation

Regards,
Alex
Reply all
Reply to author
Forward
0 new messages