1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#include <iostream>
#include <seqan/arg_parse.h>
#include <seqan/seq_io.h>
#include "common.h"
#include "GeneModel.hpp"
#include "FilterFusions.hpp"
seqan::ArgumentParser::ParseResult
parseCommandLine(ProgramOptions & options, int argc, char const ** argv) {
seqan::ArgumentParser parser("pizzly");
// We require one argument.
seqan::addArgument(parser, seqan::ArgParseArgument(
seqan::ArgParseArgument::STRING, "FUSION"));
// Define Options
seqan::addOption(parser, seqan::ArgParseOption(
"k", "", "k-mer size used in kallisto",
seqan::ArgParseArgument::INTEGER, "K"));
seqan::addOption(parser, seqan::ArgParseOption(
"a", "align-score", "Maximum number of mismatches allowed (default: 2)",
seqan::ArgParseArgument::INTEGER, "ALIGN_SCORE"));
seqan::addOption(parser, seqan::ArgParseOption(
"i", "insert-size", "Maximum fragment size of library (default: 400)",
seqan::ArgParseArgument::INTEGER, "INSERT_SIZE"));
seqan::addOption(parser, seqan::ArgParseOption(
"o", "output", "Prefix for output files",
seqan::ArgParseArgument::STRING, "OUTPUT_PREFIX"));
seqan::addOption(parser, seqan::ArgParseOption(
"G", "gtf", "Annotation in GTF format",
seqan::ArgParseArgument::STRING, "GTF"));
seqan::addOption(parser, seqan::ArgParseOption(
"C", "cache", "File for caching annotation (created if not present, otherwise reused from previous runs)",
seqan::ArgParseArgument::STRING, "cache"));
seqan::addOption(parser, seqan::ArgParseOption(
"F", "fasta", "Fasta reference",
seqan::ArgParseArgument::STRING, "FASTA"));
seqan::addOption(parser, seqan::ArgParseOption(
"", "ignore-protein", "Ignore any protein coding information in annotation"));
seqan::setRequired(parser, "k");
seqan::setRequired(parser, "o");
seqan::setRequired(parser, "F");
seqan::setVersion(parser, std::string(PIZZLY_VERSION));
// Parse command line.
seqan::ArgumentParser::ParseResult res = seqan::parse(parser, argc, argv);
// Only extract options if the program will continue after parseCommandLine()
if (res != seqan::ArgumentParser::PARSE_OK)
return res;
// Extract option values.
getOptionValue(options.k, parser, "k");
getOptionValue(options.alignScore, parser, "align-score");
getOptionValue(options.insertSize, parser, "insert-size");
getOptionValue(options.gtf, parser, "gtf");
getOptionValue(options.fasta, parser, "fasta");
getOptionValue(options.cache, parser, "cache");
getOptionValue(options.outprefix, parser, "output");
getArgumentValue(options.fusionFile, parser, 0);
if (seqan::isSet(parser, "ignore-protein")) {
options.ignoreProtein = true;
}
return seqan::ArgumentParser::PARSE_OK;
}
int main(int argc, char const ** argv)
{
// Parse the command line.
ProgramOptions options;
seqan::ArgumentParser::ParseResult res = parseCommandLine(options, argc, argv);
// If parsing was not successful then exit with code 1 if there were errors.
// Otherwise, exit with code 0 (e.g. help was printed).
if (res != seqan::ArgumentParser::PARSE_OK)
return res == seqan::ArgumentParser::PARSE_ERROR;
// parse GTF file
Transcriptome trx;
if (options.cache.empty()) {
parseGTF(trx, options.gtf, options);
} else {
std::ifstream in(options.cache);
if (in.good()) {
std::cerr << "Opening cached file ... ";
loadTranscriptome(trx,in, options);
std::cerr << "loaded " << trx.genes.size() << " genes and " << trx.trxToGeneId.size() << " transcripts" << std::endl;
in.close();
} else {
parseGTF(trx, options.gtf, options);
in.close();
std::ofstream out(options.cache);
writeTranscriptome(trx,out);
out.close();
}
in.close();
}
parseFasta(trx, options.fasta);
int numTxpSeqFound = 0;
int numProt = 0;
for (const auto &it : trx.seqs) {
if (trx.trxToGeneId.find(it.first) != trx.trxToGeneId.end()) {
numTxpSeqFound++;
}
}
for (const auto &git : trx.genes) {
for (const auto &it : git.second.transcripts) {
if (it.second.type == BioType::PROTEIN) {
numProt++;
}
}
}
if (numTxpSeqFound == 0) {
std::cerr << "Error, could not find any transcript sequences check that the ids in the FASTA file and GTF file match" << std::endl;
exit(1);
} else if (numTxpSeqFound != trx.seqs.size()) {
std::cerr << "Warning: could not find annotations for " << (trx.seqs.size() - numTxpSeqFound) << " transcripts\n" << std::endl;
}
if (!options.ignoreProtein && numProt == 0) {
std::cerr << "Warning: the annotation contains no protein coding information\n"
<< " pizzly will probably not report any fusions, consider finding\n"
<< " a better annotation or run again with --ignore-protein option.\n" << std::endl;
}
// filter fusion edges
processFusions(trx,options);
return 0;
}
|