Skip to content
Snippets Groups Projects
Commit f707d4dc authored by Langella Olivier's avatar Langella Olivier
Browse files

fasta files can be writed by groups or subgroups

parent a8382d19
No related branches found
No related tags found
No related merge requests found
......@@ -26,19 +26,19 @@
******************************************************************************/
#include "exportfastafile.h"
#include <pappsomspp/fasta/fastaoutputstream.h>
ExportFastaFile::ExportFastaFile(QString filename, ExportFastaType type)
{
p_outputFastaFile = new QFile(filename);
mp_outputFastaFile = new QFile(filename);
m_exportType = type;
}
void
ExportFastaFile::write(ProjectSp project_sp)
{
p_outputFastaFile->open(QIODevice::WriteOnly);
QTextStream *p_outputStream = new QTextStream(p_outputFastaFile);
mp_outputFastaFile->open(QIODevice::WriteOnly);
QTextStream *p_outputStream = new QTextStream(mp_outputFastaFile);
pappso::FastaOutputStream fasta_output(*p_outputStream);
......@@ -46,29 +46,74 @@ ExportFastaFile::write(ProjectSp project_sp)
for(IdentificationGroup *identification :
project_sp.get()->getIdentificationGroupList())
{
for(ProteinMatch *protein_match : identification->getProteinMatchList())
{
if(protein_match->getValidationState() >= ValidationState::grouped)
{
pappso::Protein protein(
QString("%1 %2")
.arg(protein_match->getProteinXtpSp().get()->getAccession())
.arg(
protein_match->getProteinXtpSp().get()->getDescription()),
protein_match->getProteinXtpSp().get()->getSequence());
fasta_output.writeProtein(protein);
}
}
writeIdentificationGroup(fasta_output, identification);
}
p_outputStream->flush();
delete p_outputStream;
p_outputFastaFile->close();
mp_outputFastaFile->flush();
delete mp_outputFastaFile;
mp_outputFastaFile->close();
}
void
ExportFastaFile::close()
{
delete p_outputFastaFile;
p_outputFastaFile = nullptr;
delete mp_outputFastaFile;
mp_outputFastaFile = nullptr;
}
void
ExportFastaFile::writeIdentificationGroup(
pappso::FastaOutputStream &fasta_output, IdentificationGroup *p_ident)
{
for(const std::pair<unsigned int, GroupingGroupSp> &group_pair :
p_ident->getGroupStore().getGroupMap())
{
unsigned int protein_rank = 0;
unsigned int group_number = 0;
unsigned int subgroup_number = 0;
unsigned int old_group_number = 0;
unsigned int old_subgroup_number = 0;
std::vector<const ProteinMatch *> protein_match_list =
group_pair.second.get()->getProteinMatchList();
std::sort(protein_match_list.begin(),
protein_match_list.end(),
[](const ProteinMatch *a, const ProteinMatch *b) {
return a->getGrpProteinSp().get()->getGroupingId() <
b->getGrpProteinSp().get()->getGroupingId();
});
for(auto &protein_match : protein_match_list)
{
pappso::GrpProtein *p_grp_protein =
protein_match->getGrpProteinSp().get();
ProteinXtp *p_protein = protein_match->getProteinXtpSp().get();
group_number = p_grp_protein->getGroupNumber();
subgroup_number = p_grp_protein->getSubGroupNumber();
if((m_exportType == ExportFastaType::oneBySubgroup) &&
(group_number == old_group_number) &&
(subgroup_number == old_subgroup_number) &&
(p_grp_protein->getRank() > 1))
continue;
if((m_exportType == ExportFastaType::oneByGroup) &&
(group_number == old_group_number) && (subgroup_number > 1))
continue;
old_group_number = group_number;
old_subgroup_number = subgroup_number;
pappso::Protein protein(QString("%1|%2 %3")
.arg(p_grp_protein->getGroupingId())
.arg(p_protein->getAccession())
.arg(p_protein->getDescription()),
p_protein->getSequence());
fasta_output.writeProtein(protein);
}
}
}
......@@ -30,11 +30,16 @@
#include <QString>
#include "../utils/types.h"
#include "../core/project.h"
#include <pappsomspp/fasta/fastaoutputstream.h>
class ExportFastaFile
{
private:
QFile *p_outputFastaFile = nullptr;
QFile *mp_outputFastaFile = nullptr;
ExportFastaType m_exportType;
private:
void writeIdentificationGroup(pappso::FastaOutputStream & fasta_output,IdentificationGroup *p_ident);
public:
ExportFastaFile(QString filename, ExportFastaType type);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment