Dear JP,

On Thu, Aug 4, 2011 at 4:48 PM, JP <[email protected]> wrote:
>
> I have a theoretical/general cheminformatics question and a practical one.
>
> In theory, which is better -- having a program which reads/writes
> everything from stdin/stdout or having the said program read an input
> file and spit out an output file.

It's hard to pick one of these as being better than the other; they're
different.

> Possibly these methods are equivalent, and from one you can do the
> other (via redirection or use of /dev/stdout as file descriptor etc).
> One problem I have with the stdin/stdout approach is that then I have
> to log messages to a file instead of screen, as you do not want the
> info message "20 molecules in file abc.sdf" to go out in your
> molecules stream.   Which do you find the most usable/user friendly
> approach?

The logging problem with pipes can be solved by sending your messages
to stderr instead of stdout.

> To my practical question now (and I'd like this answered, if possible
> irrespective of the above).   I would like to access the SDMolSupplier
> (std::istream *inStream, ...) method - to feed the SDMolSupplier from
> stdin (e.g. cat abc.sdf | myprog.py ) how do I go about doing that in
> python; the following bit of code does not work:
>
> suppl = Chem.SDMolSupplier(sys.stdin.readlines(), sanitize=False)

Nope, that does not work. You need to do:

suppl =Chem.SDMolSupplier()
data=sys.stdin.read()
suppl.SetData(data,sanitize=False)
data=None   # <- do this last step to free up memory in case the file is large

Note that this isn't really the same as having the supplier work
directly from stdin, since the entire contents of the file need to be
read into memory first. At the moment there is no way from python to
create a supplier that reads directly from stdin.

You can, on the other hand, create an SDWriter that writes to stdout
by providing the filename "-":

w = Chem.SDWriter("-")

If there's a need for it, I could certainly explore adding a similar
special case to the SDMolSupplier() constructor.

-greg

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts. 
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to