コード例 #1
0
ファイル: fetchhead.c プロジェクト: CodeSmithyIDE/libgit2
void test_online_fetchhead__colon_only_dst_refspec_creates_no_branch(void)
{
	int refs;

	fetchhead_test_clone();
	refs = count_references();
	fetchhead_test_fetch("refs/heads/first-merge:", FETCH_HEAD_EXPLICIT_DATA);

	cl_assert_equal_i(refs, count_references());
}
コード例 #2
0
ファイル: fetchhead.c プロジェクト: CodeSmithyIDE/libgit2
void test_online_fetchhead__empty_dst_refspec_creates_no_branch(void)
{
	git_reference *ref;
	int refs;

	fetchhead_test_clone();
	refs = count_references();

	fetchhead_test_fetch("refs/heads/first-merge", FETCH_HEAD_EXPLICIT_DATA);
	cl_git_fail(git_branch_lookup(&ref, g_repo, "first-merge", GIT_BRANCH_ALL));

	cl_assert_equal_i(refs, count_references());
}
コード例 #3
0
ファイル: fetchhead.c プロジェクト: CodeSmithyIDE/libgit2
void test_online_fetchhead__explicit_dst_refspec_creates_branch(void)
{
	git_reference *ref;
	int refs;

	fetchhead_test_clone();
	refs = count_references();
	fetchhead_test_fetch("refs/heads/first-merge:refs/heads/explicit-refspec", FETCH_HEAD_EXPLICIT_DATA);

	cl_git_pass(git_branch_lookup(&ref, g_repo, "explicit-refspec", GIT_BRANCH_ALL));
	cl_assert_equal_i(refs + 1, count_references());

	git_reference_free(ref);
}
コード例 #4
0
ファイル: theoretical.cpp プロジェクト: markadamo/tempest
extern void Tempest::search_fasta_database()
{
    int i;
    int iProtein;
    int iLengthProtein;
    int iLengthBuffer;
    int iProteinBuffer = INITIAL_PROTEIN_BUFFER;
    char sLineBuffer[LENGTH_INPUT_BUFFER+1];
    char sProteinReference[MAX_LENGTH_REFERENCE+1];
    char *sProteinSequence;
    FILE *fp;
    eObj *e;
    float fProgress;

    // Setup
    // allocate working memory
    if (0 == (sProteinSequence = (char*) malloc(iProteinBuffer*sizeof(char)))) {
        fprintf(stderr, "\nERROR\tUnable to allocate memory for the active protein sequence.\n");
        Tempest::tempest_exit(EXIT_FAILURE);
    }

    // calculate peptide mass range
    // TODO: change if we allow negative mod masses
    float fMaxAAModMass = 0.0f;
    for (i=0; i<Tempest::params.iNumMods; i++) {
        if (Tempest::params.tMods[i].cSymbol && Tempest::params.tMods[i].dMassDiff > fMaxAAModMass)
            fMaxAAModMass = Tempest::params.tMods[i].dMassDiff;
    }
    float fMaxNtermModMass = 0.0f;
    for (i=0; i<Tempest::params.numNtermModSites; i++)
        if (Tempest::params.ntermModMasses[i] > fMaxNtermModMass)
            fMaxNtermModMass = Tempest::params.ntermModMasses[i];
    float fMaxCtermModMass = 0.0f;
    for (i=0; i<Tempest::params.numCtermModSites; i++)
        if (Tempest::params.ctermModMasses[i] > fMaxCtermModMass)
            fMaxCtermModMass = Tempest::params.ctermModMasses[i];

    float maxMaxTermModMass = fMaxNtermModMass > fMaxCtermModMass ? fMaxNtermModMass : fMaxCtermModMass;
    float minMaxTermModMass = fMaxNtermModMass < fMaxCtermModMass ? fMaxNtermModMass : fMaxCtermModMass;

    float fMaxMassDiff = 0.0;
    int remainingMods = Tempest::params.iModificationsMax;
    if (remainingMods && maxMaxTermModMass > fMaxAAModMass) {
        fMaxMassDiff += maxMaxTermModMass;
        remainingMods -= 1;
    }
    if (remainingMods && minMaxTermModMass > fMaxAAModMass) {
        fMaxMassDiff += minMaxTermModMass;
        remainingMods -= 1;
    }
    fMaxMassDiff += fMaxAAModMass * remainingMods;

    if (Tempest::params.bPrecursorTolerancePPM) {
        Tempest::data.fMinPrecursorMass -= Tempest::data.fMinPrecursorMass*Tempest::params.fPrecursorTolerance/1000000.0f;
        Tempest::data.fMaxPrecursorMass += Tempest::data.fMaxPrecursorMass*Tempest::params.fPrecursorTolerance/1000000.0f;
    }
    else {
        Tempest::data.fMinPrecursorMass -= Tempest::params.fPrecursorTolerance;
        Tempest::data.fMaxPrecursorMass += Tempest::params.fPrecursorTolerance;
    }
    Tempest::data.dMinPeptideMass = Tempest::data.fMinPrecursorMass - fMaxMassDiff;
    Tempest::data.dMaxPeptideMass = Tempest::data.fMaxPrecursorMass;
    
    // open fasta file
    // command line overrides param file
    char* fastaFile = Tempest::args.sFasta == NULL ? Tempest::params.sFasta : Tempest::args.sFasta; 
    if (0 == (fp = (FILE *) fopen(fastaFile, "r"))) {
        fprintf(stderr, "\nERROR\tUnable to open fasta database: %s\n", fastaFile);
        Tempest::tempest_exit(EXIT_FAILURE);
    }

    // count proteins
    Tempest::data.iNumProteins = count_references(fp);
    
    if (Tempest::data.iNumProteins == 0) {
        fprintf(stderr, "\nERROR\tNo proteins found in fasta database: %s\n", Tempest::args.sFasta);
        Tempest::tempest_exit(EXIT_FAILURE);
    }

    // progress
    if (Tempest::args.iPrintLevel && !Tempest::args.bPrintCandidates) {
        printf(" » Digesting %d proteins...     ", Tempest::data.iNumProteins);
    }
    
    // Get memory for the protein references
    if (0 == (Tempest::data.sProteinReferences = (char *) malloc(Tempest::data.iNumProteins * MAX_LENGTH_REFERENCE * sizeof(char)))) {
        fprintf(stderr, "\nERROR\tUnable to allocate memory for protein references.\n");
        Tempest::tempest_exit(EXIT_FAILURE);
    }
    
    // parse fasta line by line
    iProtein = 0;
    iLengthProtein = 0;
    sProteinSequence[0] = '\0';
    while (fgets(sLineBuffer, LENGTH_INPUT_BUFFER, fp)) {
        if (strlen(sLineBuffer) <= 0) continue;
        
        // reference line
        if ('>' == sLineBuffer[0]) {
            // check for previous protein
            if (iLengthProtein > 0) {
                // process
                strcpy(&Tempest::data.sProteinReferences[iProtein * MAX_LENGTH_REFERENCE * sizeof(char)], sProteinReference);
                digest_protein(iProtein++, iLengthProtein, sProteinSequence);

                if (Tempest::args.iPrintLevel && !Tempest::args.bPrintCandidates) {
                    fProgress = (100.0f * iProtein) / Tempest::data.iNumProteins;
                    if (fProgress - floor(fProgress) < 0.01f) printf("\b\b\b\b%*d%%", 3, (int) fProgress);
                    fflush(0);
                }
            
                // reset
                iLengthProtein = 0;
                sProteinSequence[0] = '\0';
            }

            // get next reference
            parse_reference(sLineBuffer, sProteinReference);
        }

        // protein sequence line
        else {
            //get length
            iLengthBuffer = (int) strlen(sLineBuffer);
            
            //strip newlines
            while(iLengthBuffer>0 && !isalnum(sLineBuffer[iLengthBuffer-1])) {
                iLengthBuffer--;
            }

            if (iLengthBuffer <= 0)
                continue;

            // check new sequence length against buffer size
            if (iLengthProtein + iLengthBuffer > iProteinBuffer) {
                //grow protein sequence buffer
                iProteinBuffer *= 2;
                if (0 == (sProteinSequence = (char*) realloc(sProteinSequence, iProteinBuffer*sizeof(char)))) {
                    fprintf(stderr, "\nERROR\tCould not allocate memory for protein %s (length %d)\n", sProteinReference, iProteinBuffer);
                    Tempest::tempest_exit(EXIT_FAILURE);
                }
            }

            // concatenate to sequence
            strncat(sProteinSequence,sLineBuffer,iLengthBuffer);
            iLengthProtein += iLengthBuffer;
        }
    }

    // check for errors
    if (ferror(fp)) {
        fprintf(stderr, "\nERROR\tUnable to read from %s, while reading database.\n", Tempest::args.sFasta);
        Tempest::tempest_exit(EXIT_FAILURE);
    }
    
    // Final protein
    strncpy(&Tempest::data.sProteinReferences[iProtein * MAX_LENGTH_REFERENCE],sProteinReference,MAX_LENGTH_REFERENCE);
    digest_protein(iProtein++, iLengthProtein, sProteinSequence);
    
    if (Tempest::args.iPrintLevel && !Tempest::args.bPrintCandidates) {
        fProgress = (100.0f * iProtein) / Tempest::data.iNumProteins;
        printf("\b\b\b\b%*d%%", 3, (int) fProgress);
    }
        
    // Score Remaining Candidates
    for(i=0;i<Tempest::data.iNumPrecursorBins;i++) {
        for (e = Tempest::data.eScanIndex[i]; e; e = e->next) {
            //printf("%d\t%d\n", gpu_info.iNumScoringKernels, i);
            if (e->iNumBufferedCandidates > 0)
                e->device->scoreCandidates(e);
        }
    }
    
    // close fasta
    fclose(fp);

    // summary
    if (Tempest::args.iPrintLevel && !Tempest::args.bPrintCandidates) {
        printf("\n");
    }

    //cleanup
    free(sProteinSequence);
}