| 158 | } |
| 159 | |
| 160 | void IBSpectraFile::store(const String& filename, const ConsensusMap& cm) |
| 161 | { |
| 162 | // typdefs for shorter code |
| 163 | typedef std::vector<ProteinHit>::iterator ProtHitIt; |
| 164 | |
| 165 | // general settings .. do we need to expose these? |
| 166 | // ---------------------------------------------------------------------- |
| 167 | /// Allow also non-unique peptides to be exported |
| 168 | bool allow_non_unique = true; |
| 169 | /// Intensities below this value will be set to 0.0 to avoid numerical problems when quantifying |
| 170 | double intensity_threshold = 0.00001; |
| 171 | // ---------------------------------------------------------------------- |
| 172 | |
| 173 | |
| 174 | // guess experiment type |
| 175 | boost::shared_ptr<IsobaricQuantitationMethod> quantMethod = guessExperimentType_(cm); |
| 176 | |
| 177 | // we need the protein identifications to reference the protein names |
| 178 | ProteinIdentification protIdent; |
| 179 | bool has_proteinIdentifications = false; |
| 180 | if (!cm.getProteinIdentifications().empty()) |
| 181 | { |
| 182 | protIdent = cm.getProteinIdentifications()[0]; |
| 183 | has_proteinIdentifications = true; |
| 184 | } |
| 185 | |
| 186 | // start the file by adding the tsv header |
| 187 | TextFile textFile; |
| 188 | textFile.addLine(ListUtils::concatenate(constructHeader_(*quantMethod), "\t")); |
| 189 | |
| 190 | for (ConsensusMap::ConstIterator cm_iter = cm.begin(); |
| 191 | cm_iter != cm.end(); |
| 192 | ++cm_iter) |
| 193 | { |
| 194 | const ConsensusFeature& cFeature = *cm_iter; |
| 195 | std::vector<IdCSV> entries; |
| 196 | |
| 197 | /// 1st we extract the identification information from the consensus feature |
| 198 | if (cFeature.getPeptideIdentifications().empty() || !has_proteinIdentifications) |
| 199 | { |
| 200 | // we store unidentified hits anyway, because the iTRAQ quant is still helpful for normalization |
| 201 | entries.emplace_back(); |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | // protein name: |
| 206 | const PeptideHit& peptide_hit = cFeature.getPeptideIdentifications()[0].getHits()[0]; |
| 207 | std::set<String> protein_accessions = peptide_hit.extractProteinAccessionsSet(); |
| 208 | if (protein_accessions.size() != 1) |
| 209 | { |
| 210 | if (!allow_non_unique) continue; // we only want unique peptides |
| 211 | } |
| 212 | |
| 213 | for (std::set<String>::const_iterator prot_ac = protein_accessions.begin(); prot_ac != protein_accessions.end(); ++prot_ac) |
| 214 | { |
| 215 | IdCSV entry; |
| 216 | entry.charge = cFeature.getPeptideIdentifications()[0].getHits()[0].getCharge(); |
| 217 | entry.peptide = cFeature.getPeptideIdentifications()[0].getHits()[0].getSequence().toUnmodifiedString(); |
no test coverage detected