-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63eb991
commit c3a94c5
Showing
6 changed files
with
209 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/BITSapienza/Bio-Server/service/ErrManager" | ||
str "github.com/BITSapienza/Bio-Server/service/structures" | ||
) | ||
|
||
func (rt *_router) GetAnalysis() ([]str.SraBioProject, ErrManager.Errors) { | ||
var an []str.SraBioProject | ||
nProj, err := rt.db.FindAnalysis() | ||
if err != nil { | ||
return an, err | ||
} | ||
var sraProjects []str.SraBioProject | ||
srr := make(map[string]str.SraBioProject) | ||
for _, pro := range nProj { | ||
projId := pro["BioProject"].(string) | ||
val, ok := srr[projId] | ||
if !ok { | ||
|
||
sra := str.SraBioProject{ | ||
TaxId: pro["TaxId"].(string), | ||
|
||
BioProjectId: pro["BioProject"].(string), | ||
BioSamples: []struct { | ||
BioSampleId string | ||
Experiments []struct { | ||
ExperimentId string | ||
Runs []string | ||
} | ||
}{}, | ||
} | ||
if _, ok := pro["ScientificName"].(string); ok { | ||
sra.ScientificName = pro["ScientificName"].(string) | ||
} | ||
if _, ok := pro["Abstract"].(string); ok { | ||
sra.Comment = pro["Abstract"].(string) | ||
} | ||
sra.BioSamples = append(sra.BioSamples, struct { | ||
BioSampleId string | ||
Experiments []struct { | ||
ExperimentId string | ||
Runs []string | ||
} | ||
}{ | ||
BioSampleId: pro["BioSample"].(string), | ||
}) | ||
sra.BioSamples[0].Experiments = append(sra.BioSamples[0].Experiments, struct { | ||
ExperimentId string | ||
Runs []string | ||
}{ExperimentId: pro["ExperimentCode"].(string)}) | ||
sra.BioSamples[0].Experiments[0].Runs = append(sra.BioSamples[0].Experiments[0].Runs, pro["Run"].(string)) | ||
srr[projId] = sra | ||
} else { | ||
isInsideSample := false | ||
|
||
for k, sample := range val.BioSamples { | ||
if sample.BioSampleId == pro["BioSample"].(string) { | ||
isInsideSample = true | ||
isInsideExample := false | ||
for j, expreiment := range sample.Experiments { | ||
if expreiment.ExperimentId == pro["ExperimentCode"].(string) { | ||
isInsideExample = true | ||
srr[projId].BioSamples[k].Experiments[j].Runs = append(srr[projId].BioSamples[k].Experiments[j].Runs, pro["Run"].(string)) | ||
} | ||
} | ||
if !isInsideExample { | ||
srr[projId].BioSamples[k].Experiments = append(srr[projId].BioSamples[k].Experiments, struct { | ||
ExperimentId string | ||
Runs []string | ||
}{ | ||
ExperimentId: pro["ExperimentCode"].(string), | ||
}) | ||
srr[projId].BioSamples[k].Experiments[len(srr[projId].BioSamples[k].Experiments)-1].Runs = append(srr[projId].BioSamples[k].Experiments[len(srr[projId].BioSamples[k].Experiments)-1].Runs, pro["Run"].(string)) | ||
} | ||
|
||
} | ||
} | ||
if !isInsideSample { | ||
prov := struct { | ||
BioSampleId string | ||
Experiments []struct { | ||
ExperimentId string | ||
Runs []string | ||
} | ||
}{BioSampleId: pro["BioSample"].(string)} | ||
|
||
prov.Experiments = append(prov.Experiments, struct { | ||
ExperimentId string | ||
Runs []string | ||
}{ExperimentId: pro["ExperimentCode"].(string)}) | ||
prov.Experiments[0].Runs = append(prov.Experiments[0].Runs, pro["Run"].(string)) | ||
value := srr[projId] | ||
value.BioSamples = append(value.BioSamples, prov) | ||
srr[projId] = value | ||
} | ||
|
||
} | ||
} | ||
for _, key := range srr { | ||
sraProjects = append(sraProjects, key) | ||
} | ||
return sraProjects, nil | ||
} | ||
|
||
// func (a myAnalysis) mutateStruct() (str.SraBioProject, ErrManager.Errors) { | ||
|
||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
|
||
errorM "github.com/BITSapienza/Bio-Server/service/ErrManager" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
// filter = { | ||
// "STUDY.center_name": "BioProject", | ||
// "SAMPLE.IDENTIFIERS.EXTERNAL_ID.namespace": "BioSample", | ||
// } | ||
|
||
// proj = { | ||
// "_id":0, | ||
// "TaxId":"$SAMPLE.SAMPLE_NAME.TAXON_ID.value", | ||
// "BioProject":"$STUDY.alias", | ||
// "BioSample":"$SAMPLE.IDENTIFIERS.EXTERNAL_ID.value", | ||
// "ExperimentCode":"$EXPERIMENT.accession", | ||
// "SRR":"$RUN_SET.RUN.accession", | ||
// "Abstract":"$STUDY.DESCRIPTOR.STUDY_ABSTRACT.value", | ||
// "LinkSRA":"$RUN_SET.RUN.SRAFiles" | ||
// } | ||
|
||
func (db *appDB) FindAnalysis() ([]map[string]interface{}, errorM.Errors) { | ||
filter := bson.D{{ | ||
Key: "$match", Value: bson.M{ | ||
"STUDY.center_name": "BioProject", | ||
"SAMPLE.IDENTIFIERS.EXTERNAL_ID.namespace": "BioSample", | ||
}, | ||
}} | ||
proj := bson.D{{ | ||
Key: "$project", Value: bson.M{ | ||
"_id": 0, | ||
"ScientificName": "$SAMPLE.SAMPLE_NAME.SCIENTIFIC_NAME.value", | ||
"TaxId": "$SAMPLE.SAMPLE_NAME.TAXON_ID.value", | ||
"BioProject": "$STUDY.alias", | ||
"BioSample": "$SAMPLE.IDENTIFIERS.EXTERNAL_ID.value", | ||
"ExperimentCode": "$EXPERIMENT.accession", | ||
"Run": "$RUN_SET.RUN.accession", | ||
"Abstract": "$STUDY.DESCRIPTOR.STUDY_ABSTRACT.value", | ||
}, | ||
}} | ||
dataSeq, errM := db.sequences_data.Aggregate(context.TODO(), mongo.Pipeline{filter, proj}) | ||
if errM != nil { | ||
return nil, errorM.NewError(errM.Error(), errorM.StatusInternalServerError) | ||
} | ||
var seq_data []map[string]interface{} | ||
for dataSeq.Next(context.TODO()) { | ||
var seq map[string]interface{} | ||
err := dataSeq.Decode(&seq) | ||
if err != nil { | ||
return nil, errorM.NewError("Can't Decode Result", errorM.StatusInternalServerError) | ||
} | ||
seq_data = append(seq_data, seq) | ||
} | ||
return seq_data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters