Changeset 3009
- Timestamp:
- Dec 8, 2006, 10:47:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tab2mage_ebi/src/plugins/core/net/sf/basedb/plugins/Tab2MageExporter.java
r3002 r3009 19 19 */ 20 20 package net.sf.basedb.plugins; 21 21 22 22 23 import java.io.BufferedWriter; … … 255 256 Set<String> protocolHybSectionHeader= new LinkedHashSet<String>(); 256 257 Set<String> parameterHybSectionHeader= new LinkedHashSet<String>(); 257 258 258 Map<AnnotationType, Annotation> factorValues= new HashMap<AnnotationType,Annotation>(); 259 259 List<String> protocolRefId= new LinkedList<String>(); 260 260 List<String> hybridizationDataRows=new LinkedList<String>(); 261 261 List<String> parameterValues= new LinkedList<String>(); 262 List<Annotation> expFactorValues= new LinkedList<Annotation>(); 263 264 List<String> twoColorHybDataRowsFirstSection=new LinkedList<String>(); 265 List<String> twoColorHybDataRowsSecondSection=new LinkedList<String>(); 266 262 267 263 268 boolean overwrite = false; 269 boolean twoColorHyb= false; 264 270 try 265 271 { … … 289 295 // check if the logged in user owned the experiment 290 296 if (!(experiment.getOwner().equals(user))) return; //if not the logged in user do not own the experiment. This can be re-coded to return a message for usability 291 // get the release date string and convert it into date format 292 String releaseDate= (String)job.getValue("releaseDate"); 297 String releaseDate= (String)job.getValue("releaseDate"); // get the release date string and convert it into date format 293 298 //create an output stream writer to the file 294 299 //We use OutputStreamWriter so that characters written to it are encoded into bytes using a specified charset for all 295 300 //System.out.println("The java runtime default char set is :" +Charset.defaultCharset()); 296 301 Writer out= new BufferedWriter(new OutputStreamWriter(file.getUploadStream(false),"ISO-8859-1")); 297 302 303 // Header section 304 out.write("# This file contains an experiment exported in tab2mage specification from BASE2\n\n"); 298 305 // Experiment Section 299 //outputExperimentSection(out,experiment,releaseDate, response);300 306 out.write("Experiment section \n"); 301 307 out.write("domain\t"+Application.getHostName()+"\n"); 302 308 out.write("accession\tE-BASE-"+experiment.getId()+"\n"); 309 out.write("quality_control\t\n"); 303 310 out.write("experiment_design_type\t"+ Values.getEmptyStringIfNull(experiment.getExperimentDesign())+"\n"); 304 311 out.write("name\t"+experiment.getName() +"\n"); … … 307 314 out.write("release_date\t"+Values.getEmptyStringIfNull(releaseDate)+"\n"); 308 315 out.write("submission_date\t"+Values.formatDate(new Date())+"\n"); 309 out.write("submitter\t"+experiment.getOwner().getName() +" email: "+Values.getEmptyStringIfNull(experiment.getOwner().getEmail()) +"\n"); 316 out.write("submitter\t"+experiment.getOwner().getName()+"\n"); 317 out.write("submitter_email\t"+Values.getEmptyStringIfNull(experiment.getOwner().getEmail())+"\n"); 310 318 out.write("organization\t"+ Values.getEmptyStringIfNull(experiment.getOwner().getOrganisation()) +"\n"); 319 out.write("publication_title\t"+Values.getEmptyStringIfNull(experiment.getTitle()) +"\n"); 311 320 out.write("authors\t"+Values.getEmptyStringIfNull(experiment.getAuthors())+"\n"); 312 321 out.write("journal\t"+Values.getEmptyStringIfNull(experiment.getPublication())+"\n"); 313 out.write("year\t"+ String.format("%1$tY", experiment.getPublicationDate())+"\n");314 out.write("pubmed_id\t"+Values.getEmptyStringIfNull(experiment.getPubMedId())+"\n");315 out.write("quality_control\t\n");316 out.write("publication_title\t\n");317 322 out.write("volume\t\n"); 318 323 out.write("issue\t\n"); 319 324 out.write("pages\t\n"); 325 out.write("year\t"+ String.format("%1$tY", experiment.getPublicationDate())+"\n"); 326 out.write("pubmed_id\t"+Values.getEmptyStringIfNull(experiment.getPubMedId())+"\n"); 320 327 out.write("\n"); 321 328 out.flush(); 329 322 330 323 331 // Get all protocols and hybs … … 327 335 for (RawBioAssay rba : rawBioAssays) 328 336 { 337 twoColorHybDataRowsFirstSection.add("-done-"); //initialise the twocolor hyb row with -done- as the delimeter 329 338 /* 330 339 Data files and array information section// … … 339 348 hybSectionHeader.add("File[raw]"); 340 349 hybridizationDataRows.add(celFile.getName()); 350 twoColorHybDataRowsFirstSection.add(celFile.getName()); 341 351 hybSectionHeader.add("File[cdf]"); 342 352 hybridizationDataRows.add(cdfFile.getName()); 353 twoColorHybDataRowsFirstSection.add(cdfFile.getName()); 343 354 } 344 355 else … … 346 357 hybSectionHeader.add("File[raw]"); 347 358 hybridizationDataRows.add(rba.getName()); 359 twoColorHybDataRowsFirstSection.add(rba.getName()); 348 360 } 349 361 hybSectionHeader.add("Array[accession]"); 350 362 hybridizationDataRows.add(arrayDesign.getName()); 363 twoColorHybDataRowsFirstSection.add(arrayDesign.getName()); 351 364 352 365 //Raw BioAssay protocol 353 366 protocolRefId.add(getFormattedProtocolId(rba.getProtocol())); 354 367 protocolHybSectionHeader.add("Protocol[image_analysis]"); 355 protocols.add(rba.getProtocol()); //rawbioassay protocol 368 //if (rba.getProtocol()!=null) 369 //{ 370 protocols.add(rba.getProtocol()); //rawbioassay protocol 371 372 // System.out.println("raw bioassay protocol: P-BASE-"+rba.getProtocol().getId()); 373 //} 356 374 if (rba.isAnnotated()) 357 375 { … … 363 381 { 364 382 parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]"); 365 parameterValues.add(annotation.getValues().toString()); 366 } 383 for (int i=0; i<annotation.getValues().size(); i++) 384 { 385 parameterValues.add(annotation.getValues().get(i).toString()); 386 } 387 } 388 //else 389 //{ 390 // parameterValues.add("\t"); 391 //} 367 392 } 368 393 } … … 382 407 { 383 408 parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]"); 384 parameterValues.add(annotation.getValues().toString()); 385 } 386 409 for (int i=0; i<annotation.getValues().size(); i++) 410 { 411 parameterValues.add(annotation.getValues().get(i).toString()); 412 } 413 } 414 //else 415 //{ 416 // parameterValues.add("\t"); 417 // } 387 418 } 388 419 } 389 420 390 421 //Hybridization 391 422 Hybridization hyb= scan.getHybridization(); 392 423 hybSectionHeader.add("Array[serial]"); 393 424 hybridizationDataRows.add(hyb.getArraySlide().getName()); 394 425 twoColorHybDataRowsFirstSection.add(hyb.getArraySlide().getName()); 395 426 /* 396 427 Names of materials and processes section … … 398 429 hybSectionHeader.add("Hybridization"); 399 430 hybridizationDataRows.add(hyb.getName()); 400 431 twoColorHybDataRowsFirstSection.add(hyb.getName()); 432 401 433 System.out.println("The number of scans: "+hyb.countScans()); // count scans that created the hyb 402 434 BioMaterialEvent bioMaterialEvent= hyb.getCreationEvent(); // event that created the hyridization … … 415 447 { 416 448 parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]"); 417 parameterValues.add(annotation.getValues().toString()); 418 } 419 420 } 421 } 422 423 449 for (int i=0; i<annotation.getValues().size(); i++) 450 { 451 parameterValues.add(annotation.getValues().get(i).toString()); 452 } 453 } 454 //else 455 //{ 456 // parameterValues.add("\t"); 457 //} 458 } 459 } 460 424 461 ItemQuery<LabeledExtract> labeledExtractQuery =(ItemQuery<LabeledExtract>) bioMaterialEvent.getSources(); // get all the labeled extract 425 462 ItemResultList<LabeledExtract> labeledExtracts= labeledExtractQuery .list(dc); 426 for (LabeledExtract labeledExtract :labeledExtracts) // can have more that one labeled extract 427 { 463 int hybsize=labeledExtracts.size(); 464 int count=1; 465 //STOPPED HERE (LAST CODE) TRYING TO IMPLEMENT TWO COLOR HYBS 466 //if (hybsize==2 && !hybridizationDataRows.contains("-done-")) 467 //{ 468 // twoColorHybDataRowsFirstSection.addAll(hybridizationDataRows); //create anew data row for 2 color experiment 469 // twoColorHybDataRowsSecondSection.addAll(hybridizationDataRows); 470 // twoColorHyb=true; 471 //}else if(hybsize==2 && twoColorHyb ) 472 //{ //NOTE THE OUTPUT SHOWS THAT i AM ADDING THE LAST INFORMATION, SO FIX THIS 473 // twoColorHybDataRowsFirstSection.addAll(twoColorHybDataRowsSecondSection); 474 //} 475 // END OF LAST CODE 476 System.out.println("The size of the two color data hyb data row before the labeled extract section: " +twoColorHybDataRowsFirstSection.size()); 477 System.out.println("The size of the hyb data row before adding to tow color hyb row: " +hybridizationDataRows.size()); 478 System.out.println(hybsize ==1 ? "Affy Expriment. Hyb size:"+hybsize :"2 - color Expreriment. Hyb size : "+hybsize ); 479 for (LabeledExtract labeledExtract :labeledExtracts) // can have more than one labeled extract (2 color experiments) 480 { 481 428 482 // labeled extract 429 483 hybSectionHeader.add("LabeledExtract"); 430 hybridizationDataRows.add(labeledExtract.getName()); 431 484 if (count<hybsize) 485 { 486 hybridizationDataRows.add(labeledExtract.getName()); 487 } 488 else if (count==2) 489 { 490 twoColorHyb=true; 491 twoColorHybDataRowsFirstSection.add(labeledExtract.getName()); 492 } 493 432 494 Protocol lbExtractProtocol= labeledExtract.getCreationEvent().getProtocol(); 433 495 protocols.add(lbExtractProtocol); // labeled extract protocol 434 496 protocolRefId.add(getFormattedProtocolId(lbExtractProtocol)); 435 497 protocolHybSectionHeader.add("Protocol[labeling]"); 436 437 498 if (labeledExtract.isAnnotated()) 438 499 { … … 444 505 { 445 506 parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]"); 446 parameterValues.add(annotation.getValues().toString()); 507 for (int i=0; i<annotation.getValues().size(); i++) 508 { 509 parameterValues.add(annotation.getValues().get(i).toString()); 510 } 447 511 } 448 449 } 450 } 451 512 //else 513 //{ 514 // parameterValues.add("\t"); 515 //} 516 } 517 } 452 518 String labelName= labeledExtract.getLabel().getName(); // the name of the label 453 519 hybSectionHeader.add("Dye"); 454 hybridizationDataRows.add(labelName); 455 520 if (count < hybsize) 521 { 522 hybridizationDataRows.add(labelName); 523 } 524 else if (count==2) 525 { 526 twoColorHybDataRowsFirstSection.add(labelName); 527 } 456 528 // Extract 457 Set <Annotatable> extractOrPooledLabeledExtract= labeledExtract.getAnnotatableParents(); //get extract or pooled labelled extract529 //Set <Annotatable> extractOrPooledLabeledExtract= labeledExtract.getAnnotatableParents(); //get extract or pooled labelled extract 458 530 //if (extractOrPooledLabeledExtract instanceof Extract) 459 531 Extract extract= labeledExtract.getExtract(); … … 461 533 { 462 534 hybSectionHeader.add("Extract"); 463 hybridizationDataRows.add(extract.getName()); 535 if (count < hybsize) 536 { 537 hybridizationDataRows.add(extract.getName()); 538 } 539 else if (count==2) 540 { 541 twoColorHybDataRowsFirstSection.add(extract.getName()); 542 } 464 543 465 544 Protocol extractProtocol =extract.getCreationEvent().getProtocol(); //extract protocol … … 476 555 { 477 556 parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]"); 478 parameterValues.add(annotation.getValues().toString()); 557 for (int i=0; i<annotation.getValues().size(); i++) 558 { 559 System.out.println("The extract protocol parameter is :" + annotation.getValues().get(i).toString()); 560 parameterValues.add(annotation.getValues().get(i).toString()); 561 } 479 562 } 480 563 //else 564 //{ 565 // parameterValues.add("\t"); 566 //} 481 567 } 482 568 } … … 489 575 { 490 576 hybSectionHeader.add("Sample"); 491 hybridizationDataRows.add(sample.getName()); 577 if (count < hybsize) 578 { 579 hybridizationDataRows.add(sample.getName()); 580 } 581 else if (count==2) 582 { 583 twoColorHybDataRowsFirstSection.add(sample.getName()); 584 } 492 585 493 586 Protocol sampleProtocol=sample.getCreationEvent().getProtocol(); //sampling protocol … … 505 598 { 506 599 parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]"); 507 parameterValues.add(annotation.getValues().toString()); 600 for (int i=0; i<annotation.getValues().size(); i++) 601 { 602 System.out.println("The sample protocl parameter is :" + annotation.getValues().get(i).toString()); 603 parameterValues.add(annotation.getValues().get(i).toString()); 604 } 508 605 } 509 606 //else 607 //{ 608 // parameterValues.add("\t"); 609 //} 510 610 } 511 611 } 512 612 } 513 613 // Biosource 514 614 //sample.getAnnotatableParents(); //get the biosource or pooled samples 515 615 BioSource bioSource=sample.getBioSource(); 516 616 if (bioSource!=null) //get the biosource 517 617 { 518 hybridizationDataRows.add(bioSource.getName());618 519 619 hybSectionHeader.add("Biosource"); 620 if (count < hybsize) 621 { 622 hybridizationDataRows.add(bioSource.getName()); 623 } 624 else if(count==2) 625 { 626 twoColorHybDataRowsFirstSection.add(bioSource.getName()); 627 } 520 628 AnnotationSet bsAnnotationSet =bioSource.getAnnotationSet(); 521 629 ItemQuery<Annotation> annotationsQuery= bsAnnotationSet.getAnnotations(); … … 529 637 for (int i=0; i<annotation.getValues().size(); i++) 530 638 { 531 532 hybridizationDataRows.add(annotation.getValues().get(i).toString()); 533 639 if (count < hybsize) 640 { 641 hybridizationDataRows.add(annotation.getValues().get(i).toString()); 642 } 643 else if(count==2) 644 { 645 twoColorHybDataRowsFirstSection.add(annotation.getValues().get(i).toString()); 646 } 647 534 648 } 535 649 } 536 650 } 537 } 651 } 652 System.out.println("The count before increament is :" +count); 653 count++; 538 654 539 } 540 for (String protcolId : protocolRefId) 541 { 542 System.out.println("----Test protocol id added----"); 543 System.out.println("Id: "+protcolId); 544 hybridizationDataRows.add(protcolId); 545 } 546 for (String paramValue : parameterValues ) 547 { 548 System.out.println("----Test parametervalue added----"); 549 hybridizationDataRows.add(paramValue); 550 } 655 } //end of labeled extract loop 656 657 System.out.println("THE VALUE OF COUNT IS: "+ count); 658 //for (String protcolId : protocolRefId) //add protocol id 659 //{ 660 //System.out.println("----Test protocol id added----"); 661 //System.out.println("Id: "+protcolId); 662 /// hybridizationDataRows.add(protcolId); 663 //} 664 //for (String paramValue : parameterValues ) //add parameter values 665 //{ 666 //System.out.println("----Test parametervalue added----"); 667 // hybridizationDataRows.add(paramValue); 668 //} 551 669 /* 552 670 Experimental Factor Section 553 671 */ 554 factorValues= getExperimentalFactors(dc,experiment,rba);555 for(Annotation value: factorValues.values())672 expFactorValues=getExperimentalFactorValues(dc,experiment,rba); 673 for(Annotation value: expFactorValues) //add factor values 556 674 { 557 675 if (value!=null) … … 562 680 } 563 681 } 564 } 565 682 else 683 { 684 hybridizationDataRows.add("\t"); 685 } 686 } 687 if (twoColorHyb) 688 { 689 //twoColorHybDataRowsFirstSection.add("-done-"); 690 hybridizationDataRows.addAll(twoColorHybDataRowsFirstSection); 691 //hybridizationDataRows.add("-done-"); 692 } 566 693 protocolRefId.clear(); 567 694 parameterValues.clear(); 568 695 factorValues.clear(); 569 System.out.println("done"); 696 if (!twoColorHybDataRowsFirstSection.isEmpty()) 697 { 698 twoColorHybDataRowsFirstSection.clear(); 699 twoColorHyb=false; 700 } 570 701 hybridizationDataRows.add("-done-"); 702 System.out.println("done - end of rawbioassay :" + rba.getName()); 571 703 }// end of raw biossay for loop 572 704 … … 579 711 hybSectionHeader.add(parameterHeader); 580 712 } 713 for (String factorValueHeader :factorValuesHybSectionHeader) 714 { 715 hybSectionHeader.add(factorValueHeader); 716 } 717 581 718 //Protocol Section 582 719 out.write("Protocol section \n"); … … 614 751 out.write(header.toString()+"\t"); 615 752 } 616 if (factorValues!=null) 617 { 618 for (AnnotationType fv : factorValues.keySet()) 619 { 620 out.write("FactorValue["+fv.getName()+"]\t"); 621 } 622 } 753 623 754 out.write("\n"); 624 755 //values … … 634 765 } 635 766 } 767 //for (String twoColor :twoColorHybDataRowsFirstSection ) 768 //{ 769 // if (twoColor!="-done-") 770 // { 771 // out.write(twoColor+"\t"); 772 // } 773 // else if("-done-".equals(twoColor)) 774 // { 775 // out.write("\n"); 776 // } 777 //} 636 778 out.write("\n"); 637 779 … … 650 792 } 651 793 } 652 653 654 794 // get all the experimental factors for this experiments, 655 private static Map<AnnotationType, Annotation> getExperimentalFactors(DbControl dc, Experiment experiment, RawBioAssay rba)656 { 657 Map<AnnotationType, Annotation> values= new HashMap<AnnotationType,Annotation>();795 private static List<Annotation> getExperimentalFactorValues(DbControl dc, Experiment experiment, RawBioAssay rba) 796 { 797 List<Annotation> values= new LinkedList<Annotation>(); 658 798 ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors(); 659 799 experimentalFactorsQuery.include(Include.MINE,Include.IN_PROJECT, Include.SHARED, Include.OTHERS); … … 661 801 for (AnnotationType exprFactor :experimentalFactors) //create the factor value for this experiment obtaining annotations from rawbioassay 662 802 { 803 factorValuesHybSectionHeader.add("FactorValue["+exprFactor.getName()+"]"); 663 804 AnnotationSet annotationSet = rba.isAnnotated() ? rba.getAnnotationSet() : null; 664 805 if (annotationSet!=null) 665 806 { 666 values.put(exprFactor,annotationSet.findAnnotation(exprFactor)); 807 values.add(annotationSet.findAnnotation(exprFactor)); 808 667 809 } 668 810 } 669 811 return values; 670 812 } 671 672 // get the base format id for the protocol if protocol is null and empty string is returned , this helps the mainatin the tab delim format 813 // get the base format id for the protocol if protocol is null and empty string is returned , this helps to mentain the tab delim format 673 814 private static String getFormattedProtocolId (Protocol protocol) 674 815 { … … 685 826 return protocolId ; 686 827 } 828 829 private static Set<String> factorValuesHybSectionHeader= new LinkedHashSet<String>(); 687 830 }
Note: See TracChangeset
for help on using the changeset viewer.