Answers.Body: <p>You should be able to extract anything from mzML and mzXML with Pyteomics. You will have to look at your files and figure out what you need to do, though, because you need to know what element contains the information that you want. I don't often work with mzXML and in the files that I have I do not see an acquisition date at all. With mzML it appears that the <code>&lt;run&gt;</code> element has this information:</p>
  <pre><code>&lt;run id=&quot;small_raw&quot; defaultInstrumentConfigurationRef=&quot;IC1&quot; startTimeStamp=&quot;2005-07-20T14:44:22&quot;&gt;
  </code></pre>
  <p>So I can get it like this:</p>
  <pre><code>In [1]: from pyteomics import mzml
  
  In [2]: with mzml.MzML('tests/test.mzML') as f:
     ...:     print(next(f.iterfind('run', recursive=False))['startTimeStamp'])
     ...: 
  2005-07-20T14:44:22
  </code></pre>
  <p>P.S. Disclaimer: I am the maintainer of Pyteomics.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-12T14:00:42.780Z
Answers.LastActivityDate: 2022-12-12T22:07:18.220Z
Answers.LastEditDate: 2022-12-12T22:07:18.220Z
Answers.UserDisplayName: Lev Levitsky
Answers.Body: <p><code>pymzml</code> certainly works via <a href="https://academic.oup.com/bioinformatics/article/28/7/1052/209917" rel="nofollow noreferrer">Bald <em>et al</em> 2012</a>:</p>
  <pre><code>conda install -c bioconda pymzml
  </code></pre>
  <p>Whilst this only works with <code>mzML</code> you simply convert <code>mzXML</code> to <code>pymzml</code> via <code>ProteoWizard</code></p>
  <pre><code>msconvert your_mzXML_file --mzML
  </code></pre>
  <p><a href="https://bioinformatics.stackexchange.com/questions/10807/how-to-convert-mzxml-to-mzml-format-mass-spectrometry-files">It is described here with your previous question with @haci</a></p>
  <p>I believe you managed this via</p>
  <pre><code>conda create -n openms -c bioconda openms
  FileConverter -in file.mzXML -out file.mzML
  </code></pre>
  <p>I suspect the underlying question is direct parsing in <code>mzXML</code> without the need to perform a conversion from <code>mzXML</code> to <code>mzML</code> or without using <code>Bioconductor</code></p>
  <hr />
  <p><strong>Possibility</strong> The following may be of use <code>massspec-toolbox</code> at:</p>
  <p><a href="http://code.google.com/p/massspec-toolbox/source/browse/#svn/trunk/mzxml" rel="nofollow noreferrer">http://code.google.com/p/massspec-toolbox/source/browse/#svn/trunk/mzxml</a></p>
  <p>Note, I've not tested nor read this but the repository looks genuine.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-09T21:44:27.283Z
Answers.LastActivityDate: 2022-12-09T21:44:27.283Z
Answers.UserDisplayName: M__
Body: <p>I would like to extract date of acquisiton from mzXML and mzML files, using Python. Is it possible e.g. with <a href="https://pypi.org/project/pyteomics/" rel="nofollow noreferrer">Pyteomics</a>? pymzml is only for mzML files. Are there other libraries that can do that? I assume of course that the date of acquisition is recored in mzXML/mzML files.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-09T20:31:15.190Z
Comments.Text: Please [edit] your question and i) add small example input files (they need to be valid mzXML and mzML) and ii) the output you expect from that input so we can test any answers we come up with.
Comments.UserDisplayName: terdon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-12T20:04:21.423Z
Comments.Text: This question is really targeted at people who know what a mzXML or mzML file is and who use e.g. pyteomics. Also, I don't know how to attach a data file like this to a stackoverflow question. I think, only images can be uploaded. Thanks
Comments.UserDisplayName: Soerendip
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-13T09:23:18.590Z
Comments.Text: You can simply paste a few lines into your question and then use the `{}` button to format as code. And it isn't a question of showing the format but of having clear input and output requirements so solutions can be tested.
Comments.UserDisplayName: terdon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-13T17:15:59.393Z
Comments.Text: I don't think that is necessary.
Comments.UserDisplayName: Soerendip
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-13T17:20:24.690Z
Comments.Text: It isn't about necessary, it is about helping others help you. If you include a test file, then we can test our solutions and make sure they actually work. You have the option of making it harder for people to help you, so in that sense it isn't "necessary". But if you want to ask a good, well received question that doesn't get downvoted, then it is necessary. Your call.
Comments.UserDisplayName: terdon
Tags: <python>
Title: How to extract date of acquisiton from mzXML and mzML files with Python?
ThreadText: # How to extract date of acquisiton from mzXML and mzML files with Python?
  
  (Asked by: username_0 on 2022-12-09)
  
  I would like to extract date of acquisiton from mzXML and mzML files, using Python. Is it possible e.g. with [Pyteomics](https://pypi.org/project/pyteomics/)? pymzml is only for mzML files. Are there other libraries that can do that? I assume of course that the date of acquisition is recored in mzXML/mzML files.
  
  **Tags:** python
  
  > **Comments:**
  > **username_1**: Please [edit] your question and i) add small example input files (they need to be valid mzXML and mzML) and ii) the output you expect from that input so we can test any answers we come up with.  
  > **username_0**: This question is really targeted at people who know what a mzXML or mzML file is and who use e.g. pyteomics. Also, I don't know how to attach a data file like this to a stackoverflow question. I think, only images can be uploaded. Thanks  
  > **username_1**: You can simply paste a few lines into your question and then use the `{}` button to format as code. And it isn't a question of showing the format but of having clear input and output requirements so solutions can be tested.  
  > **username_0**: I don't think that is necessary.  
  > **username_1**: It isn't about necessary, it is about helping others help you. If you include a test file, then we can test our solutions and make sure they actually work. You have the option of making it harder for people to help you, so in that sense it isn't "necessary". But if you want to ask a good, well received question that doesn't get downvoted, then it is necessary. Your call.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2022-12-12. Score: 3 | Accepted answer
  
  You should be able to extract anything from mzML and mzXML with Pyteomics. You will have to look at your files and figure out what you need to do, though, because you need to know what element contains the information that you want. I don't often work with mzXML and in the files that I have I do not see an acquisition date at all. With mzML it appears that the `<run>` element has this information:
  
  ```
  <run id="small_raw" defaultInstrumentConfigurationRef="IC1" startTimeStamp="2005-07-20T14:44:22">
  
  ```
  
  So I can get it like this:
  
  ```
  In [1]: from pyteomics import mzml
  
  In [2]: with mzml.MzML('tests/test.mzML') as f:
     ...:     print(next(f.iterfind('run', recursive=False))['startTimeStamp'])
     ...: 
  2005-07-20T14:44:22
  
  ```
  
  P.S. Disclaimer: I am the maintainer of Pyteomics.
  
  
  ---
  
  ### Answer by username_3 on 2022-12-09. Score: 0
  
  `pymzml` certainly works via [Bald *et al* 2012](https://academic.oup.com/bioinformatics/article/28/7/1052/209917):
  
  ```
  conda install -c bioconda pymzml
  
  ```
  
  Whilst this only works with `mzML` you simply convert `mzXML` to `pymzml` via `ProteoWizard`
  
  ```
  msconvert your_mzXML_file --mzML
  
  ```
  
  [It is described here with your previous question with @haci](https://bioinformatics.stackexchange.com/questions/10807/how-to-convert-mzxml-to-mzml-format-mass-spectrometry-files)
  
  I believe you managed this via
  
  ```
  conda create -n openms -c bioconda openms
  FileConverter -in file.mzXML -out file.mzML
  
  ```
  
  I suspect the underlying question is direct parsing in `mzXML` without the need to perform a conversion from `mzXML` to `mzML` or without using `Bioconductor`
  
  ---
  
  **Possibility** The following may be of use `massspec-toolbox` at:
  
  <http://code.google.com/p/massspec-toolbox/source/browse/#svn/trunk/mzxml>
  
  Note, I've not tested nor read this but the repository looks genuine.
  
  
  ---
  
  