joshuagryphon / plastid

Position-wise analysis of sequencing and genomics data
https://plastid.readthedocs.io
Other
36 stars 16 forks source link

Stratified Variable Five Prime Map Factory Error when passed .txt file #16

Closed bdweave closed 7 years ago

bdweave commented 7 years ago

I am attempting to recreate your R^2 first vs second half CDS plot in the BMC Genomics Paper, except with incorporating P-sites offsets via a txt file that I've determined based upon the plastid meta gene analysis profiles.

The first error, when attempting to implement the StratifiedVariableFivePrimeMapFactory is that it isn't defined in the package after running from plastid import *:

File "./first_v_second_half_RPF_analysis.py", line 12, in footprints.set_mapping(StratifiedVariableFivePrimeMapFactory.from_file("/tomato/dev/job/BradW/2C_ribo/data_analysis/plastid_5-24/X3_riboprofile_new.txt")) NameError: name 'StratifiedVariableFivePrimeMapFactory' is not defined.

Next - trying to use the VariableFivePrimeMapFactory function instead, the following error gets thrown:

Traceback (most recent call last): File "./first_v_second_half_RPF_analysis.py", line 12, in footprints.set_mapping(VariableFivePrimeMapFactory.from_file("~/tomato/dev/job/BradW/2C_ribo/data_analysis/plastid_5-24/X3_riboprofile_new.txt")) File "plastid/genomics/map_factories.pyx", line 560, in plastid.genomics.map_factories.VariableFivePrimeMapFactory.from_file (/tmp/pip-build-z6XyxK/plastid/plastid/genomics/map_factories.c:7162) TypeError: coercing to Unicode: need string or buffer, type found

In your documentation, you describe that 'from_file' is a method of this VariableFivePrimeMapFactory class. Could you please respond with an example of how you would implement a variable five prime map or stratified map when mapping footprints to P-sites?

joshuagryphon commented 7 years ago

Hi @bdweave ,

Thank you for pointing these out! I just realized that StratifiedVariableFivePrimeMapFactory is importable but not exported by default. I have just fixed this in the develop branch of plastid. In the mean time, you should be able to import it by typing:

>>> from plastid.genomics.map_factories import StratifiedVariableFivePrimeMapFactory

Second, I was able to reproduce the error (with both StratifiedVariableFivePrimeMapFactory.from_file() and VariableFivePrimeMapFactory.from_file()). I also fixed this in the develop branch. But, you can also workaround this without having to upgrade by passing a filehandle instead of a file name:

>>> with open("bar.txt") as my_file:
>>>     foo.set_mapping(StratifiedVariableFivePrimeMapFactory.from_file(my_file)

Finally, here are the contents of a sample file that should map for either. Just make sure the two columns are separated by tabs (which might get converted to spaces in my copy-paste here)

25    12
26    12
27    13
28    13
29    13
default    13

Please try the workarounds above and let me know if you need further help.

Best, Josh

joshuagryphon commented 7 years ago

Closing this issue unless this is still a problem. Please feel free to re-open