ProteoWizard
ReferencesTest.cpp
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 //
5 // Original author: Robert Burke <robert.burke@proteowizard.org>
6 //
7 // Copyright 2009 Spielberg Family Center for Applied Proteomics
8 // University of Southern California, Los Angeles, California 90033
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 #define PWIZ_SOURCE
24 
25 #include "References.hpp"
28 #include "TextWriter.hpp"
30 
31 using namespace pwiz::util;
32 using namespace pwiz::cv;
33 using namespace pwiz::identdata;
34 
35 
36 ostream* os_ = 0;
37 
39 {
40  IdentData mzid;
41  ContactPtr c1 = ContactPtr(new Contact("c1", "larry"));
42  PersonPtr p1 = PersonPtr(new Person("p1", "mo"));
43  PersonPtr p2 = PersonPtr(new Person("p2", "curly"));
44  OrganizationPtr o1 = OrganizationPtr(new Organization("o1", "three stooges"));
45  mzid.auditCollection.push_back(c1);
46  mzid.auditCollection.push_back(p1);
47  mzid.auditCollection.push_back(p2);
48  mzid.auditCollection.push_back(o1);
49 
50  return mzid;
51 }
52 
53 
55 {
56  IdentData mzid;
57  ContactPtr c1 = ContactPtr(new Contact("c1", "larry"));
58  PersonPtr p1 = PersonPtr(new Person("p1", "mo"));
59  PersonPtr p2 = PersonPtr(new Person("p2", "curly"));
60  OrganizationPtr o1 = OrganizationPtr(new Organization("o1", "three stooges"));
61  mzid.auditCollection.push_back(c1);
62  mzid.auditCollection.push_back(p1);
63  mzid.auditCollection.push_back(p2);
64  mzid.auditCollection.push_back(o1);
65 
67 
68  AnalysisSoftwarePtr software(new AnalysisSoftware);
69  software->contactRolePtr.reset(new ContactRole(MS_role_type, ContactPtr(new Person("p2"))));
70  mzid.analysisSoftwareList.push_back(software);
71 
72  SamplePtr sample(new Sample);
73  sample->contactRole.push_back(ContactRolePtr(new ContactRole(MS_role_type, ContactPtr(new Person("p1")))));
74  sample->contactRole.push_back(ContactRolePtr(new ContactRole(MS_role_type, ContactPtr(new Organization("o1")))));
75  mzid.analysisSampleCollection.samples.push_back(sample);
76 
77  References::resolve(mzid);
78 
79  unit_assert(mzid.provider.contactRolePtr->contactPtr->name == "larry");
80  unit_assert(software->contactRolePtr->contactPtr->name == "curly");
81  unit_assert(sample->contactRole.front()->contactPtr->name == "mo");
82  unit_assert(dynamic_cast<Person*>(sample->contactRole.front()->contactPtr.get()));
83  unit_assert(sample->contactRole.back()->contactPtr->name == "three stooges");
84  unit_assert(dynamic_cast<Organization*>(sample->contactRole.back()->contactPtr.get()));
85 }
86 
87 
89 {
90  IdentData mzid;
91 
92  SamplePtr sample(new Sample("s1", "Sample No. 1"));
93  sample->subSamples.push_back(SamplePtr(new Sample("s2")));
94 
95  mzid.analysisSampleCollection.samples.push_back(sample);
96 
97  unit_assert(mzid.analysisSampleCollection.samples.at(0)->id == "s1");
98  unit_assert(mzid.analysisSampleCollection.samples.at(0)->subSamples.at(0)->name.empty());
99 
100  sample = SamplePtr(new Sample("s2", "Sample No. 2"));
101  sample->subSamples.push_back(SamplePtr(new Sample("s1")));
102 
103  mzid.analysisSampleCollection.samples.push_back(sample);
104 
105  References::resolve(mzid);
106 
107  unit_assert(mzid.analysisSampleCollection.samples.size() == 2);
108  unit_assert(mzid.analysisSampleCollection.samples.at(0)->id == "s1");
109  unit_assert(mzid.analysisSampleCollection.samples.at(1)->id == "s2");
110  unit_assert(mzid.analysisSampleCollection.samples.at(0)->subSamples.at(0)->name == "Sample No. 2");
111  unit_assert(mzid.analysisSampleCollection.samples.at(1)->subSamples.at(0)->name == "Sample No. 1");
112 }
113 
115 {
116  ContactPtr cont(new Contact("c1", "contact1"));
117 
118  PersonPtr peep1(new Person("p1", "person1"));
119  peep1->affiliations.push_back(OrganizationPtr(new Organization("o1")));
120  PersonPtr peep2(new Person("p2", "person2"));
121  peep2->affiliations.push_back(OrganizationPtr(new Organization("o2")));
122  peep2->affiliations.push_back(OrganizationPtr(new Organization("O")));
123 
124  OrganizationPtr mail_organ(new Organization("o1", "organ1"));
125  OrganizationPtr feemail_organ(new Organization("o2", "organ2"));
126  OrganizationPtr big_Organ(new Organization("O", "Organ"));
127  big_Organ->parent = OrganizationPtr(new Organization("o1"));
128 
129  IdentData mzid;
130 
131  mzid.auditCollection.push_back(cont);
132  mzid.auditCollection.push_back(peep1);
133  mzid.auditCollection.push_back(peep2);
134  mzid.auditCollection.push_back(mail_organ);
135  mzid.auditCollection.push_back(feemail_organ);
136  mzid.auditCollection.push_back(big_Organ);
137 
138  References::resolve(mzid);
139 
140  Person* tp = (Person*)mzid.auditCollection.at(1).get();
141  unit_assert(tp->affiliations.at(0) == mail_organ);
142  tp = (Person*)mzid.auditCollection.at(2).get();
143  unit_assert(tp->affiliations.at(0) == feemail_organ);
144  unit_assert(tp->affiliations.at(1) == big_Organ);
145 
146  Organization* to = (Organization*)mzid.auditCollection.at(5).get();
147  unit_assert(to->parent == mail_organ);
148 }
149 
150 
152 {
153  IdentData mzid;
154 
155  SearchDatabasePtr sd(new SearchDatabase("sd1", "searching"));
156  mzid.dataCollection.inputs.searchDatabase.push_back(sd);
157 
158  sd = SearchDatabasePtr(new SearchDatabase("sd2", "everywhere"));
159  mzid.dataCollection.inputs.searchDatabase.push_back(sd);
160 
161  sd = SearchDatabasePtr(new SearchDatabase("sd3", "for"));
162  mzid.dataCollection.inputs.searchDatabase.push_back(sd);
163 
164  sd = SearchDatabasePtr(new SearchDatabase("sd4", "SearchDatabase"));
165  mzid.dataCollection.inputs.searchDatabase.push_back(sd);
166 
167  DBSequencePtr dbs(new DBSequence("dbs1", "db pointers"));
168  dbs->searchDatabasePtr = SearchDatabasePtr(new SearchDatabase("sd2"));
169  mzid.sequenceCollection.dbSequences.push_back(dbs);
170 
171  dbs = DBSequencePtr(new DBSequence("dbs2", "closing sequence"));
172  dbs->searchDatabasePtr = SearchDatabasePtr(new SearchDatabase("sd3"));
173  mzid.sequenceCollection.dbSequences.push_back(dbs);
174 
175  References::resolve(mzid);
176 
177  DBSequencePtr& dps1 = mzid.sequenceCollection.dbSequences.at(0);
178  unit_assert(dps1->searchDatabasePtr->name == "everywhere");
179 
180  dps1 = mzid.sequenceCollection.dbSequences.at(1);
181  unit_assert(dps1->searchDatabasePtr->name == "for");
182 }
183 
184 
186 {
187  IdentData mzid;
188  SpectrumIdentificationListPtr sil(new SpectrumIdentificationList);
189  SpectrumIdentificationResultPtr sir(new SpectrumIdentificationResult("SIR_1"));
190  SpectrumIdentificationItemPtr sii(new SpectrumIdentificationItem("SII_1"));
191 
193  sil->spectrumIdentificationResult.push_back(sir);
194  sir->spectrumIdentificationItem.push_back(sii);
195 
196  MeasurePtr measureMz(new Measure("M_MZ", "m/z measure"));
197  sil->fragmentationTable.push_back(measureMz);
198 
199  IonTypePtr it(new IonType);
200  sii->fragmentation.push_back(it);
201 
202  FragmentArrayPtr fa(new FragmentArray);
203  fa->measurePtr.reset(new Measure("M_MZ"));
204  it->fragmentArray.push_back(fa);
205 
206  References::resolve(mzid);
207 
208  unit_assert_operator_equal("m/z measure", it->fragmentArray.back()->measurePtr->name);
209 }
210 
211 
212 void test()
213 {
214  testContactRole();
215  testContacts();
217  testDBSequence();
218  testMeasure();
219 }
220 
221 int main(int argc, char* argv[])
222 {
223  TEST_PROLOG_EX(argc, argv, "_IdentData")
224 
225  try
226  {
227  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
228  test();
229  }
230  catch (exception& e)
231  {
232  TEST_FAILED(e.what())
233  }
234  catch (...)
235  {
236  TEST_FAILED("Caught unknown exception.")
237  }
238 
240 }
241 
pwiz::identdata::SpectrumIdentificationItem
Implementation of SpectrumIdentificationItemType from the mzIdentML schema.
Definition: IdentData.hpp:670
pwiz::identdata::Person
Implementation of PersonType from the mzIdentML schema.
Definition: IdentData.hpp:153
test
void test()
Definition: ReferencesTest.cpp:212
pwiz::identdata::SpectrumIdentificationResult
Implementation of SpectrumIdentificationResultType from the mzIdentML schema.
Definition: IdentData.hpp:723
pwiz::cv
Definition: cv.hpp:108
MS_role_type
MS_role_type
role type: Role of a Person or Organization.
Definition: cv.hpp:4218
TextWriter.hpp
pwiz::identdata::References::resolve
PWIZ_API_DECL void resolve(ContactRole &cr, IdentData &mzid)
pwiz::identdata::AnalysisSampleCollection::samples
std::vector< SamplePtr > samples
Definition: IdentData.hpp:260
pwiz::identdata
Definition: DefaultReaderList.hpp:33
pwiz::identdata::Contact
Implementation of ContactType from mzIdentML.
Definition: IdentData.hpp:118
os_
ostream * os_
Definition: ReferencesTest.cpp:36
pwiz::identdata::Organization
Implementation of AbstractOrganizationType from the mzIdentML schema.
Definition: IdentData.hpp:136
pwiz::identdata::IonType
Implementation of IonTypeType from the mzIdentML schema.
Definition: IdentData.hpp:608
testContacts
void testContacts()
Definition: ReferencesTest.cpp:114
unit_assert_operator_equal
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
pwiz::identdata::AnalysisData::spectrumIdentificationList
std::vector< SpectrumIdentificationListPtr > spectrumIdentificationList
Definition: IdentData.hpp:962
main
int main(int argc, char *argv[])
Definition: ReferencesTest.cpp:221
pwiz::util
Definition: almost_equal.hpp:33
pwiz::identdata::FragmentArray
Implementation of FragmentArrayType from the mzIdentML schema.
Definition: IdentData.hpp:590
pwiz::identdata::Provider::contactRolePtr
ContactRolePtr contactRolePtr
Definition: IdentData.hpp:239
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
pwiz::identdata::DataCollection::inputs
Inputs inputs
Definition: IdentData.hpp:976
pwiz::identdata::Organization::parent
boost::shared_ptr< Organization > parent
Definition: IdentData.hpp:140
XMLWriter.hpp
pwiz::msdata::SamplePtr
boost::shared_ptr< Sample > SamplePtr
Definition: MSData.hpp:118
pwiz::identdata::IdentData::provider
Provider provider
Definition: IdentData.hpp:1008
pwiz::identdata::ContactRole
Implementation of ContactRoleType from the mzIdentML schema.
Definition: IdentData.hpp:176
Std.hpp
pwiz::identdata::IdentData::analysisSampleCollection
AnalysisSampleCollection analysisSampleCollection
Definition: IdentData.hpp:1012
pwiz::identdata::SequenceCollection::dbSequences
std::vector< DBSequencePtr > dbSequences
Definition: IdentData.hpp:654
createMzid
IdentData createMzid()
Definition: ReferencesTest.cpp:38
pwiz::identdata::SearchDatabase
Implementation of SearchDatabaseType from the mzIdentML schema.
Definition: IdentData.hpp:271
pwiz::identdata::IdentData
Implementation of the MzIdentMLType from the mzIdentML schema.
Definition: IdentData.hpp:994
testAnalysisSampleCollection
void testAnalysisSampleCollection()
Definition: ReferencesTest.cpp:88
pwiz::identdata::Sample
Implementation of the SampleType from the mzIdentML schema.
Definition: IdentData.hpp:196
pwiz::identdata::IdentData::sequenceCollection
SequenceCollection sequenceCollection
Definition: IdentData.hpp:1014
testMeasure
void testMeasure()
Definition: ReferencesTest.cpp:185
pwiz::identdata::IdentData::dataCollection
DataCollection dataCollection
Definition: IdentData.hpp:1020
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
pwiz::identdata::Measure
Implementation of MeasureType from the mzIdentML schema.
Definition: IdentData.hpp:574
pwiz::identdata::DBSequence
Implementation of DBSequenceType from the mzIdentML schema.
Definition: IdentData.hpp:297
References.hpp
pwiz::identdata::AnalysisSoftware
Implementation of AnalysisSoftwareType from the mzIdentML schema.
Definition: IdentData.hpp:212
TEST_PROLOG_EX
#define TEST_PROLOG_EX(argc, argv, suffix)
Definition: unit.hpp:157
testContactRole
void testContactRole()
Definition: ReferencesTest.cpp:54
unit.hpp
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
pwiz::identdata::DataCollection::analysisData
AnalysisData analysisData
Definition: IdentData.hpp:977
pwiz::tradata::ContactPtr
boost::shared_ptr< Contact > ContactPtr
Definition: TraData.hpp:57
testDBSequence
void testDBSequence()
Definition: ReferencesTest.cpp:151
pwiz::identdata::IdentData::analysisSoftwareList
std::vector< AnalysisSoftwarePtr > analysisSoftwareList
Definition: IdentData.hpp:1006
pwiz::identdata::SpectrumIdentificationList
Implementation of SpectrumIdentificationListType from the mzIdentML schema.
Definition: IdentData.hpp:744
pwiz::identdata::Inputs::searchDatabase
std::vector< SearchDatabasePtr > searchDatabase
Definition: IdentData.hpp:947
pwiz::identdata::IdentData::auditCollection
std::vector< ContactPtr > auditCollection
Definition: IdentData.hpp:1010
pwiz::identdata::Person::affiliations
std::vector< OrganizationPtr > affiliations
Definition: IdentData.hpp:161