[Biophp-dev] Re: New question from the Newbie

Nico Stuurman biophp-dev@bioinformatics.org
23 Mar 2004 07:42:15 -0800


> I have to apologize once again cause of the following question concerning=
 the
> piece of code available at the beginning of the file
> /parsers/swissprot.inc.php :

No problem.

> what is the meaning of the & in &source I never used it before. Thanks in
> advance .

That means that $source is passed to the function by reference rather
than value (a pointer, rather than the whole dataset is copied in your
computer's memory).  This has two consequences:=20
1. Much less stuff is transfered in memory, thus the code should be
faster and more efficient.
2. Changes made to $source within the function will also be made to the
$source living outside of the function (it is the same thing after
all).  This is not the case when you omit the '&' (in that case a copy
is handed over to the function).

Hope this help.

Best,

Nico


>=20
> Fred
>=20
> //################class constructor###################
>=20
>     function parse_swissprot(&$source)=20
>     {
>         if($source !=3D "") {
>             $this->setSource($source);
>         }
>     }
>=20
> -----Message d'origine-----
> De : biophp-dev-admin@bioinformatics.org
> [mailto:biophp-dev-admin@bioinformatics.org]De la part de S Clark
> Envoy=C3=A9 : lundi 22 mars 2004 18:58
> =C3=80 : biophp-dev@bioinformatics.org
> Objet : Re: [Biophp-dev] Re: New question from the Newbie
>=20
>=20
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>=20
> I'm not Nico, but...
>=20
> The swissprot.inc.php class handles the 'loading the data into the array'
> internally.  If you're reading from a file, just pass the filename
> (or the file handle, if you've already opened the file at this point)
> to the class, like:
>=20
> $importer =3D new=20
> parse_swissprot("/home/frederic/swissprot/swissprot-data.swp");
>=20
> See the setSource() and readfromFile() methods for the actual steps
> that this parser takes to pull the lines of data into the internal
> array...
>=20
> (See also the readRecord() 'wrapper' method that decides what methods to
> call based on whether the data given to swissprot parser was a pre-read
> string of text or a file)
>=20
> I think most of the parsers work this way - if given a file rather than
> text data, the parser will read and process one record at a time from the
> file rather than loading the entire file into memory, hence the need for
> a branch in the code between file reading and text reading.  This is just
> to make it possible to read realy big files (think the extreme example of=
=20
> someone wanting to download the entire Genbank database and read through =
it,=20
> saving data from only certain types of records that match - who'd want to=
=20
> load 3GB of text into their system's memory before they could start parsi=
ng?)
>=20
> but doing this isn't absolutely necessary (and in some cases is impossibl=
e -=20
> clustal files have the sequence data interleaved, so you HAVE to read the
> entire file into memory before you can get any of the complete sequences
> parsed from them.).
>=20
> If locuslink files are never going to be very large, it's probably easies=
t
> just to go ahead and 'internally' have the locuslink parser read the enti=
re
> file into memory and just work directly from the text.  (See the clustal
> parser for an example of this).
>=20
> Sean
>=20
> On Monday 22 March 2004 09:53 am, Frederic.Fleche@aventis.com wrote:
> > Hi Nico,
> >
> > The line was the #166 of the file parsers/swissprot_inc.php that you ta=
lk
> > about on your 19 March e-mail.
> > So if $sourcelines is an array, I understand how that loops works but I
> > don't understand where is the step that put all my swissprot file (caus=
e I
> > use a file) in this array. So if you could tell me the file and the lin=
e of
> > this step it would be great.
> >
> > Thanks a lot.
> >
> > Fred
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.9.5 (GNU/Linux)
>=20
> iD8DBQFAXykYJ6yQLhNTzSkRAu2uAJ9pcUq7NJYuBv5HiptdgEz0jvTNsACeJQwB
> im16tKct0x72kL6hKASD5II=3D
> =3Dl+4z
> -----END PGP SIGNATURE-----
> _______________________________________________
> Biophp-dev mailing list
> Biophp-dev@bioinformatics.org
> https://bioinformatics.org/mailman/listinfo/biophp-dev
> _______________________________________________
> Biophp-dev mailing list
> Biophp-dev@bioinformatics.org
> https://bioinformatics.org/mailman/listinfo/biophp-dev
>=20
>=20